
function ValidateContactForm(frm) {
	var i = 0;
	var errormsg = "The following error(s) has occured in the form:\n\n";

	if (!frm.type[0].checked && !frm.type[1].checked && !frm.type[2].checked)
		errormsg += (++i) + ". Inquiry Type must be specified.\n";
	
	if (frm.location.selectedIndex<=0)
		errormsg += (++i) + ". Location must be specified.\n";

	if (frm.Name.value=="")
		errormsg += (++i) + ". Name cannot be empty.\n";

	if (frm.EmailAddress.value=="") {
		errormsg += (++i) + ". Email Address cannot be empty.\n";
	} else {
		if (!validEmail(frm.EmailAddress.value))
			errormsg += (++i) + ". Email address is of an invalid format.\n";
	}

	if (frm.OfficePhone.value=="" && frm.MobilePhone.value=="")
		errormsg += (++i) + ". Either one of Office Phone or Mobile Phone must be specified.\n";

	if (frm.Comments.value=="")
		errormsg += (++i) + ". Inquiry content cannot be empty.\n";

	if (i!=0) {
		alert(errormsg);
		return false;
	}  else {
		if (frm.type[1].checked) { //partnership
			if (frm.location.options[frm.location.selectedIndex].value=="cn")
				frm.recipient.value = "partnership@visualtron.com.sg";
			else
				frm.recipient.value = "partnership@visualtron.com.sg";
			frm.subject.value = "Online VisualGSM Partnership Inquiry";
			switch (frm.location.options[frm.location.selectedIndex].value) {
				case "cn":
					frm.subject.value += " (China)";
					break;
				case "hk":
					frm.subject.value += " (Hong Kong/Macau)";
					break;
				case "tw":
					frm.subject.value += " (Taiwan)";
					break;
				case "ww":
					break;
			}
		}
		if (frm.type[0].checked) { //sales
			frm.subject.value = "Online VisualGSM Sales Inquiry";
			switch (frm.location.options[frm.location.selectedIndex].value) {
				case "cn":
					frm.recipient.value = "sales.cn@visualtron.com.sg";
					frm.subject.value += " (China)";
					break;
				case "hk":
					frm.recipient.value = "sales.hk@visualtron.com.sg";
					frm.subject.value += " (Hong Kong/Macau)";
					break;
				case "tw":
					frm.recipient.value = "sales.tw@visualtron.com.sg";
					frm.subject.value += " (Taiwan)";
					break;
				case "ww":
					frm.recipient.value = "sales@visualtron.com.sg";
					break;
			}
		}
		
		if (frm.type[2].checked) { //sales
			frm.subject.value = "Apply for SMS2Email Keyword";
			switch (frm.location.options[frm.location.selectedIndex].value) {
				case "cn":
					frm.recipient.value = "support@visualtron.com.sg";
					frm.subject.value += " (China)";
					break;
				case "hk":
					frm.recipient.value = "support@visualtron.com.sg";
					frm.subject.value += " (Hong Kong/Macau)";
					break;
				case "tw":
					frm.recipient.value = "support@visualtron.com.sg";
					frm.subject.value += " (Taiwan)";
					break;
				case "ww":
					frm.recipient.value = "support@visualtron.com.sg";
					break;
			}
		}
		
		
		alert("Your inquiry will be submitted.  This process may take some time.  If you are encountering an error, please email us directly at support@visualtron.com.sg.");
		frm.submit();
		return true;
	}
}




// Open New Window
function openWindow(URL, WinName, Width, Height) {
	var newWin = window.open(URL,WinName,'resizable=yes,scrollbars=yes,width='+Width+',height='+Height+',left='+(screen.width-Width)/2+',top='+(screen.height-Height)/2+',toolbar=no');
	newWin.focus();
}

// Open New Window from Parent Window
function parentOpenWindow(URL, WinName, Width, Height) {
	var newWin = self.opener.open(URL,WinName,'resizable=yes,scrollbars=yes,width='+Width+',height='+Height+',left='+(screen.width-Width)/2+',top='+(screen.height-Height)/2+',toolbar=no');
	newWin.focus();
}

// Print a Page
function printit(){  
if (NS) {
    window.print() ;  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box 
WebBrowser1.outerHTML = "";  
}
}

// Validate if an input is of the correct Date format
function isdate(strDate){
   var strSeparator = "/"; //ÈÕÆÚ·Ö¸ô·û
   var strDateArray;
   var intYear;
   var intMonth;
   var intDay;
   var boolLeapYear;
   strDateArray = strDate.split(strSeparator);
   if(strDateArray.length!=3) return false;
   intYear = parseInt(strDateArray[2],10);
   intMonth = parseInt(strDateArray[1],10);
   intDay = parseInt(strDateArray[0],10);
   
   if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) return false;
   if(intMonth>12||intMonth<1) return false;
   if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intDay>31||intDay<1)) return false;
   if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30||intDay<1)) return false;
   if(intMonth==2){
      if(intDay<1) return false;
      boolLeapYear = false;
      if((intYear%100)==0){
         if((intYear%400)==0) boolLeapYear = true;
      }
      else{
         if((intYear%4)==0) boolLeapYear = true;
      }
      if(boolLeapYear){
         if(intDay>29) return false;
      }
      else{
         if(intDay>28) return false;
      }
   }
   return true;
}

// Check if it is a Valid 6-digit Number
       function ValidDM(str) {
         var num="0123456789";
        for(i=0;i<6;i++)if(num.indexOf(str.charAt(i))==-1)return(false);
        return true;
         }

// Check if it is a Valid Number
       function isNum(str) {
        var num="0123456789";
		var str1 = str;
        for(i=0;i<str1.length;i++)if(num.indexOf(str1.charAt(i))==-1)return(false);
        return true;
       }

// Check if it is a valid email
function validEmail(email) {
	invalidChars = " /:,;";
	if (email == "") {
		return false;
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar=invalidChars.charAt(i);
		if(email.indexOf(badChar,0) > -1) {
			return false;
		}
	}
	atPos = email.indexOf("@", 1);
	if (atPos == -1) {
		return false;
	}
	periodPos=email.indexOf(".", atPos);
	if (periodPos==-1){
		return false;
	}
	if (periodPos+3 > email.length) {
		return false;
	}
	if (email.charAt(email.length-1)==".") {
		return false;
	}
	return true;
}

