function alpha(value)
{
	
	len=value.length;
	chk1="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-() ";
	for(i=0;i<len;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function alphanum(value)
{
	len=value.length;
	chk1="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_. ";
	for(i=0;i<len;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function decimalNumber(value){

	len=value.length;
	chk1="1234567890.";
	for(i=0;i<len;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function number(value){
	
	len=value.length;
	chk1="1234567890";
	for(i=0;i<len;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;	
	}
	return true;
}
function phonenumber(value){

	len=value.length;
	chk1="1234567890-()";
	for(i=0;i<len;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function popwin(url,w, h)
{
	var x = Math.round((screen.availWidth - w) / 2);
	var y = Math.round((screen.availHeight - h) / 2);
	
	pollwindow=window.open(url,'pollwindow','top='+y+",left="+x+',status=no,toolbars=no,scrollbars=yes,width='+w+',height='+h+',maximize=no,resizable');
	pollwindow.focus();
	
}
function isEmail(emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}
	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
	   		}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
	   }	
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

// Make sure there's a host name preceding the domain.

	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}	
	return true;
}
function checkAll()
{
	var rs = (document.frmlist.abc.checked)?true:false;
	
	for(i=0;i<document.frmlist.elements.length;i++)
	{
	  	if(document.frmlist.elements[i].id == 'iId')
  		{
			document.frmlist.elements[i].checked = rs;
		}

	}  
}
function update(msg)
{
	
	for(i=0;i<document.frmlist.elements.length;i++)
	{
	  	if(document.frmlist.elements[i].id == 'csub')
  		{
			if(document.frmlist.elements[i].checked == true)
			{
			var val=confirm("Do you really want to "+msg+" the records ?" );
			if(val==true){
			document.frmlist.act.value=msg;
			document.frmlist.submit();
			return true;
			}
			else
			{return false;}
			}
			else
			{continue;}
		}

	}
	alert("Please select atleast one record");	
	return false;
}

function callupdate(id)
{

document.frmlist.id.value=id;
document.frmlist.act.value="Update";
document.frmlist.submit();
			
}

//This code lets you put a Bookmark Us message on your site that will bookmark the current page in the users browser once the "Bookmark Us" text is clicked. This script works across IE, Mozilla Firefox and Opera Browsers.
function addfav(title, url){
if (window.sidebar)
window.sidebar.addPanel(title, url, "");
else if (document.all)
window.external.AddFavorite(url, title);
}
//Call the JavaScript function from your page with the following:
//<a href="javascript:addfav('FunctionLibrary.com - PHP & JavaScript Code', 'http://www.functionlibrary.com')">Bookmark this Page</a>


function fprint()
{

	if(confirm("Once you press OK it will not allow you to print these orders again. Do you want to procede?")){
		window.print();
		with(document)
		{
			frmadd.act.value="print";
			frmadd.submit();
			return true;
		}
	}
	else{return false;}
}

function fprintp()
{
		window.print();
		return false;

}

function chgamt(amt1,amt2,additional){

switch(document.getElementById("nostore").value){

case "1":document.getElementById("totalAmount").value=amt1;break;
case "2":document.getElementById("totalAmount").value=amt2;break;
default:
//document.getElementById("totalAmount").value=parseInt((document.getElementById("nostore").value/2))*amt2+parseInt((document.getElementById("nostore").value%2))*additional;
if(document.getElementById("nostore").value>2)
document.getElementById("totalAmount").value=(parseInt(document.getElementById("nostore").value)-2)*additional+amt2;
document.getElementById("nostore").value=parseInt(document.getElementById("nostore").value);
if(document.getElementById("nostore").value==0){
document.getElementById("totalAmount").value=0;
alert("You will not configure any store if you do not enter valid number");}
break;

	}
	var num=eval(document.getElementById("totalAmount").value);
	document.getElementById("totalAmount").value=num.toFixed(2);
}
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
}

function ClickHereToPrint()
{
	try{ 
        var oIframe = document.getElementById('ifrmPrint');
        var oContent = document.getElementById('divToPrint').innerHTML;
        var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
        if (oDoc.document) oDoc = oDoc.document;
		oDoc.write("<html><head><title></title>");
		oDoc.write("</head><body onload='this.print();'>");
		oDoc.write(oContent + "</body></html>");	    
		oDoc.close(); 	    
    }
    catch(e){
	    self.print();
    }
}