//check numbers and set label style

//valid emails based on the top level domains
function emailCheck(input, lbltype) {
	emailStr = input.value.toLowerCase();
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
	var bValid = true;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|per|co|it)$/;
	var knownCtyPat=/^(|jp|kr|uk|us|cn|hk|sg|eu|it|au|my|)$/;
	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 (emailStr == '') {
		isBlank(this);
		return false;
	}
	if (matchArray==null) {bValid = false;	}
	else {
		var user=matchArray[1];
		var domain=matchArray[2];

		for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
				bValid = false;
			}
		}
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				bValid = false;
			}
		}

		if (user.match(userPat)==null) {
			bValid = false;
		}

		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					bValid = false;
				}
			}
			bValid = 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) {bValid = false;}
		}
		
		//if there is not country prefix
		if (domArr[domArr.length-1].length!=2){
			if (domArr[domArr.length-1].search(knownDomsPat)==-1) {bValid = false;}
		} else if (domArr[domArr.length-1].length==2){ //if there is a country prefix
			if (domArr[domArr.length-2].search(knownDomsPat)==-1) {bValid = false;}
		}

		if (len<2) {bValid = false;}

	}
	if (bValid == true) {if(lbltype){lbltype.style.color='black';}return true;} 
	else if (bValid == false) {
			//alert("Invalid entry.\n\nPlease enter a valid Email Address.");
			input.focus();
			if (lbltype) {
				lbltype.style.color='red';
			}
			return false;
	}
}

function isNumber(input,lbltype){
	var inputStr=input.value;

	var lblstyle = document.getElementById(lbltype);
	if(window.RegExp && inputStr){
	var regExp1 = /[^0-9]/
	//alert("Invalid entry.\n\nPlease ensure that entries are numbers only.");
	if(regExp1.test(inputStr)) {lbltype.style.color='red';input.focus();return false}; return true
	}
}

function isAlphaNum(input,lbltype){
	var inputStr=input.value
	var lblstyle = document.getElementById(lbltype);
	if(window.RegExp && inputStr){
		var regExp1 = /[^a-zA-Z0-9]/
		//alert("Invalid entry.\n\nPlease ensure that entries are alphanumeric only.");
		if(regExp1.test(inputStr)) {lblstyle.style.color='red';input.focus();return false}; return true
	}
}

function isYear(input){
	var inputStr=input.value
	if(window.RegExp && inputStr){
	var regExp1 = /\b\d{4}\b/
	//alert("Invalid entry.\n\nPlease ensure that year is in YYYY format.");
		if(!regExp1.test(inputStr)) {input.value="";input.focus();return false}; return true
	}
}

function isEmail(input,lbltype){
	var inputStr=input.value
	var lblstyle = document.getElementById(lbltype);
	if(window.RegExp && inputStr){
	var regstr1 = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)"
	var regstr2 = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"
	var regExp1 = new RegExp(regstr1)
	var regExp2 = new RegExp(regstr2)
	var regExp3 = /[^a-zA-Z0-9\-_.@]/
	if(!(!regExp1.test(inputStr) && regExp2.test(inputStr) && !regExp3.test(inputStr)) || !(inputStr.indexOf("@")>=0)) {alert("Invalid entry.\n\nPlease enter a valid Email Address.");input.value="";lbltype.style.color='red';input.focus();return false}; return true
}}

//start new
function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}
function CheckNum(input,min,type,lbltype,fldname) {
					if(type=="num") { 
						if (input.value == "" || input.value == null ) {  
							document.getElementById(lbltype).style.color = 'black';
							}else {
									var atxtNum = input
									var alblNum = document.getElementById(lbltype)
									var aminVal = min
									var atxtName = fldname 
									if (isNaN(atxtNum.value) == true){
										alert("Please enter numeric values to the " + atxtName + " field.");
										alblNum.style.color = 'red';
										atxtNum.select();
										atxtNum.focus();
										return false;
									}
									if (atxtNum.value.length < aminVal ) {
										alert("Please enter minimum of " + aminVal + " digits to the " + atxtName + " field.");
										alblNum.style.color = 'red';
										atxtNum.select();
										atxtNum.focus();
										return false;
									}
									alblNum.style.color = 'black';
									}
						}
				return true;
}
function CheckNumReq(input,min,type,lbltype,fldname) {
				if(type) { 
					if(type=="alphanum") { 
						if (input.value == "" || input.value == null ) {  
							document.getElementById(lbltype).style.color = 'red';
							}else {
									var atxtNum = input
									var alblNum = document.getElementById(lbltype)
									var aminVal = min
									var atxtName = fldname
									if (alphanumeric(atxtNum.value) == false){
										alert('Please enter alphanumeric values to the ' + atxtName + ' field. Special characters are not allowed.');
										alblNum.style.color = 'red';
										atxtNum.select();
										atxtNum.focus();
										return false;
									}
									if (atxtNum.value.length < aminVal ) {
										alert('Please enter minimum of ' + aminVal + ' characters to the ' + atxtName + ' field.');
										alblNum.style.color = 'red';
										atxtNum.select();
										atxtNum.focus();
										return false;
									}
									alblNum.style.color = 'black';
									}
						}
					if(type=="num") { 
						if (input.value == "" || input.value == null ) {  
							document.getElementById(lbltype).style.color = 'red';
							}else {
									var atxtNum = input
									var alblNum = document.getElementById(lbltype)
									var aminVal = min
									var atxtName = fldname 
									if (isNaN(atxtNum.value) == true){
										alert("Please enter numeric values to the " + atxtName + " field.");
										alblNum.style.color = 'red';
										atxtNum.select();
										atxtNum.focus();
										return false;
									}
									if (atxtNum.value.length < aminVal ) {
										alert("Please enter minimum of " + aminVal + " digits to the " + atxtName + " field.");
										alblNum.style.color = 'red';
										atxtNum.select();
										atxtNum.focus();
										return false;
									}
									alblNum.style.color = 'black';
									}
						}
				}
			return true;
}
//end new
function chkField(input,min,type,lbltype){
	if(type=="num") {isNumber(input,lbltype)}
	else if(type=="alphanum") {isAlphaNum(input,lbltype)}
	else {isBlank(input)}
	var inputStr=input.value
	var lblstyle = document.getElementById(lbltype);
	if(window.RegExp && inputStr){
	inputStr=inputStr.replace(/^\s+/,""); inputStr=inputStr.replace(/\s+$/,"")
	
	if(min && inputStr.length<min) {alert("Invalid entry.\n\nPlease enter a minimum of "+min+" characters.");lbltype.style.color='red';input.focus();return false;}}
	else {return true;}}
	
function chkminField(input,min,lbltype){
	var inputStr=input.value
	var lblstyle = document.getElementById(lbltype);
	if(window.RegExp && inputStr){
		inputStr=inputStr.replace(/^\s+/,""); inputStr=inputStr.replace(/\s+$/,"")
		if(min && inputStr.length<min) {
			alert("Invalid entry.\n\nPlease enter a minimum of "+min+" characters.");lbltype.style.color='red';input.value="";input.focus()
		}
	}
}
	
function chkMaxLen(input,max,count){
	var inputStr=input.value
	if(max && inputStr.length>max) {alert("Your message has exceeded the maximum length of "+max+" characters.\n\nPlease shorten your entry.");input.value=inputStr.substring(0,max);input.focus()}
	if(count) {count.value=input.value.length;input.blur();input.focus()}
}

var cmlTimer
function showMaxLen(input,max,count){
	cmlTimer=setTimeout("chkMaxLen(document."+input.form.name+"."+input.name+","+max+",document."+count.form.name+"."+count.name+")",1000)
}

function chkSelect(input){
	if(!input.length) {if(input.checked) return true}
	else {for(i=0;i<input.length;i++) {if(input[i].checked) return true}}
	return false
}

function isListSelChg(ff){
	return ff.options[ff.selectedIndex].defaultSelected
}

//
// Misc Form Field Check Functions
//

function isPrice(input){
var inputStr=input.value
if(window.RegExp && inputStr){
	var regExp1 = /[^0-9]/
	var regExp2 = /^[0-9]+\.\d{1,2}$/
	if(regExp1.test(inputStr) && !regExp2.test(inputStr)) {alert("Invalid entry.\n\nPlease ensure entry is a proper price value.");input.value="";input.focus();return false}; return true
}}

function noSpace(input){
var inputStr=input.value
if(window.RegExp && inputStr){
	var regExp1 = /\s/
	if(regExp1.test(inputStr)) {alert("Invalid entry.\n\nPlease do no use spaces for the entry.");input.value="";input.focus();return false}; return true
}}
function isBlank(input){
var inputStr=input.value
if(window.RegExp && inputStr){
	var regExp1 = /\S/
	if(!regExp1.test(inputStr)) {input.value="";return true}; return false
}}

//
// Date Functions
//

function writeDateList(dd){
for(i=1; i<=31; i++){
	if(i==parseInt(dd,10)) {document.write("<option value="+insZero(i,2)+" selected>"+insZero(i,2))}
	else {document.write("<option value="+insZero(i,2)+">"+insZero(i,2))}
}}

function isDate(day,month,year){
var cDate = new Date()
cDate.setDate(1);cDate.setFullYear(parseInt(year,10));cDate.setMonth(parseInt(month,10)-1);cDate.setDate(parseInt(day,10))
if(cDate.getDate()!=parseInt(day,10) || cDate.getMonth()!=(parseInt(month,10)-1) || cDate.getFullYear()!=parseInt(year,10)) {return false}
return true
}

function isFwdDate(sd,sm,sy,min,cd,cm,cy){
var sDate=new Date(); cDate=new Date()
sDate.setDate(1);sDate.setFullYear(parseInt(sy,10));sDate.setMonth(parseInt(sm,10)-1);sDate.setDate(parseInt(sd,10))
if(cd&&cm&&cy) {cDate.setDate(1);cDate.setFullYear(parseInt(cy,10));cDate.setMonth(parseInt(cm,10)-1);cDate.setDate(parseInt(cd,10))}
if(min) {cDate.setDate(cDate.getDate()+min)}
if(sDate.getTime()<cDate.getTime()) {return false}
return true
}
//-----------------------Check change pass ------------------------------------------
function checkpass(){
	var existpass = document.getElementById('txtcurpass');
	var lblexist = document.getElementById('lblcurpass');
	if (existpass.value != ''){
		lblexist.style.color = 'black';
		if (chkField(existpass,'6','alphanum',lblexist) == false ){return false;} 
		else { 
			var newpass = document.getElementById('txtnewpass');
			var cfmpass = document.getElementById('txtcfmpass');
			var lblnewpass = document.getElementById('lblnewpass');
			var lblcfmpass = document.getElementById('lblcfmpass');
			if ((newpass.value == '')||(cfmpass.value == '')){
				lblnewpass.style.color = 'red';
				lblcfmpass.style.color = 'red';
				return false;
			} 
			if ((chkField(newpass,'6','alphanum',lblnewpass) == false ) ||(chkField(cfmpass,'6','alphanum',lblcfmpass) == false )){return false;} else {
				if (newpass.value != cfmpass.value){
					alert('The new password you entered does not match. Please enter you new password again.');
					
					lblnewpass.style.color = 'red';
					lblcfmpass.style.color = 'red';
					return false;
				} else {
					lblnewpass.style.color = 'black';
					lblcfmpass.style.color = 'black';
				}
			}
		}
	}else {
		alert('Please enter your existing password.');
		lblexist.style.color = 'red';
		return false;
	}
}
function checkpassnew(f, type){
	var bvalidate = true;
	if (type=='chkpass'){
		var oldpass = f.txtcurpass.value;
		var newpass = f.txtnewpass.value;
		var cfmpass = f.txtcfmpass.value;
		var lblcur = document.getElementById('lblcurpass');	
		var lblnew = document.getElementById('lblnewpass');
		var lblcfmnew = document.getElementById('lblcfmpass');
		if (oldpass == ''){
			alert('Please enter your current password.');
			lblcur.style.color='red';
			lblnew.style.color='black';
			lblcfmnew.style.color='black';
			return false;
		}
		if ((oldpass != '') && (newpass == '')){
			alert('Please enter your new password.');
			lblcur.style.color='black';
			lblnew.style.color='red';
			lblcfmnew.style.color='black';
			return false;
		}
		if ((oldpass != '') && (newpass != '') && (cfmpass =='')){
			alert('Please confirm your new password.');
			lblcur.style.color='black';
			lblnew.style.color='black';
			lblcfmnew.style.color='red';
			return false;
		}
		if ((oldpass != '') && (newpass != '') && (cfmpass !='')){
			if (newpass != cfmpass ){
				alert('The new password you entered does not match. Please enter you new password again.');
				lblcur.style.color='black';
				if (lblnew){lblnew.style.color='red';}
				if (lblcfmnew){lblcfmnew.style.color='red';} 
				return false;
			} else {
				if (lblnew){lblnew.style.color='black';}
				if (lblcfmnew){lblcfmnew.style.color='black';} 
			}
		}
		else if ((oldpass == '') && (newpass != '') || (cfmpass !='')){
			alert('Please enter your current password.')
			lblcur.style.color='red';
			return false;
		}
		}	
		if (bvalidate == false){
		alert('Please check the compulsory fields highlighted in red.');
		}
		return bvalidate;
}

//------------------------Check Recipient Delivery Page-------------------------------------
function checkrec(f) {
	var bvalidate;
	for (var i=0; i<f.elements.length;i++){
		var eletype = f.elements[i].type;
		var elename = f.elements[i].name;
		
		if (eletype =='text') {
			var elelabelname = elename.replace('txt','lbl');
			var elelabel = document.getElementById(elelabelname);
			var eleobj = document.getElementById(elename);

			if ((elename =='txtrecFName') ||(elename =='txtrecLName')){
				if (eleobj.length <= 0){
					bvalidate = false;
					if (elelabel) {
						elelabel.style.color='red';
					}
					eleobj.focus();
				} else {elelabel.style.color='black';}
			}
			if ((elename=='txtrecEmail') && (eleobj!=null)){
				if (eleobj.value != '') {
					if (emailCheck(eleobj, elelabel)==false){
						bvalidate = false;
						elelabel.style.color='red';
					} else {elelabel.style.color='black';}
				} 
			}
			if ((elename=='txtrecHP') && (eleobj !=null)){
				if (eleobj.value.length > 0){
					if (chkField(eleobj,7,'num',elelabel)==false){
						bvalidate = false;
						elelabel.style.color='red';
					} else {elelabel.style.color='black';} 
				}
			}
			if ((elename=='txtrecAdd1') && (eleobj!=null)){
				var elevalue = eleobj.value;
				var elevalue2 = document.getElementById('txtrecAdd2').value;
				if (elevalue =='' && elevalue2==''){
					bvalidate = false;
					elelabel.style.color='red';
					eleobj.focus();
				} else if (elevalue !='' ){
					elelabel.style.color='black';
				}
			}
			if ((elename=='txtrecPostal') && (eleobj!=null)){
				var elevalue = eleobj.value;
				if (elevalue ==''){
					bvalidate = false;
					elelabel.style.color='red';
					eleobj.focus();
				} else {
					elelabel.style.color='black';
					//var ctry = dcoument.getElementById('lblcountry');
					//alert(ctry.innerHTML.toUpper);
					if (chkField(eleobj,6,'alphanum',elelabel)==false){
						bvalidate = false;
						elelabel.style.color='red';
					}
				}
			}
				
			if ((elename=='txtrecContact') && (eleobj!=null)){
				var elevalue = eleobj.value;
				if (elevalue == '') {bvalidate = false;elelabel.style.color='red';eleobj.focus();}
				else{
					if (chkField(eleobj,7,'num',elelabel)==false){
						bvalidate = false;
						elelabel.style.color='red';
					} else {elelabel.style.color='black';} 
					} 
				}
		} //end of if eletype='text'
		else if (eletype =='radio') {
			var eleobj = document.getElementById(elename);
			if (elename == 'radHome'){
				var chkOffice = document.getElementById('radOffice');
				if (eleobj.checked == false && chkOffice.checked==false){
					bvalidate = false;
					alert('Please choose the contact number type.');
					
				}
			}
		}
	} //end of for loop
	
	if (bvalidate != false){
		bvalidate = true;
	}
	
	if (bvalidate == false){
		alert('Please check the compulsory fields highlighted in red.');
		return false;
	} else if (bvalidate == true) {
		return true;
	}
} // end of function
//-------------------------check default reminder------------------------------------------------------
function chkDFRemind() {
	
	var chk3days = document.getElementById('chkthreeday');
	var chk1wk = document.getElementById('chkoneweek');
	var chk2wk = document.getElementById('chktwoweek');
	var chk1mth = document.getElementById('chkonemonth');

	if ((chk3days.checked == false) && (chk1wk.checked == false) && (chk2wk.checked==false) && (chk1mth.checked == false)){
		alert('Please select when you wish to be reminded of this occasion.');
		return false;
	} 
}
//-------------------------check custom reminder------------------------------------------------------
function chkCTRemind() {
	var occ = document.getElementById('txtcustocc');
	
	var dayval = document.getElementById('cboday');
	var monthval = document.getElementById('cbomonth');
	var yearval = document.getElementById('cboyear');
	
	if (occ.value ==''){
		alert('Please enter an occasion name.');
		return false;
	}
	if (dayval.selectedIndex == -1  || monthval.selectedIndex == -1 ||yearval.selectedIndex ==-1 ){
		alert('Please select a date for the occsaion.');
		return false;
	} else {
		var dd = dayval.options[dayval.selectedIndex].value;
		var mm = monthval.options[monthval.selectedIndex].value;
		var yy = yearval.options[yearval.selectedIndex].value;
		if (!isFwdDate('dd','mm','yyyy',dayval,mm,yy)){	alert('Please ensure that the occasion date selected is valid.');return false;}
	}
	
	var chk3days = document.getElementById('chkcustthreeday');
	var chk1wk = document.getElementById('chkcustoneweek');
	var chk2wk = document.getElementById('chkcusttwoweek');
	var chk1mth = document.getElementById('chkcustonemonth');

	if ((chk3days.checked == false) && (chk1wk.checked == false) && (chk2wk.checked==false) && (chk1mth.checked == false)){
		alert('Please select when you wish to be reminded of this occasion.');
		return false;
	} 
}
//------------------------Check contacts---------------------------------------------------------------
function checkContact(f){
	var bvalidate;
	bvalidate = true;
	for (var i=0; i<f.elements.length;i++){
		var eletype = f.elements[i].type;
		var elename = f.elements[i].name;
		
		if (eletype =='text') {
			var elelabelname = elename.replace('txt','lbl');
			var elelabel = document.getElementById(elelabelname);
			var eleobj = document.getElementById(elename);
			/*
			if (elename == 'txtnickname'){
				if (eleobj.value == ''){
					elelabel.style.color = 'red';
					bvalidate = false;
				} else {
					elelabel.style.color = 'black';
				}
			}
			*/
			if (elename =='txtemail'){
				if (eleobj.value != ''){
					if (emailCheck(eleobj, elelabel)==false){
						bvalidate = false;
						elelabel.style.color='red';
					} else {elelabel.style.color='black';}
				} else {elelabel.style.color='black';}
			}
			if (elename == 'txtfname' || elename == 'txtlname'){
				if (eleobj.value == ''){
					elelabel.style.color = 'red';
					bvalidate = false;
				} else {
					elelabel.style.color = 'black';
				}
			}
			if (elename == 'txtadd1') {
				var eleadd = document.getElementById('lbladd');
				if (eleobj.value == ''){	
					eleadd.style.color = 'red';
					bvalidate = false;
				} else {
					eleadd.style.color = 'black';
				}
			}	
			if (elename == 'txtpostal'){
				if (eleobj.value == '') {
					elelabel.style.color = 'red';
					bvalidate = false;
				} else {
					if (chkField(eleobj,6,'alphanum',elelabel) == false){bvalidate = false;} 
					else {elelabel.style.color = 'black';}
				}
			}
			if (elename == 'txtcontact'){
				if (eleobj.value == ''){
					elelabel.style.color = 'red';
					bvalidate = false;
				} else{
					var radH = document.getElementById('radHome');
					var radO = document.getElementById('radOffice');
					if (radH.checked == false && radO.checked == false){
						alert('Please click on \'Home\' or \'Office\' button.');
						elelabel.style.color = 'red';
						bvalidate = false;
					} else {
						if (chkField(eleobj,7,'num',elelabel)==false){bvalidate = false;}
						else{elelabel.style.color = 'black';}
					}
				}
			} 
			if (elename == 'txtnewf'){
				var chknewf = document.getElementById('radNewf');
				if (eleobj.value != '' && chknewf.checked == false){
					alert('Please select the \'new folder\' button or clear the \'new folder\' field to continue');
					bvalidate = false;
				}
				else if (eleobj.value == '' && chknewf.checked == true){
					alert('Please enter a \'new folder\' name to continue');
					bvalidate = false;	
				}
			}
		}
	}
	if (!bvalidate){alert('Please check the compulsory fields highlighted in red.');}
	return bvalidate;
}
//-----------------------------------check tell a friend --------------------
//
function checktaf(f){
	var txtname = document.getElementById('txtname');
	var txtemail = document.getElementById('txtemail');
	var txtmsg = document.getElementById('txtmsg');
	if (txtname.value =='' || txtemail.value ==''){
		alert('Please enter your name/email.');
		if (txtname.value==''){
		 var lblname = document.getElementById('lblname');
		 if (lblname){lblname.style.color = 'red';}
		}
		if (txtemail.value==''){
		 var lblemail = document.getElementById('lblemail');
		 if (lblemail){lblemail.style.color = 'red';}
		}
		return false;
		if (txtemail.value !=''){
			var validemail = emailCheck(txtrcpemail,'');
			if (validemail == false){
				return false;
			}
		}
	}
	if (txtmsg.value ==''){
		alert('Please enter the message that you would like to tell your friend(s).');
		return false;
	}
}
//------------------------Check send wishlist fields------------------------------------------------------
function checksendlist(length){
	
	var contact;
	contact = 0;
	var txtmsg = document.getElementById('txtmsg');
	if (txtmsg) {
		if (txtmsg.value == ''){
			alert('Please enter the message that you would like to send out with this wishlist.');
			return false;
		}
	}
	for (var i=1;i<length;i++){
		var rcpname,rcpemail;
		rcpname = 'txtrcpname' + i;
		rcpemail = 'txtrcpemail' + i;
		
		var txtrcpname = document.getElementById(rcpname);
		var txtrcpemail = document.getElementById(rcpemail);
		if ((txtrcpname.value=='') && (txtrcpemail.value=='') && contact == 0){
			contact = 0;
		} 
		else if (((txtrcpname.value=='') && (txtrcpemail.value!='')) || ((txtrcpname.value!='') && (txtrcpemail.value==''))){
			alert('Please ensure the name and email are entered in pairs.');
			return false;
		}
		else if ((txtrcpname.value!='') && (txtrcpemail.value!='')) {
			var validemail;
			contact += 1;
			validemail = emailCheck(txtrcpemail,'');
			if (validemail== false){return false;}
			else if (validemail==true) {if (chkRepeat(txtrcpemail,length)==false){return false;}}
		}
	}

	if (contact == 0){			
		alert('Please enter at least one contact name and corresponding email.');
		return false;
	}else if (contact>0){return true;}
}
//-------------------------------------check for repeat email in send wish list-----------------------------
function chkRepeat(g,length){
	var obj,compareobj;
	compareobj = document.getElementById(g);
	
	for(i=1;i<length;i++){
		obj=document.getElementById('txtrcpemail'+i);
		if (obj && obj.value!=''){
			if(obj!=g && obj.value==g.value) {alert('Please note that email cannot be repeated.');return false;}
		}
	}
	return true;
}
//------------------------Validate Member Registration----------------------------------------------------
function memberSignUp(f, type) {
	
	var bvalidate = true;
	for (var i=0; i<f.elements.length;i++){
		var eletype = f.elements[i].type;
		var elename = f.elements[i].name;
			
		//loop thru all the textbox element
		if ((eletype =='text') ||(eletype =='password' ) ) {
			var elelabelname = elename.replace('txt','lbl');
			var elelabel = document.getElementById(elelabelname);
			var eleobj = document.getElementById(elename);
			if ((elelabel) && (eleobj)){
				
				//--new for email, regpass as required fields
				if (elename=='txtemail' && eleobj.value != '' ){
						
					if (emailCheck(eleobj,elelabel) == false){
						bvalidate = false;
						elelabel.style.color = 'red';
					} else {elelabel.style.color = 'black';}
				} else if (elename == 'txtemail' && eleobj.value == ''){
					bvalidate = false;
					elelabel.style.color='red';
				}
				
				if (elename == 'txtregpass'){
					if (eleobj.value == ''){
						bvalidate = false;
						elelabel.style.color = 'red';
					}
				}
				//
				
				//if (type == 'chkreg'){
				if (elename == 'txtregcfmpass'){
					var regpass = document.getElementById('txtregpass');
					if (eleobj.value == '' || regpass.value == '') {
						//alert('Please enter a password.');
						bvalidate = false
						elelabel.style.color = 'red';
						//return false;
					} else {
						if ((eleobj.value != regpass.value)) {
							//alert("Please re-confirm your password.");
							elelabel.style.color = 'red';
							document.getElementById('lblregpass').style.color = 'red';
							bvalidate = false;
							//return false;
						} else if (eleobj.value == regpass.value) {
							elelabel.style.color = 'black';
							document.getElementById('lblregpass').style.color = 'black';
						}
					}
				}
				//}
				 
				//--new for chkreg2 in m_register.aspx
				/*
				if (type == 'chkreg2'){
					if (elename == 'txtregcfmpass') {
						var regpass = document.getElementById('txtregpass');
						if (eleobj.value == '' || regpass.value == '') {
							alert('Please enter your password.');
							bvalidate = false
							elelabel.style.color = 'red';
							//return false;
						} else {
							if ((eleobj.value != regpass.value)) {
								alert("Please re-confirm your password.");
								elelabel.style.color = 'red';
								document.getElementById('lblregpass').style.color = 'red';
								bvalidate = false;
							} else if (eleobj.value == regpass.value) {
								elelabel.style.color = 'black';
								document.getElementById('lblregpass').style.color = 'black';
							}
						}
					}
				}
				*/
				//-- end for chckReg2 in m_register.aspx
				if ((elename == 'txtfname') || (elename == 'txtlname')){
					if (eleobj.value == '') {
						bvalidate = false;
						elelabel.style.color = 'red';
					} else {elelabel.style.color = 'black';}
				}
				
				if (elename == 'txtadd'){
					if (eleobj.value == ''){
						bvalidate = false;
						elelabel.style.color = 'red';
					} else {elelabel.style.color = 'black';}
				}
				/*
				var cboctry = document.getElementById('cbocountry');
				var selctry = cboctry.options[cboctry.selectedIndex].value;
				var lblcity = document.getElementById('lblcity');
				if (selctry != 'SG'){
					if (elename=='txtcity' ){
					lblcity.innerHTML='City *'
						if (eleobj.value == '' ){
							bvalidate = false;
							elelabel.style.color='red';		
						} else {elelabel.style.color = 'black';}
					} 
				} else {
					lblcity.innerHTML = 'City';
				}
				*/
				
				if (elename == 'txtcity'){
					if (eleobj.value == ''){
						bvalidate = false;
						elelabel.style.color = 'red';
					}  else {
						elelabel.style.color='black';
					}
				}
				var cboctry = document.getElementById('cbocountry2');
				var selctry = cboctry.options[cboctry.selectedIndex].value;
				var lblctry = document.getElementById('lblcountry');
				if (selctry == 'HK' || selctry == 'HK ') {
					if (elename == 'txtpostal'){
						elelabel.style.color = 'black';
					}
				} else {
						if (elename == 'txtpostal'){
						if (eleobj.value == ''){
							bvalidate = false;
							elelabel.style.color = 'red';
						} else {
							if (eleobj.value.length<4) {
								bvalidate = false;
								elelabel.style.color = 'red';
							} else {
								elelabel.style.color='black';
							}	
						}
					}
				}
				
				//check if home no or office no is blank
				//if (type == 'chkreg'){
				if (elename =='txthomeno' || elename =='txtcontact') {
					if (eleobj.value == '') {
						//alert("Please provide at least 1 contact number - Home and/or Office.");
						elelabel.style.color = 'red';
						bvalidate = false
					} else if (eleobj.value != '' ) {
						if (eleobj.value.length < 7 ){
							elelabel.style.color = 'red';
							bvalidate = false
						}else{
							elelabel.style.color = 'black';
						}
					}
				}
				if (elename =='txthpno'){
					if (eleobj.value != '' && eleobj.value.length < 7){
						bvalidate = false
						elelabel.style.color='red';
					} else {
						elelabel.style.color='black';
					}
				}
				if (elename =='txtfaxno'){
					if (eleobj.value != '' && eleobj.value.length < 7){
						bvalidate = false
						elelabel.style.color='red';
					} else {
						elelabel.style.color='black';
					}
				}
				//}
				//--new for txtcontact.text
				/*if (type == 'chkreg2'){
					if (elename == 'txtcontact'){
						if (eleobj.value == ''){
							elelabel.style.color = 'red';
							bvalidate = false;
						} else {
							var radH = document.getElementById('radHome');
							var radO = document.getElementById('radOffice');
							if (radH.checked == false && radO.checked == false){
								alert('Please click on \'Home\' or \'Office\' button.');
								elelabel.style.color = 'red';
								bvalidate = false;
							} else {
								if (chkField(eleobj,7,'num',elelabel)==false){
									bvalidate = false;
								}else{
									elelabel.style.color = 'black';
								}
							}
						}
					}
				}*/
				//-end of check for txtcontact.text
			}
		}
	}
	
	if (type=='chkupd'){
		var oldpass = f.txtcurpass.value;
		var newpass = f.txtnewpass.value;
		var cfmpass = f.txtcfmpass.value;
		//add
		var lblcur = document.getElementById('lblcurpass');
		var lblnew = document.getElementById('lblnewpass');
		var lblcfmnew = document.getElementById('lblcfmpass');
		//--modify 20060717
		if  ((oldpass != '') && (newpass == '')) {
			alert('Please enter your new password.');
			lblcur.style.color='black';
			lblnew.style.color='red';
			return false;
		}
		if  ((oldpass != '') && (newpass == '') && (cfmpass =='')){
			alert('Please enter your new password.');
			lblcur.style.color='black';
			lblnew.style.color='red';
			lblcfmnew.style.color='red';
			return false;
		}
		if  ((oldpass != '') && (newpass != '') && (cfmpass =='')){
			alert('Please confirm your new password.');
			lblcur.style.color='black';
			lblnew.style.color='black';
			lblcfmnew.style.color='red';
			return false;
		}
		if ((oldpass != '') && (newpass != '') && (cfmpass !='')){
			if (newpass != cfmpass ){
				alert('The new password you entered does not match. Please enter you new password again.');
				if (lblnew){lblnew.style.color='red';}
				if (lblcfmnew){lblcfmnew.style.color='red';} 
				return false;
			} else {
				if (lblnew){lblnew.style.color='black';}
				if (lblcfmnew){lblcfmnew.style.color='black';} 
			}
		}
		else if ((oldpass == '') && (newpass != '') || (cfmpass !='')){
			alert('Please enter your current password.');
			return false;
		}
	}	
	
	if (bvalidate == false){
		alert('Please check the compulsory fields highlighted in red.');
	}
	
	return bvalidate;
	//if (bvalidate == false ){			
	//	return false;
	//} else {
	//	return true;
	//}	
}
//-----------------------------------------check billing info ------------------------------------------------------
/*
function billingcheck(f) {
	var bvalidate = true;
	for (var i=0; i<f.elements.length;i++){
		var eletype = f.elements[i].type;
		var elename = f.elements[i].name;

		//loop thru all the textbox element
		if (eletype =='text') {
			var elelabelname = elename.replace('txt','lbl');
			var elelabel = document.getElementById(elelabelname);
			var eleobj = document.getElementById(elename);
			
			if (elename == 'txtAdd3' || elename=='txtAdd2' || elename=='txtCity'){}
			else if	(elename == 'txtFax' ){}
			
			//else {
				//if (eleobj.value ==''){
				//	bvalidate = false;
				//	if (elelabel){elelabel.style.color = 'red';}
				//	eleobj.focus();
				//}
				//else {
			if (elelabel){elelabel.style.color = 'black';}
			if (elename == 'txtFName'){
				if (eleobj.value ==''){elelabel.style.color='red';bvalidate=false;}
				else {elelabel.style.color='black';}
			}
			if (elename == 'txtLName'){
				if (eleobj.value ==''){elelabel.style.color='red';bvalidate=false;}
				else {elelabel.style.color='black';}
			}
			if (elename=='txtPostal'){
				if (eleobj.value =='' || chkField(eleobj,6,'alphanum',elelabel)==false){
					elelabel.style.color = 'red';
					bvalidate = false;
					//eleobj.focus();
				}else {elelabel.style.color = 'black';}
			} 
			else if (elename=='txtContact'){
				if (chkField(eleobj,7,'num',elelabel)==false  || eleobj.value ==''){
					elelabel.style.color = 'red';
					bvalidate = false;
					//eleobj.focus();
					//alert('contact')
				}else {elelabel.style.color = 'black';}
			}
			else if (elename =='txtHp'){
				
				if (chkField(eleobj,7,'num',elelabel)==false || eleobj.value ==''){
					if (elelabel){elelabel.style.color = 'red';}
					bvalidate = false;
					//eleobj.focus();
					//alert('contact')
				}else {elelabel.style.color = 'black';}
			}
			else if (elename == 'txtAdd'){
				var lbladd = document.getElementById('lblAdd');
				var txtadd2 = document.getElementById('txtAdd2');
				if (eleobj.value =='' && txtadd2.value==''){
					if (lbladd){lbladd.style.color = 'red';}
					bvalidate = false;
				}else if (eleobj.value !='' || txtadd2.value!='')
					{if (lbladd){lbladd.style.color='black';}}
			}
				//}
				
		} else if (eletype == 'select' || eletype == 'select-one'){
			var eleobj = document.getElementById(elename);
			if (elename == 'cboPaymentMode'){
				var lblpay = document.getElementById('lblPaymentMode');
				if (eleobj.selectedIndex == 0 || eleobj.selectedIndex == -1){
					if (lblpay){lblpay.style.color='red';}
					//alert('Please choose a payment method.');
					bvalidate = false;
				} else {lblpay.style.color='black';}
			} else if (elename == 'cbocountry'){
				if (eleobj.selectedIndex == -1){
					//alert('Please choose a country.');
					var lblctry = document.getElementById('lblCountry');
					if (lblctry){lblctry.style.color='red';}
					bvalidate = false;
				} 
			}
		}
	}
	if (bvalidate == false) {
	alert('Please check the compulsory fields highlighted in red.');
	}
	return bvalidate
	}
*/

//
//-------------------------------------Login Page Check-----------------------------------
//
function checkLoginFields(){
	var loginid = document.getElementById('txtuserid');
	var loginpass = document.getElementById('txtuserpass');
	if ((loginid.value == '') || (loginpass.value == '')) {
		alert('Please enter both Login ID and Password to Login.');
		return false;
	}
}
//-------------------------------------clearform-----------------------------------------
function clearfield(f){
	for (var i=0; i<f.elements.length;i++){
		var eletype = f.elements[i].type;
		var elename = f.elements[i].name;
		if ((eletype == 'text' || eletype =='textarea') && elename !='txtkeyword'){
			var obj = document.getElementById(elename);
			if (obj){obj.value = '';}
		}
	}
}
//
//------------------------------------- Pop-Up Window--------------------------------------
//

function popWin(i,w,h){
var popUp=window.open(i,'','width='+w+',height='+h+',scrollbars,resizable=0')
popUp.focus()
}

function popWinL(i,w,h,n){
var popUp=window.open(i,n,'width='+w+',height='+h+',scrollbars,resizable=1')
popUp.focus()
}


//
// Add on functions
//

function chgState(f,actionURL){
f.action=actionURL; f.submit()
}
function focusAddress(f){
f.Address3.focus(); f.State.focus()
}
//
// Generate Password
//
function genPass(){
var pass="",conv,temp,alpha=new Array
alpha[0]="a";alpha[1]="b";alpha[2]="c";alpha[3]="d";alpha[4]="e";alpha[5]="f";alpha[6]="g";alpha[7]="h";alpha[8]="i";alpha[9]="j";alpha[10]="k";alpha[11]="l";alpha[12]="m";alpha[13]="n";alpha[14]="o";alpha[15]="p";alpha[16]="q";alpha[17]="r";alpha[18]="s";alpha[19]="t";alpha[20]="u";alpha[21]="v";alpha[22]="w";alpha[23]="x";alpha[24]="y";alpha[25]="z"
for(j=0;j<8;j++){
	conv=parseInt(Math.random()*10)%2
	if(conv==0) {pass+=parseInt((Math.random()*10)+1)-1}
	else {temp=parseInt(((Math.random()*1000)%26)+1)-1;pass+=alpha[temp]}
}
return pass
}
//------------Misc Scripts------------------------------------
//Create a dynamic div to diplay information on rollover
	var divHelp_offsetTop = 0;
	var divHelp_offsetLeft = 0;
	var Div = false;
	var Div2 = false;
	var DivRec = false;
	//--new (modified) Create Company Field Help rollover
	function createHelpDiv(type)
	{
		var img;
		Div = document.createElement('div'); 
		Div.setAttribute('id','dynDiv');  
		Div.className='top';   				
		Div.style.position="absolute";       
		if (type == 'gpack'){
			img = document.getElementById('imgPack');
			x = (getDivleftPos(img)/1) + 25;
			y = (getDivTopPos(img)/1) - 25;
			Div.style.left = x + 'px'; 
			Div.style.top = y + 'px';
		/*} else if (type == 'rechelp'){
			img = document.getElementById('imgRec');
			x = (getDivleftPos(img)/1) - 120;
			y = (getDivTopPos(img)/1) - 35;
			Div.style.left = x + 'px'; 
			Div.style.top = y + 'px';*/
		} else if (type == 'help'){
			img = document.getElementById('imgCom');
			Div.style.left = getDivleftPos(img) + 'px'; 
			Div.style.top = getDivTopPos(img) + 'px';
		}
		Div.style.width=200;
		Div.style.height=50;
		
		createContent(type);
		document.body.appendChild(Div);
	}
	
	//-- new Create Address Lookup Help rollover
	function createAddDiv()
	{
		Div2 = document.createElement('div'); 
		Div2.setAttribute('id',"addDiv");   
		Div2.className="top";   
		var img = document.getElementById('imgAdd');
		
		Div2.style.position="absolute";       
		Div2.style.left= getDivleftPos(img) + 'px'; 
		Div2.style.top= getDivTopPos(img) + 'px'; 
		Div2.style.width=200;
		Div2.style.height=50;
		
		createContent('add');
		document.body.appendChild(Div2)
	}
	function createRecDiv()
	{
		DivRec = document.createElement('div'); 
		DivRec.setAttribute('id',"recDiv");   
		//DivRec.className="top";   
		var img = document.getElementById('imgRec');
		
		DivRec.style.position="absolute";       
		DivRec.style.left= (getDivleftPos(img)/1) - 200 + 'px'; 
		DivRec.style.top= (getDivTopPos(img)/1) - 40 + 'px'; 
		DivRec.style.width=200;
		DivRec.style.height=40;
		
		createContent('rechelp');
		document.body.appendChild(DivRec)
	}
	//Create Package Rollover
	/*
	var packdesc;
	function createPackageDiv(imgname, pkdesc)
	{
		packdesc = '<strong>' + pkdesc + '</strong>';
		Div = document.createElement('div'); 
		Div.setAttribute('id',"packDiv");  
		Div.className="top";   
		var img = document.getElementById(imgname);
		
		Div.style.position="absolute";       
		Div.style.left= getleftPos(img) + 'px'; 
		Div.style.top= getTopPos(img) + 'px'; 
		Div.style.width=200;
		Div.style.height=50;
		//Div.style.backgroundColor = 'white';
		createContent('pack');
		document.body.appendChild(Div)
	}
	*/
	function getDivTopPos(inputObj)
	{
		var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
		while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
		return returnValue + divHelp_offsetTop;
	}

	function getDivleftPos(inputObj)
	{
		var returnValue = inputObj.offsetLeft;
		while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
		return returnValue + divHelp_offsetLeft;
	}
	//--new (modified)
	function showhelp(type){
		if (type == 'comhelp'){
			//company field help
			if (!Div){createHelpDiv('help');}
			Div.style.display = 'block';
		} else if (type == 'addhelp'){
			//address look up
			if (!Div2){createAddDiv();}
			Div2.style.display = 'block';
		} else if (type == 'gpack'){
			//gift packaging
			if (!Div){createHelpDiv(type);}
			Div.style.display = 'block';
		} else if (type=='rechelp'){
			if (!DivRec){createRecDiv(type);}
			DivRec.style.display = 'block';
		}
		
	}
	function hidehelp(type){
		if (Div){Div.style.display = 'none';}
		if (Div2){Div2.style.display = 'none';}
	}
	function hiderechelp(){
		if (DivRec){DivRec.style.display = 'none';}
	}
	function createContent(type){
		var tbl = document.createElement('table');
		tbl.setAttribute('border','0');
		tbl.setAttribute('class','normalsmall');
		tbl.className='normalsmall';
		var tb=document.createElement('tbody');
		var tr = document.createElement('tr');
		var td = document.createElement('td');

		td.align= 'left';
		//td.innerHTML='<i>required only if you are sending to recipient&#39; s company.</i>';
		if (type == 'help') {
			td.innerHTML='<i>Please fill in only if you are sending to a company.</i>';
			Div.appendChild(tbl);
		}
		if (type == 'add') {
			td.innerHTML='<i>Click Address Lookup to select registered addresses.</i>';
			Div2.appendChild(tbl);
		}
		if (type == 'gpack') {
			td.innerHTML='<i>Select gift packaging from our list below.</i>';
			Div.appendChild(tbl);
		}
		if (type == 'rechelp') {
			td.innerHTML='<i>Select single or multiple recipients.</i>';
			DivRec.appendChild(tbl);
		}
		
		tr.appendChild(td);
		tb.appendChild(tr);
		tbl.appendChild(tb);
		
	}
	//------------check all checkbox-----------------
	function chkAll(f){
		for (var i=0; i < f.elements.length;i++){
			if (f.elements[i].type == 'checkbox'){
				f.elements[i].checked = true;
			}
		}
	}
	//----------------uncheck all checkbox------------
	function unchkAll(f){
		for (var i=0; i < f.elements.length;i++){
			if (f.elements[i].type == 'checkbox'){
				f.elements[i].checked = false;
			}
		}
	}
	//--end
	
	//----------------restrict length card no textfield
	function checkccfield(){
		var cc = document.getElementById('cboCardType');
		if (cc.selectedIndex != -1){
			var cctype = cc.options[cc.selectedIndex].value;
			var cclength = document.getElementById('txtcardNo');
			var ccsecure = document.getElementById('txtSecurityCode');
			var maxcardlength;
			var maxsecurelength;
			switch (cctype){
				case 'MAST':
					maxcardlength = 16;
					maxsecurelength = 3;
					break;
				case 'VISA':
					maxcardlength = 16;
					maxsecurelength = 3;
					break;
				case 'AMEX':
					maxcardlength = 15;
					maxsecurelength = 4;
					break;
			}
			cclength.setAttribute('maxLength',maxcardlength);
			ccsecure.setAttribute('maxLength',maxsecurelength);
			cclength.value = trimLeft(cclength.value, maxcardlength);
			ccsecure.value = trimLeft(ccsecure.value,maxsecurelength);
		}
	}
	
	function trimLeft(str, maxlength){
		var n = str.length
		if (n <= maxlength) {
			return str; }
		else if (n > maxlength){
			return str.substring(0,maxlength);
		}
	}
	if( document.captureEvents && Event.KEYDOWN ) {
		//remove this part if you do not need Netscape 4 to work
		document.captureEvents( Event.KEYDOWN );
	}
	document.onkeydown = alertkey;
	function alertkey(e) {
		if( !e ) {
			//if the browser did not pass the event information to the
			//function, we will have to obtain it from the event register
			if( window.event ) {
			//Internet Explorer
			e = window.event;
			} else {
			//total failure, we have no way of referencing the event
			return;
			}
		}
		if( typeof( e.keyCode ) == 'number'  ) {
			//DOM
			e = e.keyCode;
		} else if( typeof( e.which ) == 'number' ) {
			//NS 4 compatible
			e = e.which;
		} else if( typeof( e.charCode ) == 'number'  ) {
			//also NS 6+, Mozilla 0.9+
			e = e.charCode;
		} else {
			//total failure, we have no way of obtaining the key code
			return;
		}
		if (e == 13){
			if (window.submitform?true:false){
				submitform();
			}
		} 
	}
	/*
	//set todays date
	Now = new Date();
	NowDay = Now.getDate();
	NowMonth = Now.getMonth();
	NowYear = Now.getYear();
	if (NowYear < 2000) NowYear += 1900; //for Netscape
	
	//function for returning how many days there are in a month including leap years
	function DaysInMonth(WhichMonth, WhichYear)
	{
	 
	   var DaysInMonth = 31;
	  if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
	  if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
	  if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
	  
	  return DaysInMonth;
	}
	
	function SetToToday(Which)
	{
		
		
	  DaysObject = eval("document.frmPay." + Which + "Day");
	  MonthObject = eval("document.frmPay." + Which + "Month");
	  YearObject = eval("document.frmPay." + Which + "Year");
	  
	  YearObject[0].selected = true;
	  MonthObject[NowMonth].selected = true;
	
	  ChangeOptionDays(Which);
	
	  DaysObject[NowDay-1].selected = true;
	}
	
	//function to change the available days in a months
	function ChangeOptionDays(Which)
	{
	  DaysObject = eval("document.frmPay." + Which + "Day");
	  MonthObject = eval("document.frmPay." + Which + "Month");
	  YearObject = eval("document.frmPay." + Which + "Year");
	
	  Month = MonthObject[MonthObject.selectedIndex].text;
	  Year = YearObject[YearObject.selectedIndex].text;
	
	  DaysForThisSelection = DaysInMonth(Month, Year);
	  CurrentDaysInSelection = DaysObject.length;
	  if (CurrentDaysInSelection > DaysForThisSelection)
	  {
		for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
		{
		  DaysObject.options[DaysObject.options.length - 1] = null
		}
	  }
	  if (DaysForThisSelection > CurrentDaysInSelection)
	  {
		for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
		{
		  NewOption = new Option(DaysObject.options.length + 1);
		  DaysObject.add(NewOption);
		}
	  }
		if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
	
	}
	*/
function checkenqfields(f){
	var bvalidate = true;
	var chkenqtype = false;
	var errmsg = '';
	for (var i=0; i<f.elements.length;i++){
		var eletype = f.elements[i].type;
		var elename = f.elements[i].name;
		if (eletype == 'text' || eletype =='textarea'){
			
			var eleobj = document.getElementById(elename);
			var elelabelname = elename.replace('txt','lbl');
			var elelabel = document.getElementById(elelabelname);
			if (elename == 'txtfname' ){
				if (eleobj.value == ''){
					errmsg += "-name \n" ;
					bvalidate=false
					if (elelabel){elelabel.style.color='red';}
				} else if (eleobj.value != ''){
					if (elelabel){elelabel.style.color='#555555';}
				}
			}
			else if (elename == 'txtadd1'){
				var txtadd2 = document.getElementById('txtadd2');
				if (eleobj.value == '' && txtadd2.value == ''){
					bvalidate = false
					errmsg += "-address \n" ;
					if (elelabel){elelabel.style.color='red';}
				} else if (eleobj.value != '' || txtadd2.value != ''){
					if (elelabel){elelabel.style.color='#555555';}
				}
			}
			else if (elename == 'txtpostal'){
				if (eleobj.value =='' || chkField(eleobj,6,'alphanum',elelabel)==false){
					bvalidate = false
					errmsg += "-postal code \n" ;
					if (elelabel){elelabel.style.color='red';}
				} else {if (elelabel){elelabel.style.color='#555555';}}
			}
			else if (elename == 'txthomeno'){
					var txtoff = document.getElementById('txtofficeno');
					var lbloff = document.getElementById('lblofficeno');
					if (txtoff.value =='' && eleobj.value ==''){
						bvalidate = false
						errmsg += "-contact number \n" ;
						if (elelabel){elelabel.style.color='red';}
						if (lbloff){lbloff.style.color='red';}
					} else if (txtoff.value !='' || eleobj.value !=''){
						//if (txtoff.value !='' || eleobj.value !=''){
							if (chkField(eleobj,7,'num',elelabel)==false){
								bvalidate = false;
								if (elelabel){elelabel.style.color = 'red';}
								errmsg += '-min 7 number for home contact \n'
							} else if (chkField(eleobj,7,'num',elelabel)==true){if (elelabel){elelabel.style.color = '#555555';}} 
							if(chkField(txtoff,7,'num',lbloff)==false){
								bvalidate = false;
								if (lbloff){lbloff.style.color = 'red';}
								errmsg += '-min 7 number for office contact \n'
							} else {if (lbloff){lbloff.style.color = '#555555';}}
						//}
					
					}
			} else if (elename == 'txtemail'){
				if (eleobj.value == ''){
					bvalidate = false
					if (elelabel){elelabel.style.color = 'red';}
					errmsg += '-email \n';
				} else if (eleobj.value != ''){
					if (emailCheck(eleobj,elelabel) == false){
						errmsg += '-invalid email \n';
						bvalidate = false
						if(elelabel){elelabel.style.color='red';}
					} else if (emailCheck(eleobj,elelabel) == false){
						if(elelabel){elelabel.style.color= '#555555';}
					}
				}
			} else if (elename == 'txtmsg'){
				if (eleobj.value == ''){
					bvalidate = false;
					if (elelabel){elelabel.style.color='red';}
					errmsg += '-your enquiry/comments \n';
				} else {if (elelabel){elelabel.style.color='#555555';}}
			}
		}
		else if (eletype == "select"){
			var eleobj = document.getElementById(elename);
			var elelabelname = elename.replace('txt','lbl');
			var elelabel = document.getElementById(elelabelname);
			if (eleobj.selectedIndex == -1){
				bvalidate = false
				if (elelabel){elelabel.style.color = 'red';}
			} else if (eleobj.selectedIndex != -1) {
				if (elelabel){elelabel.style.color = '#555555';}
			}
		} 
		else if (eletype == 'checkbox'){
			var eleobj = document.getElementById(elename);
			if (eleobj.checked == true){
				chkenqtype = true;
			}
		}
	}
	var lblreq = document.getElementById('lblRequest');
	if (chkenqtype == false){
		if (lblreq){lblreq.style.color='red';}
		errmsg += "-type of request\n"
		bvalidate = false;
	} else if (chkenqtype == true) {
		if (lblreq){lblreq.style.color='#555555';}
	}
	if (bvalidate == false){alert('Please check the following fields (highlighted in red):\n' + errmsg );}
	return bvalidate
}
//------------Unused Script ----------------------------------
/*
Populate Month Name function
smonths = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')
function writeMonthList(mm){
for(i=1; i<=12; i++){
	if(i==parseInt(mm,10)) {document.write("<option value="+insZero(i,2)+" selected>"+smonths[i-1])}
	else {document.write("<option value="+insZero(i,2)+">"+smonths[i-1])}
}}

function insZero(num,sf){
var inputStr=num.toString()
while(inputStr.length<sf) {inputStr="0"+inputStr}
return inputStr
}
*/
