function ValidateCCNum(ccNum)
{
	var ccno = ccNum.value;
	if(ccno == ""){
		return true;
	}
	if(isNaN(ccno)){
		alert("should be numeric");
		ccNum.focus();
		return false;
	}
}

function submitNewRentalBag(div, url)
{ 
	divName=div
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function verifyNewUserRegistration() {
        if (document.form3.agreementBox.checked == false) {
           alert("You need to accept the 'Terms of Service' before you can register your account.");
           return false;
        }
        else{ 
       	   var themessage = "You are required to complete at least these following fields: ";
	
           if (document.form3.password1.value!=document.form3.password2.value) {
                alert("The password that you have keyed in do not match\nPlease re-enter the passwords.");
                return false;
           }

	   //Put the checks for the required fields here
	   if (document.form3.userName.value=="") {
		themessage = themessage + " -  Login";
	   }
	
	   if (document.form3.password1.value=="") {
		themessage = themessage + " -  Password";
	   }
		
	   if (document.form3.password2.value=="") {
		themessage = themessage + " -  Confirm Password";
	   }

	   if (document.form3.lastName.value=="") {
		themessage = themessage + " -  Last Name";
	   }

	   if (document.form3.emailAddress.value=="") {
		themessage = themessage + " -  Email Address";
	   }

	   if (document.form3.country.value=="") {
		themessage = themessage + " -  Country";
	   }

	   //alert if fields are empty and cancel form submit
	   if (themessage == "You are required to complete at least these following fields: ") {
		return true;
	   }	
	   else {
		alert(themessage);
		return false;
	   }
        }
}

function verifyContactUsDetails() {
	var themessage = "You are required to complete at least these following fields: ";
	
	//Put the checks for the required fields here
	if (document.form2.name.value=="") {
		themessage = themessage + " - Your Name";
	}
		
	if (document.form2.emailAddress.value=="") {
		themessage = themessage + " -  Email Address";
	}

	if (document.form2.subject.value=="") {
		themessage = themessage + " -  Subject";
	}

	if (document.form2.description.value=="") {
		themessage = themessage + " -  Brief Description";
	}
	
	//alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete at least these following fields: ") {
		return true;
	}	
	else {
		alert(themessage);
		return false;
	}
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

function verifyNewBagEnquiry() {
	var themessage = "You are required to complete at least these following fields: ";

	if (document.form4.renterName.value=="") {
		themessage = themessage + " -  Your Name";
	}
        
	var emailadd = document.form4.renterEmailAddress.value;
	emailadd = trim(emailadd);

	if (emailadd=="") {
		themessage = themessage + " -  Email Address";
	}
        
	//alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete at least these following fields: ") {
		return true;
	}	
	else {
		alert(themessage);
		return false;
	}
}

function verifyUpdateBagPosting(userName) {
	if(userName == null || userName == ""){
		alert("Please log in before posting a new bag.\nThank you");
                return false;
	}else{
		if (document.form1.agreementBox.checked == false) {
        	alert("You need to accept the 'Terms of Service' before you can post your bag.");
            return false;
        }else if(document.form1.authenticAgreementBox.checked == false){
        	alert("You need to acknowledge that you are posting an Authentic and Genuine bag/handbag");
            return false;
		}else if(document.form1.rentalPricePerWeek.value == "" && document.form1.sellingPrice.value == ""){
			alert("Are you renting out your handbag or selling it? Please fill in 'rental price' or 'selling price' to indicate whether you are renting out your bag or selling it.");
			return false;			
		}else if(isNaN(document.form1.rentalPricePerWeek.value)){
			alert("You need to enter a number for Rental Price");
			return false;
		}else if(isNaN(document.form1.sellingPrice.value)){
			alert("You need to enter a number for Selling Price");
			return false;
		}else if(document.form1.exchangeBag.checked == true && document.form1.sellingPrice.value == ""){
			alert("You need to key in a Selling Price if you want to do an exchange of handbag with another person.");
			return false;
        }else{
			var themessage = "You are required to complete at least these following fields: ";
	
			//Put the checks for the required fields here
			if (document.form1.brand.value=="") {
				themessage = themessage + " - Brand";
			}
		
			if (document.form1.displayName.value=="") {
				themessage = themessage + " -  Display Name";
			}
		
			if (document.form1.condition.value=="") {
				themessage = themessage + " -  Condition";
			}
	
			//alert if fields are empty and cancel form submit
			if (themessage == "You are required to complete at least these following fields: ") {
                                document.form1.Submit.disabled=true;
				return true;
			}	
			else {
				alert(themessage);
				return false;
			}
		}
	}
}

function verifyBagPosting(userName) {
	if(userName == null || userName == ""){
		alert("Please log in before posting a new bag.\nThank you");
                return false;
	}else{
		if (document.form1.agreementBox.checked == false) {
        	alert("You need to accept the 'Terms of Service' before you can post your bag.");
            return false;
        }else if(document.form1.authenticAgreementBox.checked == false){
        	alert("You need to acknowledge that you are posting an Authentic and Genuine bag/handbag");
            return false;
		}else if(document.form1.rentalPricePerWeek.value == "" && document.form1.sellingPrice.value == ""){
			alert("Are you renting out your handbag or selling it? Please fill in 'rental price' or 'selling price' to indicate whether you are renting out your bag or selling it.");
			return false;			
		}else if(isNaN(document.form1.rentalPricePerWeek.value)){
			alert("You need to enter a number for Rental Price");
			return false;
		}else if(isNaN(document.form1.sellingPrice.value)){
			alert("You need to enter a number for Selling Price");
			return false;
		}else if(document.form1.exchangeBag.checked == true && document.form1.sellingPrice.value == ""){
			alert("You need to key in a Selling Price if you want to do an exchange of handbag with another person.");
			return false;
        }else{
			var themessage = "You are required to complete at least these following fields: ";
	
			//Put the checks for the required fields here
			if (document.form1.brand.value=="") {
				themessage = themessage + " - Brand";
			}
		
			if (document.form1.displayName.value=="") {
				themessage = themessage + " -  Display Name";
			}


		
			if (document.form1.condition.value=="") {
				themessage = themessage + " -  Condition";
			}
	
			//alert if fields are empty and cancel form submit
			if (themessage == "You are required to complete at least these following fields: ") {
                                document.form1.Submit.disabled=true;
				return true;
			}	
			else {
				alert(themessage);
				return false;
			}
		}
	}
}

function popUp(companyWebpage) 
{
	new_window =  open("http://" + companyWebpage);
}

function open_new_window(website) 
{
new_window = open(website,"displayWindow",config='width=300,height=300,left=10,top=10,scrollbars=yes');
}

function open_new_window1(website) 
{
new_window = open(website,"displayWindow",config='width=428,height=580,left=10,top=10,scrollbars=yes');
}

function open_new_window2(website,width,height) 
{
new_window = open(website,"displayWindow",config="width=" + width + ",height=" + height + ",left=10,top=10,scrollbars=yes");
}