function IsDigit(o,e) {
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	if (((code < 48)||(code > 57 ))) 
	{		
		return false;	
	}
}
function checkDigit(objParam)
{
	var str = document.getElementById(objParam).value;
	var str1 = "";
	for (i = 0 ;i <= str.length ;i++ )
	{
		for (j = 0; j < 10 ;j++ )
		{
			if (str.charAt(i) == j)
			{
				str1 = str1 + str.charAt(i);
			}
		}
	}
	document.getElementById(objParam).value = str1;
	
}
function limitText(limitFieldID, limitCountID, limitNum) {
	if (document.getElementById(limitFieldID).value.length > limitNum) {
		document.getElementById(limitFieldID).value = document.getElementById(limitFieldID).value.substring(0, limitNum);
	} else {
		document.getElementById(limitCountID).value = limitNum - document.getElementById(limitFieldID).value.length;
	}
}

function Trim(inputString)
{
	var retValue = inputString;
	var ch = retValue.substring(0, 1);

	while (ch == " ")
	{ // Check for space at the start of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}

	ch = retValue.substring(retValue.length-1, retValue.length);

	while (ch == " ")
	{ // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}	
	return retValue;
}
function popUp(URL, w, h) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+"');");
}
function IsEmpty(v){
	varValue = Trim(v);
	if (varValue.length == 0){ return true; }else{ return false; }
}
function IsValidEmail(str){
	var at = '@';
	var dot = '.';
	var lat = parseInt(str.indexOf(at));
	var ldot = parseInt(str.lastIndexOf(dot));
	var lstr = parseInt(str.length);
	
	//no '@' or '@' is first character or '@' is the last character
	if ((lat <= 0) || (lat == parseInt(lstr-1)))
		return false;

	//no '.' or '.' is first character or '.' is the last character
	if ((ldot <= 0) || (ldot == parseInt(lstr-1)))
		return false;

	//presence of another '@'
	if (str.indexOf(at, parseInt(lat+1)) != -1) 
		return false;

	//presence of '.' before or after '@'
	if ((str.substr(parseInt(lat - 1), 1) == dot) || (str.substr(parseInt(lat + 1), 1) == dot))
		return false;

	//check '.' is at least one character after '@'
	if (str.indexOf(dot, parseInt(lat + 2)) == -1) 
		return false;

	//check for blank
	if (str.indexOf(" ") != -1) 
		return false;

	//check the length after the last '.' is not less than 2 characters
	if (str.substr(parseInt(ldot + 1)).length < 2) 
		return false;

	if (!IsAlphaNumeric(str.substr(ldot + 1)))
		return false;	
	
	return true;
}
function IsValidPassword(v){
	if (IsAlphaNumeric(v)) {
		if (v.length < 6) { return false; } else { return true; }
	} else { return false; }
}
function IsAlphaNumeric(str){
	for (i=0; i<str.length; i++){
		if (!((str.charCodeAt(i)>=97) && (str.charCodeAt(i)<=122)) && !((str.charCodeAt(i)>=65) && (str.charCodeAt(i)<=90)) && !((str.charCodeAt(i)>=48) && (str.charCodeAt(i)<=57))){
			return false;
		}
	}
	return true;
}

function clearText(objParam){
	document.getElementById(objParam).value = "";
}



function validate_Submit(){
	if (IsEmpty(document.getElementById("name").value))
	{
		alert("Please enter your name.");
		document.getElementById("name").focus();
		return;
	}
	if (IsEmpty(document.getElementById("email").value))
	{
		alert("Please enter your email address.");
		document.getElementById("email").focus();
		return;
	}
	else
	{
		if (!IsValidEmail(document.getElementById("email").value))
		{
			alert("Please enter a valid email address.");
			document.getElementById("email").focus();
			return;
		}
	}
	if (IsEmpty(document.getElementById("contact").value))
	{
		alert("Please enter your contact no.");
		document.getElementById("contact").focus();
		return;
	}
	if (IsEmpty(document.getElementById("receipt").value))
	{
		alert("Please enter your receipt no.");
		document.getElementById("receipt").focus();
		return;
	}
	if (IsEmpty(document.getElementById("address").value))
	{
		alert("Please enter your address.");
		document.getElementById("address").focus();
		return;
	}
	if (IsEmpty(document.getElementById("country").value))
	{
		alert("Please enter your country.");
		document.getElementById("country").focus();
		return;
	}
	if (IsEmpty(document.getElementById("postalcode").value))
	{
		alert("Please enter your postal code.");
		document.getElementById("postalcode").focus();
		return;
	}
	document.getElementById("form1").action = "venetto1.php";
	document.getElementById("form1").submit();
}


