
var xajaxRequestUri="include/ajax.php";
var xajaxDebug=false;
var xajaxStatusMessages=false;
var xajaxWaitCursor=true;
var xajaxDefinedGet=0;
var xajaxDefinedPost=1;
var xajaxLoaded=false;

function xajax_call(){return xajax.call("call", arguments, 1);}

function init(more)
{
	a = "<div id='body'></div>";
	a = a + "<div id='error_message' style='position:absolute; left:0; top:0;' ></div>";
	a = a + "<div id='loading_message' style='position:absolute; left:0; top:0;' ></div>";
	a = a + "<div id='floating_screen' style='position:absolute; left:0; top:0;' ></div>";
	document.body.innerHTML = a;
	act(more);
}

function redirect(n)
{
	window.location = n;
}

function act(n,p,f)
{
	document.getElementById('loading_message').innerHTML = "<table width='100%'><tr><td align='right'><span style='background-color:#FF0000; color:#ffffff; width:60px;'>Loading...</span></td></tr></table>";
	xajax_call(n,p,f);
}


function myobjfind(id,a)
{
	found = 0;
	for(i=0;i<a.length;i++)
	{
		obj = a[i];
		if (obj.id == id)
		{
			found = 1;
		}
	}
	return found;
}


function myobjlistfree(obj)
{
	for (i=0;i<obj.list.length;i++)
	{
		var p = obj.list[i];
		p = null;
	}
	while (obj.list.length > 0)  obj.list.pop();
}

// --------------------------------------------------

function clear_href_focus()
{
	if(document.all)
	{
	  var tags = document.all.tags("a");
	  for (var i = 0; i < tags.length; i++)
		tags(i).outerHTML = tags(i).outerHTML.replace("<a href", "<a hidefocus=true href");
	}
}

function post(fm,a)
{
	act(a,'',xajax.getFormValues(fm));
}


function option_selected(id,a)
{
		var o = document.getElementById(id);
		var result = 0;
		for (var i=0; i<o.length; i++)
		{
			if (o.options[i].value == a)
			{
				result = i;
			}
		}
        o.options.selectedIndex = result;
}

// --------------------------------------------------
function check_code(input, index){
	var oc = document.getElementById('option_code');
	var flag = 'FALSE';
	for(i=1; i<oc.options.length; i++){
		if (input.toLowerCase() == oc.options[i].value.toLowerCase()){
			flag = 'TRUE';
			break;
		}
	}
	
	if (input == ''){
		document.getElementById('code'+index).style.color = '#000000';
		return;
	}

	if (flag == 'FALSE'){
		document.getElementById('code'+index).style.color = '#ff0000';
		document.getElementById('code_msg').innerHTML = "Note: This is a new Code. Once saved, it will be available in the drop-down menu.";
	}
	else{
		document.getElementById('code'+index).style.color = '#000000';
		document.getElementById('code_msg').innerHTML = "";
	}
}

function check_sbrn(input, index){
	var os = document.getElementById('option_sbrn');
	var flag = 'FALSE';
	for(i=1; i<os.options.length; i++){
		if (input.toLowerCase() == os.options[i].value.toLowerCase()){
			flag = 'TRUE';
			break;
		}
	}
	
	if (input == ''){
		document.getElementById('sbrn'+index).style.color = '#000000';
		return;
	}
  
	if (flag == 'FALSE'){
		document.getElementById('sbrn'+index).style.color = '#ff0000';
		document.getElementById('code_msg').innerHTML = "Note: This is a new SBRN. Once saved, it will be available in the drop-down menu.";
	}
	else{
		document.getElementById('sbrn'+index).style.color = '#000000';
		document.getElementById('code_msg').innerHTML = "";
	}
}

function check_importer_name(input){
	var os = document.getElementById('option_us_importer');
	var flag = 'FALSE';
	for(i=1; i<os.options.length; i++){
		if (input.toLowerCase() == os.options[i].value.toLowerCase()){
			flag = 'TRUE';
			break;
		}
	}
	
	if (input == ''){
		document.getElementById('us_importer_name').style.color = '#000000';
		return;
	}

	if (flag == 'FALSE'){
		document.getElementById('us_importer_name').style.color = '#ff0000';
		document.getElementById('us_importer_msg').innerHTML = "A new Importer Name. Once saved, it will be available in the drop-down menu.";
	}
	else{
		document.getElementById('us_importer_name').style.color = '#000000';
		document.getElementById('us_importer_msg').innerHTML = "";
	}
}

