/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function LoginAlert() {
if (loggedIn==false) {
	alert('You need to be logged in to access the requested information. Please either login or register with Poultex');
	getObject('txtusername').focus();
	return false;
} else {
return true;
}
}

function DeleteFromListBox(ListBox)
{
var ListItems = new Array();
for(var i=(ListBox.options.length - 1);i>=0;i--)
 if(ListBox.options[i].selected)
   {
	ListItems[ListItems.length] = new Option(ListBox.options[i].text);
	ListBox.options[i] = null;
   } 
}

function isValidEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail address - please check and try again")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail address - please check and try again")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail address - please check and try again")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail address - please check and try again")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail address - please check and try again")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail address - please check and try again")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail address - please check and try again")
		    return false
		 }

 		 return true					
	}

function getObject(objName) {
	if(document.getElementById){
		return eval("document.getElementById('" +objName +"')");
}
	if(document.layers){
		return eval("document."+objName);
	}
	if(document.all){
		return eval("document.all." + objName);
	}

}
function popSelectList(SelectItem, Values) {
   for (var i=0; i < Values.length; i++) {      
   		getObject(SelectItem).options[i]=new Option(Values[i])
       }
   }

function AsyncCmd(nCmd,vParm1,vParm2,vParm3,vParm4,vParm5) {
	//Execute the Asynchronous Callback
	HTTPRequest("/AsyncCmd.asp?c="+nCmd+"&1="+vParm1+"&2="+vParm2+"&3="+vParm3+"&4="+vParm4+"&5="+vParm5);
	//Do not put an more commands after it as it is asynchronous 
	// - get the return text/code to call the next step in the sequence
}

function AsyncMapData(nCmd,vParm1,vParm2,vParm3,vParm4,vParm5) {
	//Execute the Asynchronous Callback
	HTTPRequest("/AsyncMapData.asp?c="+nCmd+"&1="+vParm1+"&2="+vParm2+"&3="+vParm3+"&4="+vParm4+"&5="+vParm5);
	//Do not put an more commands after it as it is asynchronous 
	// - get the return text/code to call the next step in the sequence
}

function AsyncCmdMapTables(nCmd,vParm1,vParm2,vParm3,vParm4,vParm5,vParm6,vParm7,vParm8) {
	//Execute the Asynchronous Callback
	HTTPRequest("/AsyncCmdMapTables.asp?c="+nCmd+"&1="+vParm1+"&2="+vParm2+"&3="+vParm3+"&4="+vParm4+"&5="+vParm5+"&6="+vParm6+"&7="+vParm7+"&8="+vParm8);
	//Do not put an more commands after it as it is asynchronous 
	// - get the return text/code to call the next step in the sequence
}

function asyncCallProducts(sParam1) {
	//Execute the Asynchronous Callback
	HTTPRequest("/admin/asyncCallProducts.asp?companyid="+sParam1);
	//Do not put an more commands after it as it is asynchronous 
	// - get the return text/code to call the next step in the sequence
}

function popUp(URL, sW,sH,sL,sT) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open('" + URL + "', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+ sW + ",height="+ sH + ",left = "+ sL + ",top = "+ sT + "')");
}


function fixedTo(number, n) {
  var k = Math.pow(10, n+1);
  return (Math.round(number * k) / k);
}

