

  function xmlhttpPost(strURL, divName, txtObj) {

	 // alert(strURL);

    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) 

		{

			var val = self.xmlHttpReq.responseText;		

			if(val != '')	{						

			 document.getElementById(divName).innerHTML=self.xmlHttpReq.responseText;

			 txtObj.value='';	

			 txtObj.focus();			 

			}

			else 

			document.getElementById(divName).innerHTML='';			

		}

    }

    self.xmlHttpReq.send('');

  }

   

   

   

   function defaulthttpPost(strURL,divName) {

  // alert(divName);

  // alert(strURL);

   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) 

		{

			var val = self.xmlHttpReq.responseText;		

			if(val != '')	{		



			 document.getElementById(divName).innerHTML=self.xmlHttpReq.responseText;

			 document.getElementById(divName).style.display = '';

			// setTimeout('test()',2000);

//			 txtObj.focus();//txtObj.value='';	

			}

			else{ 

									

				document.getElementById(divName).innerHTML='';			

				

			}

		}

    }

 

    self.xmlHttpReq.send('');

  }





function doAjax(strURL,strPostData,strObj,method,strProgressMessage,nTime,fn) {

    var xmlHttpReq = false;

    var self = this;

	var msg="";

    // Mozilla/Safari

	

	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) 

		{

			

			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 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 uplaodBackGround(field, id)		

{

	var mywindow=window.open("uploadPopUp.php?field="+field+"&id="+id,"mywindow","location=0,status=0,scrollbars=1,width=400,height=300");

	mywindow.moveTo(350,175);

}



function toPost(getString) 

{

	var parms = getString.split('?'); 

	var newF = document.createElement("form");

	newF.action = parms[0];

	newF.method = 'POST';

	var parms = parms[1].split('&');

	for (var i=0; i<parms.length; i++) 

	{

		var pos = parms[i].indexOf('=');

		if (pos > 0) {var key = parms[i].substring(0,pos);

		var val = parms[i].substring(pos+1);

		var newH = document.createElement("input"); newH.name = key;

		newH.type = 'hidden'; 

		newH.value = val; newF.appendChild(newH);

		}

	}

	document.getElementsByTagName('body')[0].appendChild(newF); newF.submit();

}



function v_numeric(string)

{

    string = trim(string);

    if(parseInt(string) > 0)

    {

        if(string.match(/^[0-9]+$/))

        {

            return true;

        }

        else

        {

            return false;

        }

    }

    else

    {

        return false;

    }

}





function validateEmail(email)

{

		var at = email.lastIndexOf("@");



		// Make sure the at (@) sybmol exists and  

		// it is not the first or last character

		if (at < 1 || (at + 1) === email.length)

			return false;



		// Make sure there aren't multiple periods together

		if (/(\.{2,})/.test(email))

			return false;



		// Break up the local and domain portions

		var local = email.substring(0, at);

		var domain = email.substring(at + 1);



		// Check lengths

		if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)

			return false;



		// Make sure local and domain don't start with or end with a period

		if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))

			return false;



		// Check for quoted-string addresses

		// Since almost anything is allowed in a quoted-string address,

		// we're just going to let them go through

		if (!/^"(.+)"$/.test(local)) {

			// It's a dot-string address...check for valid characters

			if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))

				return false;

		}





		// Make sure domain contains only valid characters and at least one period

		if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)

			return false;	



		return true;



}

