// JavaScript Document
/*
// email validation
//--------------------------
var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[a-zA-Z]$"
var regex = new RegExp(emailReg);
//i.e. regex.test(_email) == false
//-------------------------
// accept string
// return: string

// accept string
// return: bool

// accept email string
// return: bool
*/
function isMoney(elm) {
     str = elm.replace("$", "");
     str = str.replace(",","");      //regex=/^[a,b,c,x,y,z]{3}\d{3}$/;
     //var myexp = /^\d+\.\d{0,2}$/;
	 var myexp = /^\d+\.\d{0,2}$/;
	 var regex = new RegExp(myexp);
	 chk = regex.test(str);
	 if(chk==false) {
			str = str + '.00'; 
	 }
	 //alert(str);
     return regex.test(str);
}
function checkmail(email){
		var _email = email;
		var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
		var returnval = emailfilter.test(_email);			
		return returnval;
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function validatetForm(form) {
	var _fname = trim(form['fname'].value);
	var _lname = trim(form['lname'].value);
	var _email = trim(form['email'].value);
	var _country = trim(form['country'].value);
	var _amount = trim(form['amount'].value);
	
	
	if(_fname.length==0) {
		alert("Enter your name.");
		form.fname.focus();
		return false;
	} else if(_lname.length==0) {
		alert("Enter your last name.");
		form.lname.focus();
		return false;
	} else if(_email.length==0) {
		alert("Enter your email address.");
		form.email.focus();
		return false;
	} else if(checkmail(_email) == false) {
		alert("Please provide a valid email address.");
		form.email.focus();
		return false;
	} else if(_country.length==0) {
		alert("Enter your country.");
		form.country.focus();
		return false;
	} else if(_amount.length==0) {
		alert("Enter an amount.");
		form.amount.focus();
		return false;
	} else if(isMoney(_amount)==false) {
		alert("Enter correct amount.");
		form.amount.focus();
		return false;
	}
	
	return true;
}
function SelectonChange(obj, id) {
		 txt=obj.options[obj.selectedIndex].text;
		 txtv=obj.options[obj.selectedIndex].value;
		 
		  var strInput = new String(txtv);
		  if(txtv.match('US')) {
					if(document.getElementById(id).style.display=='none')  {
								document.getElementById(id).style.display='block';
						}
			}
}