function ajaxcountrystate(holder,strupdate) 
{    
	
	val=document.getElementById(holder).value;
	
	strURL="ajaxcountrystate.php?cid="+val;
	//alert(strURL+"-------------"+strupdate) 
	var xmlHttpReq = false;
    var self = this;
	
    // Mozilla/Safari
    if (window.XMLHttpRequest) 
	{
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) 
	{
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() 
	{
      if (self.xmlHttpReq.readyState == 4) 
	  {
	//alert(self.xmlHttpReq.responseText);
	
		
	  	argstr=self.xmlHttpReq.responseText;
		argctrl="document.getElementById('" + strupdate + "').options";
		
		var ctrl = eval(argctrl)
		var prezar = argstr.split("|");
		argctrl.length = 0;
		
	 	for (var i=ctrl.length-1; i>=0; i--)
		  {
			ctrl[i] = null;
		  }
		
	
		for (o=0; o < prezar.length-1; o++)
		{
		  splitarr = prezar[o].split(":");
		  ctrl[ctrl.length] = new Option(splitarr[1], splitarr[0]);
		}
	  
	  }
    }	
    self.xmlHttpReq.send('');
}

function ajaxmodel(holder,strupdate) 
{    
	
	val=document.getElementById(holder).value;
	
	strURL="ajaxmodel.php?prod_brand="+val;
	//alert(strURL+"-------------"+strupdate) 
	var xmlHttpReq = false;
    var self = this;
	
    // Mozilla/Safari
    if (window.XMLHttpRequest) 
	{
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) 
	{
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() 
	{
      if (self.xmlHttpReq.readyState == 4) 
	  {
	//alert(self.xmlHttpReq.responseText);
	
		
	  	argstr=self.xmlHttpReq.responseText;
		argctrl="document.getElementById('" + strupdate + "').options";
		
		var ctrl = eval(argctrl)
		var prezar = argstr.split("|");
		argctrl.length = 0;
		
	 	for (var i=ctrl.length-1; i>=0; i--)
		  {
			ctrl[i] = null;
		  }
		
	
		for (o=0; o < prezar.length-1; o++)
		{
		  splitarr = prezar[o].split(":");
		  ctrl[ctrl.length] = new Option(splitarr[1], splitarr[0]);
		}
	  
	  }
    }	
    self.xmlHttpReq.send('');
}




function check_unique_entry(field_id, update_id, t, f, value)
{
	//alert(t+f+value);
strURL="checkemailuser.php?t="+t+"&f="+f+"&v="+value;

//alert(strURL);
if(document.getElementById(field_id).value=='')
return false;
var xmlHttpReq = false;
var self = this;
	
    // Mozilla/Safari
		if (window.XMLHttpRequest) 
		{
			self.xmlHttpReq = new XMLHttpRequest();
		}
		// IE
		else if (window.ActiveXObject) 
		{
			self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() 
	{
      if (self.xmlHttpReq.readyState == 4) 
	  {
		//  alert(self.xmlHttpReq.responseText);
			if(self.xmlHttpReq.responseText==0)
			{
				document.getElementById(update_id).innerHTML="<font color='#ff0000' size='+1'>Already Exist</font>";
				document.getElementById(field_id).focus();
				document.getElementById(field_id).value='';
				
			}
			else
			{
			document.getElementById(update_id).innerHTML="<font color='#006600' size='+1'>Available</font>";
			}
		}
	 }
	  
   self.xmlHttpReq.send('');
}

function doAjax(strURL,strPostData,strObj,method,strProgressMessage,nTime,fn) {
    var xmlHttpReq = false;
    var self = this;
	var msg="";
    // Mozilla/Safari
/*alert(strURL);
strURL=urlencode(strURL);*/
//alert(strURL);
	www=(window.location.href.toLowerCase().indexOf("//www.")>0)?"http://www.":"http://";
	strURL=strURL.replace("http://",www);
	updateMessage(strObj,strProgressMessage);

    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open(method, strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
		
        if (self.xmlHttpReq.readyState == 4) 
		{
			//alert(self.xmlHttpReq.responseText);
			msg=(strObj+"~|~"+self.xmlHttpReq.responseText).split("~|~");
			
			for (i=0;i<msg.length;i=i+2)
			{
				
				updateMessage(msg[i],msg[i+1]);
			}
			
			switch(fn)
			{
				case "renderProductOptions":				
				
					removeItemRow();
					updateMessage(strObj,"Inventory updated successfully!");
					renderProductOptions(self.xmlHttpReq.responseText);
					
					break;
					case 'delete':
					 window.location.reload();
					break;
				/*case 'reload':
					window.location.reload();
					break;*/
				case null:
					break;
			}
			
			if (nTime>0) setTimeout("hide('"+strObj+"');",nTime);
        }
		else
		{
			//alert(self.xmlHttpReq.readyState);
		}
    }
	
    self.xmlHttpReq.send(strPostData);
}

function removeItemRow()
{
  var tbl = document.getElementById('tblGroups');
  var lastRow = tbl.rows.length;
  var iteration = lastRow;
  for (i=3;i<iteration;i++)
  {
  	tbl.deleteRow(tbl.rows.length-1);
	
  }

}


function updateMessage(obj,str)
{
	show(obj);	
	document.getElementById(obj).innerHTML=str;
}

function showHide(id)
{
	if (document.getElementById(id).style.display=='')
		document.getElementById(id).style.display='none';
	else
		document.getElementById(id).style.display='';
		
}
function show(id)
{
		document.getElementById(id).style.display='block';
		
}
function hide(id)
{
		document.getElementById(id).style.display='none';
}
function updateLinks(divid, n){
	var i=1;
	while(1){
		if(!document.getElementById(divid+i)) break;
		document.getElementById(divid+i).style.color='#000000';
		i++;
	}
	document.getElementById(divid+n).style.color="#FF0000";
}
function updateSize(n){
	var i=0;
	while(1){
		if(!document.getElementById('upps'+i)) break;
		document.getElementById('upps'+i).style.color='#000000';
		document.getElementById('dnps'+i).style.color='#000000';
		i++;
	}
	document.getElementById('upps'+n).style.color="#FF0000";
	document.getElementById('dnps'+n).style.color="#FF0000";
}
function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                                     
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}
function checkbothmail(mail1, mail2)
{
 if(document.getElementById(mail1).value=="")	
{
	alert("Enter Login Email");
	return false;
}
else if(document.getElementById(mail2).value=="")	
{
	alert("Enter Confirm Login Email");
	return false;
}
else if(document.getElementById('emp_password').value=="")	
{
	alert("Enter Password");
	return false;
}
else if(document.getElementById(mail1).value!=document.getElementById(mail2).value)	
{
	alert("Confirm Email is Not Matched!");
	return false;
}
}
function updatePaging(url)
{

}
