function ajaxFunction()
{
var xmlHttp;

try
  {  
  // Firefox, Opera 8.0+, Safari    
   xmlHttp=new XMLHttpRequest();     
  }
catch (e)
  {
	   // Internet Explorer  
	   try
	   {    
		 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
	   }
	   catch (e)
	   {    
		  try
		  {      
 			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
		  }
		  catch (e)
		  { 
	//	    alert("Your browser does not support AJAX!");      
			return false;      
	      }    
       }  
   }  
   
return xmlHttp;   
}


function formatDate(dateValue, format) 
{   
	var fmt = format.toUpperCase(); 
    var re = /^(M|MM|D|DD|YYYY)([\-\/]{1})(M|MM|D|DD|YYYY)(\2)(M|MM|D|DD|YYYY)$/; 
    if (!re.test(fmt)) { fmt = "MM/DD/YYYY"; } 
    if (fmt.indexOf("M") == -1) { fmt = "MM/DD/YYYY"; } 
    if (fmt.indexOf("D") == -1) { fmt = "MM/DD/YYYY"; } 
    if (fmt.indexOf("YYYY") == -1) { fmt = "MM/DD/YYYY"; } 

    var M = "" + (dateValue.getMonth()+1); 
    var MM = "0" + M; 
    MM = MM.substring(MM.length-2, MM.length); 
    var D = "" + (dateValue.getDate()); 
    var DD = "0" + D; 
    DD = DD.substring(DD.length-2, DD.length); 
    var YYYY = "" + (dateValue.getFullYear()); 

    var sep = "/"; 
    if (fmt.indexOf("-") != -1) { sep = "-"; } 
    var pieces = fmt.split(sep); 
    var result = ""; 

    switch (pieces[0]) { 
         case "M" : result += M + sep; break; 
         case "MM" : result += MM + sep; break; 
         case "D" : result += D + sep; break; 
         case "DD" : result += DD + sep; break; 
         case "YYYY" : result += YYYY + sep; break; 
    } 

    switch (pieces[1]) { 
         case "M" : result += M + sep; break; 
         case "MM" : result += MM + sep; break; 
         case "D" : result += D + sep; break; 
         case "DD" : result += DD + sep; break; 
         case "YYYY" : result += YYYY + sep; break; 
    } 
    switch (pieces[2]) { 
         case "M" : result += M; break; 
         case "MM" : result += MM; break; 
         case "D" : result += D; break; 
         case "DD" : result += DD; break; 
         case "YYYY" : result += YYYY; break; 
    } 

    return result; 
} 

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  
}

function replace_webdata(entry)
{
		
	out = "'"; // replace this
	add = "&#39;"; // with this
	temp = "" + entry; // temporary holder
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}
	
	return temp;
	
}

function replace_comma_quote(entry)
{
		
	out = ','; // replace this
	add = ""; // with this
	temp = "" + entry; // temporary holder
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}
	
	out = '`'; // replace this
	add = ""; // with this
	temp = "" + entry; // temporary holder
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}
	return temp;
	
}

function replace_comma(entry)
{
		
	out = ','; // replace this
	add = ""; // with this
	temp = "" + entry; // temporary holder
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}
	
	return temp;
	
}


function stripslashes_js (str) {
           
	   return (str+'').replace(/\\(.?)/g, function (s, n1) {
	   switch (n1) 
		  {
            case '\\':
                return '\\';
            case '0':                
			    return '\u0000';
            case '':
                return '';
            default:
                return n1;        
		 }
    });
} 

function htmlspecialchars_js(str) {
 if (typeof(str) == "string") {
  str = str.replace(/&/g, "&amp;"); /* must do &amp; first */
  str = str.replace(/"/g, "&quot;");
  str = str.replace(/'/g, "&#039;");
  str = str.replace(/</g, "&lt;");
  str = str.replace(/>/g, "&gt;");
  }
 return str;
 }

function replace_htmlchar(entry) 
{

	// first char
	out = "&amp;"; // replace this
	add = "&"; // with this
	temp = "" + entry; // temporary holder
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}

	// second char
	out = '&quot;'; // replace this
	add = '"'; // with this
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}


	// third char
	out = '&#039;'; // replace this
	add = "'"; // with this
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}

	// fourth char
	out = '&lt;'; // replace this
	add = "<"; // with this
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length)); 
   }
   
   // fourth char
	out = '&gt;'; // replace this
	add = ">"; // with this
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length)); 
   }

  return temp;
}


function replace_char(entry) 
{

	// first char
	out = "'"; // replace this
	add = "`"; // with this
	temp = "" + entry; // temporary holder
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}

	// second char
	out = '"'; // replace this
	add = " "; // with this
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}


	// third char
	out = '|'; // replace this
	add = " "; // with this
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}

	// fourth char
	out = '&'; // replace this
	add = " and "; // with this
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length)); 
   }

  return temp;
}



 
function changeText(id,str) {
// id is the ID of the td cell, str is new text
var mycel = document.getElementById(id);
var myceltext = mycel.childNodes.item(0);
mycel.removeChild(myceltext);
var newtxt = document.createTextNode(str);
mycel.appendChild(newtxt);
}

function floatdiv(id,y,x)
{    
	lay=document.getElementById(id);
	lay.style.position='absolute';
	lay.style.top=x;
	lay.style.left=y;
}
function set_zindex(id)
{   
	zidx = 8;
	for (k=0;k<9;k++)
	{ 
	  if (id == 'tab'+k)
	   {
		document.getElementById(id).style.zIndex = 9;
	   }
	  else
	   { 
	  document.getElementById('tab'+k).style.zIndex = zidx;
	   }
	  zidx = zidx - 1;
	}
}

function remove_left_border(id)
 {
  document.getElementById(id).style.borderLeft="1px #EEF7F5 solid";
 }
function return_left_border(id)
 {
  document.getElementById(id).style.borderLeft="1px #93A4B0 solid";
 } 
 

 
function disable_menu(mnu_rights,mnu_pos)
{
   var accessRights = mnu_rights.split("|");					    
  
  if (accessRights[mnu_pos] == 0) 
   { return "Denied"; }
  else
   { return "Allowed" }
} 

function onReturn_focus(event,focusid)
{
	
var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

	if (Key == 13)
	 {
	   document.getElementById(focusid).focus();	  
	   return false;
	 }
	 
	 return true;
}

function onReturn(event,inpval)
{
var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

   if (Key == 13)
    {
     window.location.href = "#"+inpval;
     return false;
    }
  return true;	
}
 
function onReturnSearch(event)
 {
	var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

	if (Key == 13)
	 {
	   search_now(); 
	   return false;
	 }
	 
	 return true; 
 }
function onReturnQty(event,numid)
{
    var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

	if (Key == 13)
	 {
	   calculate_shipping(numid);
	   return false;
	 }
	 return true;
} 
 
function Zero_on_Blur(id)
{
	
if (document.getElementById(id).value.length == 0)
 {
	document.getElementById(id).value = "0.00";  
 }
 
}

function is_alphanumeric(event) {
  var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

   //alert(Key)
   if (Key == 38 || Key == 34 || Key == 124)  return false;
  
 
  return true;
}

function onReturn_login(event)
{
  var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

  if (Key == 13)
    {
		login_now();
		return false;
	}
  
  return true;

}

function is_int(event) {

  var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

  // the following is copied and pasted from yours
  if (Key == 13 || Key == 45 || Key == 46 || Key == 8)  return true;
  
  for(i=48;i<=57;i++){
      if(Key == i) return true;
  }
  return false;
}



function trapkeys_alphanumeric()
 {
 
   if (event.keyCode == ",".charCodeAt() || event.keyCode == "(".charCodeAt() || event.keyCode == ")".charCodeAt() || event.keyCode == "'".charCodeAt())
    {
	  return false;
	}
   else
    { 
     return true;	
    }
//   return event.keyCode != ','.charCodeAt();
}

function trapkeys_numeric_only()
 {
 
   if (event.keyCode == '1'.charCodeAt() || event.keyCode == '2'.charCodeAt() || event.keyCode == '3'.charCodeAt() || event.keyCode == '4'.charCodeAt()
       || event.keyCode == '5'.charCodeAt() || event.keyCode == '6'.charCodeAt() || event.keyCode == '7'.charCodeAt() || event.keyCode == '8'.charCodeAt()
	   || event.keyCode == '9'.charCodeAt() || event.keyCode == '0'.charCodeAt() || event.keyCode == '.'.charCodeAt() || event.keyCode == '-'.charCodeAt())
    {
	  return true;
	}
   else
    { 
     return false;	
    }
//   return event.keyCode != ','.charCodeAt();
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function toggle(x,origColor,newColor)
  {
	if ( x.style ) 
	 {
		x.style.backgroundColor = (newColor == x.style.backgroundColor)? origColor : newColor;
	 }
  }

function get_opt_text(id1,id2,txtval)
{
	if (txtval == "None")
	    {
		  document.getElementById(id2).value = "";
		  return;
		}	
	
	var lb = document.getElementById(id1);
    arrTexts = new Array();

	for(i=0; i<lb.length; i++)  
	{
	  if (lb.options[i].value == txtval)
	    {
		  document.getElementById(id2).value = lb.options[i].text;
		  return;
		}
	  
	}

}
function sortlist(id) 
{
var lb = document.getElementById(id);
arrTexts = new Array();

for(i=0; i<lb.length; i++)  
{
  arrTexts[i] = lb.options[i].text;
}

arrTexts.sort();

for(i=0; i<lb.length; i++)  
{
  lb.options[i].text = arrTexts[i];
  lb.options[i].value = arrTexts[i];
}
}

function uc_first(str)
{
  var lc_str = str.substring(0,1);
  var ucfirst = lc_str.toUpperCase();
  
  return ucfirst+str.substring(1,str.length);
}


function replace_value(str)
{ 
  ostr1 = trim(str.replace("'", "`"));
  ostr2 = trim(ostr1.replace('"', " "));
  ostr3 = trim(ostr2.replace(",", " "));  
  return ostr3;  
}


function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  
  return newnumber; // Output the result to the form field (change for your purposes)
  
  
}

function formatCurrency(num) 
{
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}

function getBrowserHeight() {
	var intH = 0;
	var intW = 0;
   
	if(typeof window.innerWidth  == 'number' ) {
	   intH = document.body.clientHeight; //window.innerHeight;
	   intW = window.innerWidth;	  
	} 
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		intH = document.body.clientHeight; //document.documentElement.clientHeight;
		intW = document.documentElement.clientWidth;		
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		intH = document.body.clientHeight;
		intW = document.body.clientWidth;
	}

	return { width: parseInt(intW), height: parseInt(intH) };
}  

function setLayerPosition(id) {
	var shadow = document.getElementById("shadow");
	var question = document.getElementById(id);
	var thewidth = parseInt(question.style.width);
	//var theheight = parseInt(question.style.height);
	var bws = getBrowserHeight();
	
	shadow.style.width = bws.width + "px";
	shadow.style.height = "1500px";
	//shadow.style.height = bws.height + 100 + "px";
	question.style.left = parseInt((bws.width - thewidth) / 2) + "px";
	//question.style.top = parseInt((bws.height - theheight) / 2) + "px";

    question.style.top = "100px"; 
	shadow = null;
	question = null;
}

function showLayer(id) {
	
	window.scroll(0,0);
	setLayerPosition(id);

	var shadow = document.getElementById("shadow");
	var question = document.getElementById(id);

	shadow.style.display = "block"; 
	question.style.display = "block";

	shadow = null;
	question = null;             
}

function hideLayer(id) {
	var shadow = document.getElementById("shadow");
	var question = document.getElementById(id);

	shadow.style.display = "none"; 
	question.style.display = "none";

	shadow = null;
	question = null; 
}

function disable_link(href) 
 {
    for (var i=0; i<document.links.length; i++) {
        if (document.links[i].href == href) {
            document.links[i].href = 'javascript:;';
            document.links[i].onclick = '';
        }
    }
 }

function submit_access()
 {
  document.getElementById('login_loading').innerHTML = "&nbsp; ";
  if (document.getElementById('usr').value.length == 0 || document.getElementById('pwd').value.length == 0)
   {
	  if (document.getElementById('usr').value.length == 0)
	   {
		  alert("Username is required");  
	      document.getElementById('usr').focus();
		  document.getElementById('login_loading').innerHTML = "&nbsp;";	  
  		  return;
	   }
	  if (document.getElementById('pwd').value.length == 0)
	   {
		  alert("Password is required");  
	      document.getElementById('pwd').focus();
		  document.getElementById('login_loading').innerHTML = "&nbsp;";
		  return;
	   } 
   }
   var usr = escape(document.getElementById('usr').value);
   var pwd = escape(document.getElementById('pwd').value);
   document.getElementById('login_loading').innerHTML = "<img src='kool_grid/loading/4.gif' />";	  
	  var xmlHttp = ajaxFunction();	
	  xmlHttp.onreadystatechange=function()
		{
		if(xmlHttp.readyState==4)
		  {		
		    document.getElementById('login_loading').innerHTML = "&nbsp; ";
			var get_result = trim(xmlHttp.responseText);	
		    
			var exp_result = get_result.split("**-**");			
			if (trim(exp_result[0]) == "Accepted")
				 {  
				   if (exp_result[1] == "None")
				    {
				      window.location = "../index.php";
					} else {
					  window.location = exp_result[1];
					}
					
				 }
			   else
				 {
				  alert("Access Denied !!!");				  
				 }
		  }
		}
		 xmlHttp.open("GET","get_access.php?typ=Get_Access&usr="+usr+"&pwd="+pwd,true);
		 xmlHttp.send(null);   	  
 }



function end_session() 
  {
      var path = document.location.pathname;
	  var exppath = path.split("/");
	  var newpath = "/"+exppath[1]+"/";
	
	 
      var xmlHttp = ajaxFunction();
	  xmlHttp.onreadystatechange=function()       
			{
			if(xmlHttp.readyState==4)
			  {			  
			      window.location = newpath+"index.php";
				  //window.location = "/index.php";
			  }
			}
			 xmlHttp.open("GET","admin/get_access.php?typ=end_session",true);
			 xmlHttp.send(null);  
  
  }
  

  
function LocationSearch()        
  {            
    var queryString = new String();            
	queryString = window.location.search;            
	queryString = queryString.substring(1);            
	document.getElementById("div1").innerHTML = queryString + "<br />";            
	var arr1 = new Array();            
	arr1 = queryString.split("&");            
	var arr2 = new Array();            
	for(var i = 0; i<arr1.length; i++)            
	  {                
	  arr2[i] = arr1[i].toString().substring(arr1[i].toString().indexOf("=") + 1);                
	  arr1[i] = arr1[i].toString().substring(0,arr1[i].toString().indexOf("="));            
	  }            
	
	document.getElementById("div1").innerHTML += arr1.concat() + "<br />";            
	document.getElementById("div1").innerHTML += arr2.concat();        
  }     
  
function hideit(id)
{
    document.getElementById(id).style.display = "none";  
	Popup.hide(id);	
}

function showit(id)
{
    document.getElementById(id).style.display = "block";  
	Popup.showModal(id);
}  
  
function setLocationSearch(valueObj)        
    {            
	  window.location.search = valueObj;        
	}    

function show_combo(id)
{
	document.getElementById(id).style.display = "block";  
	Popup.showModal(id);
}

function hide_combo(id)
{
	document.getElementById(id).style.display = "none";  
	Popup.hide(id);
}  

function convertthis_date(dte)
{
 thisdate = dte.split("/");
 returndate = thisdate[2]+"-"+thisdate[0]+"-"+thisdate[1];
 return returndate;
}

function disable_menu(mnu_rights,mnu_pos)
{
   var accessRights = mnu_rights.split("|");					    
  
  if (accessRights[mnu_pos] == 0) 
   { return "Denied"; }
  else
   { return "Allowed" }
} 

function run_module(menu_rights,mnu_pos,scriptfile)
{
	if (disable_menu(menu_rights,mnu_pos) == "Denied")
     { 
	   alert("You do not have access rights !!!"); return; 
	 }
	else
	 {
	   window.location = scriptfile;	 
	 }
}

function update_combo_field()
{
	
	var tbl = document.getElementById('additem_info_tbl').value;
	var tdid = document.getElementById('additem_info_tdid').value;
	var selid = document.getElementById('additem_info_selid').value;
	var select_value_start = "";
	var select_value_end = "";
	
	if (tbl == "currency")
	 {
	select_value_start = "&nbsp;&nbsp;<select name='"+selid+"' id='"+selid+"' class='genfont_1'>";
	select_value_end = "</select>";
	 }
	else if (tbl == "shipper" || tbl == "countrycode")
	 {
	select_value_start = "<select name='"+selid+"' id='"+selid+"' class='genfont_1'>";
	select_value_end = "</select>";	 
	 } 
	else
	 {
	select_value_start = "&nbsp;<select name='"+selid+"' id='"+selid+"' class='genfont_1'>";
	select_value_end = "</select>";	 
	 }
	      
		   var xmlHttp = ajaxFunction();
		   var params = "typ=get_select_opt&tbl="+tbl+"&tdid="+tdid+"&selid="+selid;
	   
		   xmlHttp.open("POST","../get_data.php",true);
		   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		   xmlHttp.setRequestHeader("Content-length", params.length);
		   xmlHttp.setRequestHeader("Connection", "close");
		   xmlHttp.send(params);
		  
		  
		  xmlHttp.onreadystatechange=function()
			{
			if(xmlHttp.readyState==4)
			  {			  
			     var select_result = trim(xmlHttp.responseText);
				 var newselect = document.getElementById(tdid);				 	
				 newselect.innerHTML = select_value_start+select_result+select_value_end;
			  }
			}	
	
	
}

function show_add_pop(tdid,tbl,selid)
{
	var select_stmt = "";
	var select_stmt_up = "";
	var select_stmt_del = "";
	var select_stmt_ins = "";
		   
	document.getElementById('float_additem').style.display = "block";
	Popup.showModal('float_additem');
     
	
	if (tbl == "shipper")
	 {
	   select_stmt = "select ID,Shipper,shipper_address FROM shipper ORDER BY Shipper";
	   select_stmt_up = "update shipper set Shipper='@Shipper',shipper_address='@shipper_address' where ID=@ID";
	   select_stmt_del = "delete from shipper where ID=@ID";
	   select_stmt_ins = "insert into shipper (Shipper,shipper_address) values ('@Shipper','@shipper_address');";
	   document.getElementById('additem_caption').innerHTML = "Add Shipper"; 
	 }
	if (tbl == "countrycode")
	 {
	   select_stmt = "select ID,Country_Code, Country FROM countrycode ORDER BY Country";	 
	   select_stmt_up = "update countrycode set Country_Code='@Country_Code',Country='@Country' where ID=@ID";
	   select_stmt_del = "delete from countrycode where ID=@ID";
	   select_stmt_ins = "insert into countrycode (Country_Code,Country) values ('@Country_Code','@Country');";
	   document.getElementById('additem_caption').innerHTML = "Add Country Code"; 
	 } 
	if (tbl == "currency")
	 {
	   select_stmt = "select ID,Currency FROM currency ORDER BY Currency";	 
	   select_stmt_up = "update currency set Currency='@Currency' where ID=@ID";
	   select_stmt_del = "delete from currency where ID=@ID";
	   select_stmt_ins = "insert into currency (Currency) values ('@Currency');";
	   document.getElementById('additem_caption').innerHTML = "Add Currency"; 
	 } 
	if (tbl == "sales_person")
	 {
	   select_stmt = "select ID,SM_Code,SM_Name FROM sales_person ORDER BY SM_Name";	 
	   select_stmt_up = "update sales_person set SM_Code='@SM_Code',SM_Name='@SM_Name' where ID=@ID";
	   select_stmt_del = "delete from sales_person where ID=@ID";
	   select_stmt_ins = "insert into sales_person (SM_Code,SM_Name) values ('@SM_Code','@SM_Name');";
	   document.getElementById('additem_caption').innerHTML = "Add Sales Person"; 
	 }
	 
	if (tbl == "tax_group")
	 {
	   select_stmt = "select ID,tax_group FROM tax_group ORDER BY tax_group";	 
	   select_stmt_up = "update tax_group set tax_group='@tax_group' where ID=@ID";
	   select_stmt_del = "delete from tax_group where ID=@ID";
	   select_stmt_ins = "insert into tax_group (tax_group) values ('@tax_group');";
	   document.getElementById('additem_caption').innerHTML = "Add Tax Group"; 
	 } 
	 
	if (tbl == "payment_terms")
	 {
	   select_stmt = "select ID,payment_terms FROM payment_terms ORDER BY payment_terms";	 
	   select_stmt_up = "update payment_terms set payment_terms='@payment_terms' where ID=@ID";
	   select_stmt_del = "delete from payment_terms where ID=@ID";
	   select_stmt_ins = "insert into payment_terms (payment_terms) values ('@payment_terms');";
	   document.getElementById('additem_caption').innerHTML = "Add Payment Terms"; 
	 }  
	 
	if (tbl == "delivery_info")
	 {
	   select_stmt = "select ID,Delivery_Info FROM delivery_info ORDER BY Delivery_Info";	 
	   select_stmt_up = "update delivery_info set Delivery_Info='@Delivery_Info' where ID=@ID";
	   select_stmt_del = "delete from delivery_info where ID=@ID";
	   select_stmt_ins = "insert into delivery_info (Delivery_Info) values ('@Delivery_Info');";
	   document.getElementById('additem_caption').innerHTML = "Add Delivery Information"; 
	 } 
	 
	 if (tbl == "courier")
	 {
	   select_stmt = "select ID,courier FROM courier ORDER BY courier";
	   select_stmt_up = "update courier set courier='@courier' where ID=@ID";
	   select_stmt_del = "delete from courier where ID=@ID";
	   select_stmt_ins = "insert into courier (courier) values ('@courier');";
	   document.getElementById('additem_caption').innerHTML = "Add Courier"; 
	 }
	 
	if (tbl == "shipping_terms")
	 {
	   select_stmt = "select ID,shipping_terms FROM shipping_terms ORDER BY shipping_terms";	 
	   select_stmt_up = "update shipping_terms set shipping_terms='@shipping_terms' where ID=@ID";
	   select_stmt_del = "delete from shipping_terms where ID=@ID";
	   select_stmt_ins = "insert into shipping_terms (shipping_terms) values ('@shipping_terms');";
	   document.getElementById('additem_caption').innerHTML = "Add Shipping Terms"; 
	 }  
	 
	 if (tbl == "price_level")
	 {
	   select_stmt = "select ID,price_level FROM price_level ORDER BY price_level";	 
	   select_stmt_up = "update price_level set price_level='@price_level' where ID=@ID";
	   select_stmt_del = "delete from price_level where ID=@ID";
	   select_stmt_ins = "insert into price_level (price_level) values ('@price_level');";
	   document.getElementById('additem_caption').innerHTML = "Add Price Level"; 
	 } 
	 
	if (tbl == "supplier")
	 {
	   select_stmt = "select ID,Supplier FROM supplier ORDER BY Supplier";	 
	   select_stmt_up = "update supplier set Supplier='@Supplier' where ID=@ID";
	   select_stmt_del = "delete from supplier where ID=@ID";
	   select_stmt_ins = "insert into supplier (Supplier) values ('@Supplier');";
	   document.getElementById('additem_caption').innerHTML = "Add Supplier"; 
	 } 
	 
	 if (tbl == "POD")
	 {
	   select_stmt = "select ID,Country_Code, Country FROM countrycode ORDER BY Country";	 
	   select_stmt_up = "update countrycode set Country_Code='@Country_Code',Country='@Country' where ID=@ID";
	   select_stmt_del = "delete from countrycode where ID=@ID";
	   select_stmt_ins = "insert into countrycode (Country_Code,Country) values ('@Country_Code','@Country');";
	   document.getElementById('additem_caption').innerHTML = "Add POD"; 
	 } 
	 
	 
	document.getElementById('additem_info_tbl').value = tbl; 
	document.getElementById('additem_info_tdid').value = tdid; 
	document.getElementById('additem_info_selid').value = selid; 
	
	grid_additem.attachData("additem_datasource",select_stmt);
	grid_additem.attachData("additem_up_datasource",select_stmt_up);
	grid_additem.attachData("additem_del_datasource",select_stmt_del);
	grid_additem.attachData("additem_ins_datasource",select_stmt_ins);
		
    grid_additem.refresh();
    grid_additem.commit();
}

function hide_add_pop()
{
	document.getElementById('float_additem').style.display = "none";  
	Popup.hide('float_additem');
}

function show_pop_up(id)
{
	document.getElementById(id).style.display = "none";  
	Popup.showModal(id);
}

function hide_pop_up(id)
{
	document.getElementById(id).style.display = "none";  
	Popup.hide(id);
}

function echeck(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 ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   // alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   // alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   // alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
	
function convert_CN_ToEntities(tstr) 
 {
  var bstr = '';

  for (i=0; i<tstr.length; i++) 
   {
	  if (tstr.charCodeAt(i)>127)  
	   {
		bstr += '#' + tstr.charCodeAt(i) + ';';
		
		//bstr += tstr.charCodeAt(i) + ';';
	   } 
	  else 
	   {
	  bstr += tstr.charAt(i);
	   }
   }
   
   return bstr;
 }
 

function convert_CN_To_Entities(tstr) 
 {
  var bstr = '';

  for (i=0; i<tstr.length; i++) 
   {
	  if (tstr.charCodeAt(i)>127)  
	   {
		bstr += '&#' + tstr.charCodeAt(i) + ';';
		
		//bstr += tstr.charCodeAt(i) + ';';
	   } 
	  else 
	   {
	  bstr += tstr.charAt(i);
	   }
   }
   
   return bstr;
 } 	

function convertthis_date_js(dte)
{
 var thisdate = dte.split("/");
 var returndate = thisdate[2]+"-"+thisdate[0]+"-"+thisdate[1];
 return returndate;
}

function change_language(lang)
{
	               var xmlHttp = ajaxFunction();
				   var params = "typ=change_language&lang="+lang;
			       xmlHttp.open("POST","get_data.php",true);
				   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				   xmlHttp.setRequestHeader("Content-length", params.length);
				   xmlHttp.setRequestHeader("Connection", "close");
				   xmlHttp.send(params);
				  
				  
				  xmlHttp.onreadystatechange=function()
					{
					if(xmlHttp.readyState==4)
					  {		
						 /*var get_result = trim(xmlHttp.responseText);	
						 alert(get_result);*/
						 window.location.reload();
					  }
					}
}

function SelectAll(id)
{
    document.getElementById(id).value = "";
	//document.getElementById(id).focus();
    //document.getElementById(id).select();
	//return;
}

function stripslashes (str) {
    
        return (str + '').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
        case '\\':
            return '\\';
        case '0':            return '\u0000';
        case '':
            return '';
        default:
            return n1;        }
    });
}

function login_now()
{
   var usr = document.getElementById("username").value; 
   var pwd = document.getElementById("password").value;
   var ResultData = koolajax.callback(doget_login(usr,pwd));
  
   var split_result = ResultData.split("|"); 
	     if (split_result[0] == "Success")
	      { 
			window.location = document.location.href;
		  }
		 else
		  {
			showLayer('popup_window'); 
			document.getElementById("poptext0").innerHTML = "Log-In Failed!";
			document.getElementById("poptext1").innerHTML = "Access Denied!";
			document.getElementById("poptext2").innerHTML = "Please check you username and password.  Make sure your account has been activated. If you have any question please dont hesitate to email us at support@toyntoys.com. We will try our outmost best to answer your questions. Please allow us 24 hours within business day to reply to your emails.";
			document.getElementById("poptext3").innerHTML = "Thank you.";			
		  }

}

function logmeout()
{
	       var ResultDataLogOut = koolajax.callback(dolog_out("OK"));
		  
		   if (ResultDataLogOut == "OK")
		    {
		      window.location = "index.php";
			}
}

function shift_lang(siteDir)
{
	  
	  var shift_lang = document.getElementById('shift_lang').value;
	  var xmlHttp = ajaxFunction();	
	  		 
		           var params = "typ=Shift_Language&shiftTo="+shift_lang;
				   
			       xmlHttp.open("POST","get_data.php",true);
				   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				   xmlHttp.setRequestHeader("Content-length", params.length);
				   xmlHttp.setRequestHeader("Connection", "close");
				   xmlHttp.send(params);
				  
				  
				  xmlHttp.onreadystatechange=function()
					{
					if(xmlHttp.readyState==4)
					  {		
						 window.location.reload();
					  }
					}
		 
}
