
function trim(tmp)
{
	var temp;
	temp = tmp;
	//tmp = "      this is test     ";
	pat = /^\s+/;
	temp = temp.replace(pat, "");
	pat = /\s+$/;
	temp = temp.replace(pat, "");
	//alert(":" + tmp + ":");
	return temp;
}


/*
function trim(myval)
{
	var chklen=myval.length; 
	var pos=0;
	mychar = myval.charAt(0);

	while(pos>=0 || lstpos >=0)
	{
		pos=myval.indexOf(" ");
		if (pos==0)
		{
			myval=myval.substring(1,chklen);
			chklen = myval.length;
			mychar = myval.charAt(0);
		}
		lstpos=myval.lastIndexOf(" ");

		if (lstpos==chklen-1)
		{	
			myval=myval.substring(0,chklen-1);
			chklen=myval.length;
			mychar = myval.charAt(chklen-1);
		}
		
		if(mychar!=" ")
			break;

	}
	return myval;			
}
*/

function isEmail(str) 
{
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
	var tempStr = "a";
	var tempReg = new RegExp(tempStr);
	if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	  return (!r1.test(str) && r2.test(str));
}

function isLoginName(str)
{
	var pat = /[a-z,A-Z,0-9,\-,\_]+/g;
	var vr = str;
	var vr = vr.replace(pat,"");
	if (vr) { return false; }
	
	return true;
}

function checkInt(a)
{
	if (a.split(" ").join("").length ==0)
	{
		return false;
	}
	var Anum = "0123456789";
	for (i=0;i<a.length;i++)
	{
		if (Anum.indexOf(a.substr(i,1)) == -1)
		{
			//alert(Anum.indexOf(a.substr(i,1)) + "," + a.substr(i,1));
			return false;
		}
		
	}
	return true;
}

function checkFloat(a)
{
	if (a.split(" ").join("").length ==0)
	{
		return false;
	}
	var Anum = "0123456789.";
	for (i=0;i<a.length;i++)
	{
		if (Anum.indexOf(a.substr(i,1)) == -1)
		{
			return false;
		}
		
	}
	if (isNaN(a))
	{
		return false;
	}
	return true;
}

function FormatNumber(N, D)
// To format a given number upto specified decimals
{
	var r, ro, ra, s, No;
	
	r = 0;
	ro = 1;
	
	r = parseFloat(N);
	
	ro = parseInt(D+1);
	
	ro = parseFloat(1*(Math.pow(10, ro)));
	
	ra = parseFloat(5/ro);

	r = parseFloat(r + ra);
			
	ro = parseFloat(ro/10);
	
	r = parseFloat(r*ro);
	
	r = parseInt(r);
	
	r = parseFloat(r/ro);
	
	s = new String(r);		
	
	if (s.indexOf(".") == -1)
	{
		r = r + ".00";
	}
	else
	{
		
		if ((s.substr(s.indexOf(".")+1)).length == 1)
		{
		r = r + "0";
		}
	}
	
	return r;
}			


function cancelOrder()
{
	if (confirm("Are you sure you want to cancel the order process"))
	{
		document.frm.action = "http://www.postaposter.com/default.asp";
		document.frm.submit();
	}
}


function SetFocusYear()
{
	if (trim(document.frm.ExpiryDateMM.value)=="")
		return true;
		
	var s = new String(document.frm.ExpiryDateMM.value);
	
	if (s.length == 2)
	{
		document.frm.ExpiryDateYY.focus();
		document.frm.ExpiryDateYY.select();
		return true;
	}
}

function SetFocusYear2()
{
	if (trim(document.frm.StartDateMM.value)=="")
		return true;
		
	var s = new String(document.frm.StartDateMM.value);
	
	if (s.length == 2)
	{
		document.frm.StartDateYY.focus();
		document.frm.StartDateYY.select();
		return true;
	}
}
