
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
} 
function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		//var ret=xmlHttp.responseText;
		location.href='index.php';
	}
}
function ValidateLoginForm(theform)
{

	if(!theform.user.value || !theform.pwd.value){
		alert('Please key in username and password !');
		return false;
	}else{
		return true;
	}
}

function ValidateResetPwd(theform)
{

  
	if(!theform.ic.value || !theform.name.value){
		alert('Please key in your new IC and name!');
		return false;
	}else{
		return true;
	}
}

function ValidateChgPwd(theform)
{
	var msg="";

	if(!theform.oldpwd.value)msg+="Old password required. \n";

	if(theform.newpwd.value.length < 6)msg+="Please specify the password, minimum 6 characters. \n";
	else if(theform.newpwd.value != theform.conpwd.value)msg+="The confirm password does not match. \n";

	 if(msg){
		alert(msg)
		return false;
	}else return true;
	

}

function ValidateAddUser(theform){
	var msg="";


	if(!theform.username.value)msg+="Please specify the username. \n";
	else if(theform.username.value.length > 10)msg+="Username maximum 10 character. \n"; 
	if(!theform.name.value)msg+="Please key in the name. \n";
//	if(!theform.access.value)msg+="Please select the access. \n";	
	if(theform.pwd.value.length < 6)msg+="Please specify the password, minimum 6 characters. \n";
	else if(theform.pwd.value != theform.cpwd.value)msg+="The confirm password does not match the first password. \n";


   if(msg){
		alert(msg)
		return false;
	}else return true;
}

function ValidateEditUser(theform){
	var msg="";

//	if(!theform.level.value)msg+="Please select the position. \n";
//	if(!theform.access.value)msg+="Please select the access. \n";	

	
	if(theform.pwd.value && theform.pwd.value.length < 6)msg+="Please specify the password, minimum 6 characters. \n";
	else if(theform.pwd.value != theform.cpwd.value)msg+="The confirm password does not match the first password. \n";

   if(msg){
		alert(msg)
		return false;
	}else return true;
}
function ValidateUpdateProfile(theform){
	var msg="";

	if(!theform.addr1.value)msg +="Please specify the Address. \n";			
	if(!theform.state.value)msg +="Please specify the state. \n";							
	if(!theform.postal.value)msg +="Please specify the postal. \n";			
	if(!theform.city.value)msg +="Please specify the city. \n";				
	if(!theform.country.value)msg +="Please specify the country. \n";					
	
	if(!theform.handphone.value && !theform.phone.value && !theform.directline.value)msg += "Please specify contact number. \n";				
	
	if((ValidateNumber(theform.handphone)==false) && theform.handphone.value)msg += "It was not specified handphone (numbers only). \n";				
	if((ValidateNumber(theform.phone)==false) && theform.phone.value)msg += "It was not specified office no (numbers only). \n";				
	if((ValidateNumber(theform.directline)==false) && theform.directline.value)msg += "It was not specified direct line no (numbers only). \n";				
	

   if(msg){
		alert(msg)
		return false;
	}else return true;
}


//  date format
/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
//		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
//		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
//		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
//		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
//		alert("Please enter a valid date")
		return false
	}
return true
}

//----------------------


function ValidateNumber(theinput)
{
   s=theinput.value
   if(s=="") return false;
   if(s.search)
   {
     return (s.search(new RegExp("^[- 0-9]+$","gi"))>=0)
   }
}
function ValidatePhoneNumber(theinput)
{
   s=theinput.value
   if(s=="") return false;
   if(s.search)
   {
     return (s.search(new RegExp("^[0-9]+$","gi"))>=0)
   }
}
function ValidateEmail(theinput)
{
   s=theinput.value
   if(s.search)
   {
      return (s.search(new RegExp("^([a-z0-9_]|\-|\\\.)+@(([a-z0-9_]|\-)+\\\.)+[a-z]{2,4}$","gi"))>=0)
   }
   if(s.indexOf)
   {
      at_character=s.indexOf('@')
      if(at_character<=0 || at_character+4>s.length)
         return false
   }
   if(s.length<6)
      return false
   else
      return true
}
function ValidatePrice(theinput)
{
   s=theinput.value
   if(s=="") return false;
   if(s.search)
   {
      return (s.search(new RegExp("^[0-9.]+$","gi"))>=0)
   }
}
function ValidateOnlyText(theinput)
{

   s=theinput.value
    if(s.search)
   {
      return (s.search(new RegExp("^[-@._' a-z ]+$","gi"))>=0)
   }
}
function ValidateText(theinput)
{
	str=theinput.value;	
	if(str == "") return false
	else if(ValidateOnlyText(theinput)==false)return false
	else return true
}

function ValidateReferral(theform){
	var msg="";

   if(msg){
		alert(msg)
		return false;
	}else return true;
}


function DialogWindow(theURL,winName,type) { 
	var features;
	if(type=="Classic")features ="width=650,height=600";
	else features=type;
	
  window.open(theURL,winName,features);
}
//-------------------------------
function getMemberList()
{
	var sMemberID=document.form.sType.value;
	var sName = document.form.sReferral.value;
	var fld = document.form.fld.value;
	var inpfld = document.form.inpfld.value;
	
	xmlHttp=GetXmlHttpObject();
	var url="ajax_memberlist.php";
	url=url+"?sMemberID="+sMemberID+"&sName="+sName+"&fld="+fld+"&inpfld="+inpfld;

	xmlHttp.onreadystatechange=stateChangedMember;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	

}

function stateChangedMember() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("divResult").innerHTML=xmlHttp.responseText;
	}
}
// -----------------------------------------------

function membershipInfo(val)
{
	
	xmlHttp=GetXmlHttpObject();
	var url="ajax_membership.php";
	url=url+"?sMemberID="+val;

	document.form.memberno.value="";
	document.form.name.value="";
	document.form.scheme.value="";
	document.form.room.value="";
	document.form.ic.value="";
	document.form.homeno.value="";
	document.form.mobile.value="";
	document.form.fax.value="";
	document.form.email.value="";
	document.form.freemaint.value="";
	document.form.entnights.value="";
	document.form.expiry.value="";
	document.form.yrexp.value="";
	document.form.program.value="";
	document.form.bal.value="";
					
	xmlHttp.onreadystatechange=stateChangedMembership;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}
function stateChangedMembership() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		ret=xmlHttp.responseText;
		if(ret==1){	
			alert("No membership found!")
		}else{	
			var val=ret.split("|");
			document.form.memberno.value=val[12];
			document.form.name.value=val[0];
			document.form.scheme.value=val[1];
			document.form.room.value=val[2];
			document.form.ic.value=val[3];
			document.form.homeno.value=val[4];
			document.form.mobile.value=val[5];
			document.form.fax.value=val[6];
			document.form.email.value=val[7];
			document.form.entnights.value=val[8];
			document.form.freemaint.value=val[9];
			document.form.expiry.value=val[10];
			document.form.bal.value=val[11];
			document.form.program.value=val[13];
			document.form.yrexp.value=val[14];			
			document.form.bal.value=val[11];
			document.form.hadult.value=val[15];
			document.form.hchild.value=val[16];
			var adult=val[15];
			var child=val[16];

			
			for(i=document.form.adult1.options.length-1;i>=0;i--)
				document.form.adult1.remove(i);

			
			for(i=1;i<= adult; i++){
				document.form.adult1.options[document.form.adult1.options.length]=new Option(i,i,false,false);
			}


			for(i=document.form.child1.options.length-1;i>=0;i--)
				document.form.child1.remove(i);

			for(i=0;i<= child; i++){
				document.form.child1.options[document.form.child1.options.length]=new Option(i,i,false,false);
			}
			
			for(i=document.form.rooms.options.length-1;i>=0;i--)
				document.form.rooms.remove(i);

			for(i=1;i<= adult * val[8]; i++){
				document.form.rooms.options[document.form.rooms.options.length]=new Option(i,i,false,false);
			}

		}
	}
}

//--------------------------------
function postMemberRecord(no,nm,fd,inpfld)
{
	if(fd=="sid")window.opener.document.form.sid.value = no;
	else if(fd=="did")window.opener.document.form.did.value = no;
	
	if(inpfld=="name")window.opener.document.form.name.value = nm;
	else if(inpfld=="dname")window.opener.document.form.dname.value = nm;

	window.close();
}

// ----------------display name info
function stateChangedName() 
{ 
	var ret;
	if (xmlHttp.readyState==4)
	{ 
		ret=xmlHttp.responseText;
		var val=ret.split("|");

//	 var a=val[1].length;
//alert(a)
		if(val[1]=="dName ")document.form.dName.value = val[0];
		else if(val[1]=="dName2 ")document.form.dName2.value = val[0];
	}
}

function disName(val,inpfld)
{
	xmlHttp=GetXmlHttpObject();
	var url="ajax_disName.php?no="+val+"&inpfld="+inpfld;

	xmlHttp.onreadystatechange=stateChangedName;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	

}

//----------------------------



function randomPassword(length)
{
  chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  pass = "";
  for(x=0;x<length;x++)
  {
    i = Math.floor(Math.random() * 62);
    pass += chars.charAt(i);
  }
  return pass;
}
function formSubmit()
{
  document.form.pwd.value = randomPassword(8);
  return false;
}


function postCompany(no,nm)
{
	window.opener.document.form.sid.value = no;
	window.opener.document.form.person.value = nm;
	window.close();
}
function postPerson(no,nm)
{
	window.opener.document.form.sid.value = no;
	window.opener.document.form.company.value = nm;
	window.close();
}
function postCustomer(no,nm,type)
{
	window.opener.document.form.sid.value = no;
	window.opener.document.form.name.value = nm;
	window.opener.document.form.type.value = type;
	window.close();
}

function newvalue(type,val){
	if(val=="add"){
		var url="popup/popNewValue.php?type="+type;
		DialogWindow(url,'NewValue','width=300,height=150')
	}
}
function ValidateAddNewValue(theform){
	var msg="";

	if(!theform.type.value)msg +="Please select the type. \n";			
	if(!theform.name.value)msg +="Please specify the name. \n";			

  if(msg){
		alert(msg)
		return false;
	}else return true;
}
function ValidateAddMember(theform){
	var msg="";

	if(!theform.formno.value)msg +="Please specify the form no. \n";			
	if(!theform.scheme.value)msg +="Please select the type of scheme. \n";			
	if(!theform.category.value)msg +="Please select the category of membership. \n";				
	if(!theform.name.value)msg +="Please specify the name of applicant. \n";			
	if(!theform.cardno.value)msg +="Please specify the card no. \n";			
	if(!theform.cardname.value)msg +="Please specify the card name. \n";			
	if(!theform.ic.value)msg +="Please specify the NRIC/passport. \n";			
	if(!theform.joindate.value)msg +="Please specify the date of application. \n";			

	if(theform.phome.value && ValidatePhoneNumber(theform.phome)==false)msg += "It was not specified home (numbers only). \n";						
	if(theform.mobile.value && ValidatePhoneNumber(theform.mobile)==false)msg += "It was not specified mobile (numbers only). \n";						
	if(theform.fax.value && ValidatePhoneNumber(theform.fax)==false)msg += "It was not specified fax (numbers only). \n";						

	if(theform.officephone.value && ValidatePhoneNumber(theform.officephone)==false)msg += "It was not specified office no (numbers only). \n";						
	if(theform.officeext.value && ValidatePhoneNumber(theform.officeext)==false)msg += "It was not specified office ext no (numbers only). \n";						
	if(theform.officefax.value && ValidatePhoneNumber(theform.officefax)==false)msg += "It was not specified office fax (numbers only). \n";						

	if(theform.nomineehome1.value && ValidatePhoneNumber(theform.nomineehome1)==false)msg += "It was not specified nominee(1) home (numbers only). \n";						
	if(theform.nomineemobile1.value && ValidatePhoneNumber(theform.nomineemobile1)==false)msg += "It was not specified nominee(1)mobile (numbers only). \n";						
	if(theform.nomineefax1.value && ValidatePhoneNumber(theform.nomineefax1)==false)msg += "It was not specified nominee(1) fax (numbers only). \n";						

	if(theform.nomineehome2.value && ValidatePhoneNumber(theform.nomineehome2)==false)msg += "It was not specified nominee(2) home (numbers only). \n";						
	if(theform.nomineemobile2.value && ValidatePhoneNumber(theform.nomineemobile2)==false)msg += "It was not specified nominee(2) mobile (numbers only). \n";						
	if(theform.nomineefax2.value && ValidatePhoneNumber(theform.nomineefax2)==false)msg += "It was not specified nominee(2) fax (numbers only). \n";						

	if(theform.sphome.value && ValidatePhoneNumber(theform.sphome)==false)msg += "It was not specified spouse home (numbers only). \n";						
	if(theform.spmobile.value && ValidatePhoneNumber(theform.spmobile)==false)msg += "It was not specified spouse mobile (numbers only). \n";						
	if(theform.spfax.value && ValidatePhoneNumber(theform.spfax)==false)msg += "It was not specified spouse fax (numbers only). \n";						

	if(msg){
		alert(msg)
		return false;
	}else return true;
}
function ValidateEditMember(theform){
	var msg="";

	if(!theform.formno.value)msg +="Please specify the form no. \n";			
	if(!theform.category.value)msg +="Please select the category of membership. \n";				
	if(!theform.name.value)msg +="Please specify the name of applicant. \n";			
	if(!theform.cardno.value)msg +="Please specify the card no. \n";			
	if(!theform.cardname.value)msg +="Please specify the card name. \n";			
	if(!theform.ic.value)msg +="Please specify the NRIC/passport. \n";			


	if(theform.phome.value && ValidatePhoneNumber(theform.phome)==false)msg += "It was not specified home (numbers only). \n";						
	if(theform.mobile.value && ValidatePhoneNumber(theform.mobile)==false)msg += "It was not specified mobile (numbers only). \n";						
	if(theform.fax.value && ValidatePhoneNumber(theform.fax)==false)msg += "It was not specified fax (numbers only). \n";						

	if(theform.officephone.value && ValidatePhoneNumber(theform.officephone)==false)msg += "It was not specified office no (numbers only). \n";						
	if(theform.officeext.value && ValidatePhoneNumber(theform.officeext)==false)msg += "It was not specified office ext no (numbers only). \n";						
	if(theform.officefax.value && ValidatePhoneNumber(theform.officefax)==false)msg += "It was not specified office fax (numbers only). \n";						

	if(theform.nomineehome1.value && ValidatePhoneNumber(theform.nomineehome1)==false)msg += "It was not specified nominee(1) home (numbers only). \n";						
	if(theform.nomineemobile1.value && ValidatePhoneNumber(theform.nomineemobile1)==false)msg += "It was not specified nominee(1)mobile (numbers only). \n";						
	if(theform.nomineefax1.value && ValidatePhoneNumber(theform.nomineefax1)==false)msg += "It was not specified nominee(1) fax (numbers only). \n";						

	if(theform.nomineehome2.value && ValidatePhoneNumber(theform.nomineehome2)==false)msg += "It was not specified nominee(2) home (numbers only). \n";						
	if(theform.nomineemobile2.value && ValidatePhoneNumber(theform.nomineemobile2)==false)msg += "It was not specified nominee(2) mobile (numbers only). \n";						
	if(theform.nomineefax2.value && ValidatePhoneNumber(theform.nomineefax2)==false)msg += "It was not specified nominee(2) fax (numbers only). \n";						

	if(theform.sphome.value && ValidatePhoneNumber(theform.sphome)==false)msg += "It was not specified spouse home (numbers only). \n";						
	if(theform.spmobile.value && ValidatePhoneNumber(theform.spmobile)==false)msg += "It was not specified spouse mobile (numbers only). \n";						
	if(theform.spfax.value && ValidatePhoneNumber(theform.spfax)==false)msg += "It was not specified spouse fax (numbers only). \n";						

	if(msg){
		alert(msg)
		return false;
	}else return true;
}

function clearFields(){
	document.form.reset();
}
function pintomenu(fld){
	var sType=document.form.sType.value;
	var sReferral=document.form.sReferral.value;
	var role=document.form.role.value;
	var type=document.form.type.value;
	var industry=document.form.industry.value;
	var country=document.form.country.value;
	
	var url="popup/pinMenu.php?fld="+fld+"&sType="+sType+"&sReferral="+sReferral+"&role="+role+"&type="+type+"&industry="+industry+"&country="+country;
	DialogWindow(url,'PintoMenu','width=300,height=150')

}
function pintomenu_company(fld){
	var sType=document.form.sType.value;
	var sReferral=document.form.sReferral.value;
	var type=document.form.type.value;
	var industry=document.form.industry.value;
	var classification=document.form.classification.value;
    var country=document.form.country.value;

	var url="popup/pinMenuComp.php?fld="+fld+"&sType="+sType+"&sReferral="+sReferral+"&type="+type+"&industry="+industry+"&country="+country+"&classification="+classification;
	DialogWindow(url,'PintoMenu','width=300,height=150')

}
function removepinmenu(id){
	var ret=confirm('Are you sure remove pin from menu?');	
	if(ret==true){
		xmlHttp=GetXmlHttpObject()		
		var url="ajax_removepin.php?id="+id;

		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}else return false;

}
function ValidateAddReservation(theform){
	var msg="";

	if(!theform.no.value)msg +="Please specify the membership no. \n";		

	var btn = valButton(theform.reserv);
	if (btn == null)msg +="No reservation requested.\n";	
	else if(btn=="Guest"){
		if(!theform.gname.value	|| !theform.gic.value	|| !theform.gcontact.value)msg +="Please specify guest name and NRIC/passport.\n";	
	}
	
	if(!theform.rooms.value)msg +="Please choice no of room. \n";					
	if(!theform.cin1.value)msg +="Please specify choice 1 of check in date. \n";					
	if(!theform.cout1.value)msg +="Please specify choice 1 of  check out date. \n";						
	if(!theform.cin2.value)msg +="Please specify choice 2 of  check in date. \n";					
	if(!theform.cout2.value)msg +="Please specify choice 2 of  check out date. \n";						
	if(!theform.cin3.value)msg +="Please specify choice 3 of  check in date. \n";					
	if(!theform.cout3.value)msg +="Please specify choice 3 of  check out date. \n";						

	if(!theform.adult1.value)msg +="Please specify no of adult. \n";						
	
	if(theform.cin1.value && theform.cout1.value){
		if(theform.cin1.value > theform.cout1.value || theform.cin1.value == theform.cout1.value)msg +="Invalid choice 1 check in and out date . \n";						
	}

	if(theform.cin2.value && theform.cout2.value){
		if(theform.cin2.value > theform.cout2.value || theform.cin2.value == theform.cout2.value)msg +="Invalid choice 2 check in and out date . \n";						
	}

	if(theform.cin3.value && theform.cout3.value){
		if(theform.cin3.value > theform.cout3.value || theform.cin3.value == theform.cout3.value)msg +="Invalid choice 3 check in and out date . \n";						
	}

if(msg){
		alert(msg)
		return false;
	}else return true;
}
function ValidateEditReservation(theform){
	var msg="";


	var btn = valButton(theform.reserv);
	if (btn == null)msg +="No reservation requested.\n";	
	else if(btn=="Guest"){
		if(!theform.gname.value	|| !theform.gic.value	|| !theform.gcontact.value)msg +="Please specify guest name and NRIC/passport and contact no.\n";	
	}
	
	if(!theform.bookingno.value)msg +="Please specify booking no. \n";					

	if(!theform.cin1.value)msg +="Please specify check in date. \n";					
	if(!theform.cout1.value)msg +="Please specify check out date. \n";						
	if(!theform.adult1.value)msg +="Please specify no of adult. \n";						
	
/*	if(theform.cin1.value && theform.cout1.value){
		if(theform.cin1.value > theform.cout1.value)msg +="Invalid choice 1 check in and out date . \n";						
	}

	if(theform.cin2.value && theform.cout2.value){
		if(theform.cin2.value > theform.cout2.value)msg +="Invalid choice 2 check in and out date . \n";						
	}

	if(theform.cin3.value && theform.cout3.value){
		if(theform.cin3.value > theform.cout3.value)msg +="Invalid choice 3 check in and out date . \n";						
	}
*/
/*	var btn = valButton(theform.confirmchoice);
	if (btn == null)msg +="No confirm choice.\n";	
	else if(btn=="Guest"){
		if(!theform.gname.value	|| !theform.gic.value)msg +="Please specify guest name and NRIC/passport.\n";	
	}
*/
	if(msg){
		alert(msg)
		return false;
	}else return true;
}
function show_Table(varclass,str) {
	xObject=document.getElementById(varclass);
    xObject.style.visibility = str;
}
function ValidateCancelReservation(theform){
	var msg="";


	if(!theform.cremark.value)msg +="Please specify the cancel remark. \n";						

	if(msg){
		alert(msg)
		return false;
	}else return true;
}
function ValidateAddRoom(theform){
	var msg="";

	if(!theform.type.value)msg +="Please key in the room type. \n";		
	if(!theform.descr.value)msg +="Please key in the descriptions. \n";			

	if(msg){
		alert(msg)
		return false;
	}else return true;
}
function ValidateAddProduct(theform){
	var msg="";

	if(!theform.code.value)msg +="Please key in product code. \n";		
	if(!theform.name.value)msg +="Please key in product name. \n";		
	if(ValidatePrice(theform.price)==false)msg += "Price is require. \n";				
	if(!theform.program.value)msg +="Please key in program tenure. \n";		
	if(!theform.night.value)msg +="Please key in annual entitlement. \n";		
	if(!theform.maint.value)msg +="Please key in free maintenance fees. \n";		
	if(theform.room.value=="")msg +="Please choose room. \n";		
	if(!theform.adult.value)msg +="Please key in no of adult. \n";		
	if(!theform.child.value)msg +="Please key in no of child. \n";		
			
	if(msg){
		alert(msg)
		return false;
	}else return true;
}
function ValidateUpgradeMember(theform){
	var msg="";

	if(!theform.upscheme.value)msg +="Please specify the upgrade type of produt. \n";		
	if(!theform.joindate.value)msg +="Please specify the apply date. \n";		

	if(msg){
		alert(msg)
		return false;
	}else return true;
}
function ValidateProfile(theform){
	var msg="";


	
	if(!theform.name.value)msg+="Please key in the name. \n";

	if(theform.newpwd.value && theform.newpwd.value.length < 6)msg+="Please specify the password, minimum 6 characters. \n";
	
	if(theform.newpwd.value != theform.conpwd.value)msg+="The confirm password does not match. \n";
	

   if(msg){
		alert(msg)
		return false;
	}else return true;
}
function postEmail(fld,nm)
{

	if(fld=="cc"){
		if(window.opener.document.form.cc.value)window.opener.document.form.cc.value = window.opener.document.form.cc.value + ","+nm;
		else window.opener.document.form.cc.value = nm;
		window.close();
	}else if(fld=="bcc"){
		if(window.opener.document.form.bcc.value)window.opener.document.form.bcc.value = window.opener.document.form.bcc.value + ","+nm;
		else window.opener.document.form.bcc.value = nm;
		window.close();	
	}else if(fld=="to"){
		if(window.opener.document.form.to.value)window.opener.document.form.to.value = window.opener.document.form.to.value + ","+nm;
		else window.opener.document.form.to.value = nm;
	}




}
function postMobile(nm)
{

	if(window.opener.document.form.contact.value)window.opener.document.form.contact.value = window.opener.document.form.contact.value + ","+nm;
	else window.opener.document.form.contact.value = nm;

//	window.close();
}

function disSMSTemplate(val)
{
	xmlHttp=GetXmlHttpObject();
	var url="ajax_disSMSTemplate.php?no="+val;

	xmlHttp.onreadystatechange=stateChangedSMS;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	

}
function stateChangedSMS() 
{ 
	var ret;
	if (xmlHttp.readyState==4)
	{ 
		ret=xmlHttp.responseText;
		var val=ret.split("|");

		if(val[1]=="Y"){
			
//			document.form.message.value=UTF8.encode(val[2]);
			document.form.message.value=val[0];
			document.form.chi.checked=true;			
		}else{
			document.form.message.value=val[0];
			document.form.chi.checked=false;
		}
	}
}
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}