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 verifyEventPosting(userName) {
	if(userName == null || userName == ""){
		alert("Please log in before posting a new event.\nThank you");
                return false;
	}else{
		if(document.form1.startDate.value == "" || document.form1.startMonth.value == "" || document.form1.startYear.value == ""){
			alert(document.form1.startDate.value);
			alert(document.form1.startMonth.value);
			alert(document.form1.startYear.value);
			alert("Please key in the 'Event Start Date'");
			return false;			
		}else if(document.form1.endDate.value == "" || document.form1.endMonth.value == "" || document.form1.endYear.value == ""){
			alert("Please key in the 'Event End Date'");
			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.eventTitle.value=="") {
				themessage = themessage + " - Event Title";
			}
		
			if (document.form1.eventDescription.value=="") {
				themessage = themessage + " -  Event Description";
			}

			if (document.form1.eventLocation.value=="") {
				themessage = themessage + " -  Event Location";
			}

			if (document.form1.openingHours.value=="") {
				themessage = themessage + " -  Event Opening Hours";
			}
			
			//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 addToWatchlist(userId,itemId,divName)
{
	if(userId!=''){
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
                        //xmlhttp.overrideMimeType('text/xml');
		}
		else{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange=function(){
  			if (xmlhttp.readyState==4 && xmlhttp.status==200){

    			document.getElementById(divName).innerHTML="<span class=\"watchlistRemoveLink\"><a href=\"javascript:removeFromWatchlist('" + userId + "'," + itemId + ",'" + divName + "')\">- Remove from Favourites</a></span>";
  			}
		};

		url="adds/addToWatchList.php?userId=" + userId + "&itemId=" + itemId;

		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	else{
		alert("You need to log in to use this feature");
	}
}

function removeFromWatchlist(userId,itemId,divName)
{
	if(userId!=''){
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
		}
		else{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange=function(){
  			if (xmlhttp.readyState==4 && xmlhttp.status==200){
    			document.getElementById(divName).innerHTML="<span class=\"watchlistAddLink\"><a href=\"javascript:addToWatchlist('" + userId + "'," + itemId + ",'" + divName + "')\">+ Add to Favourites</a></span>";
  			}
		}

		url="adds/removeFromWatchlist.php?userId=" + userId + "&itemId=" + itemId;

		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	else{
		alert("You need to log in to use this feature");
	}
}

function addSellerToWatchlist(userId,sellerId,postingUserName)
{
	if(userId!='' && userId!=0){
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
		}
		else{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange=function(){
  			if (xmlhttp.readyState==4 && xmlhttp.status==200){
    			document.getElementById("sellerWatchlistDiv").innerHTML="<span class=style17>Posted by:</span> <span class=sellerNameLink><a href=ownerBags.php?u=" + sellerId + ">" + postingUserName + "</a></span>&nbsp;&nbsp;(<a href=\"javascript:removeSellerFromWatchlist(" + userId + "," + sellerId + ", '" + postingUserName + "')\" class=addSellerWatchlist>Remove " + postingUserName + " from my seller watchlist</a></span>)";
  			}
		}

		url="adds/addSellerToWatchlist.php?userId=" + userId + "&sellerId=" + sellerId;

		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	else{
		alert("You need to log in to use this feature");
	}
}

function removeSellerFromWatchlist(userId,sellerId,postingUserName)
{
	if(userId!='' && userId!=0){
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
		}
		else{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange=function(){
  			if (xmlhttp.readyState==4 && xmlhttp.status==200){
    			document.getElementById("sellerWatchlistDiv").innerHTML="<span class=style17>Posted by:</span> <span class=sellerNameLink><a href=ownerBags.php?u=" + sellerId + ">" + postingUserName + "</a></span>&nbsp;&nbsp;(<a href=\"javascript:addSellerToWatchlist(" + userId + "," + sellerId + ", '" + postingUserName + "')\" class=addSellerWatchlist>Add " + postingUserName + " to my seller watchlist</a></span>)";
  			}
		}

		url="adds/removeSellerFromWatchlist.php?userId=" + userId + "&sellerId=" + sellerId;

		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	else{
		alert("You need to log in to use this feature");
	}
}

function addSellerToWatchlist1(userId,sellerId,postingUserName,divName)
{
	if(userId!=''){
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
		}
		else{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange=function(){
  			if (xmlhttp.readyState==4 && xmlhttp.status==200){
    			document.getElementById(divName).innerHTML="<a href=\"javascript:removeSellerFromWatchlist1(" + userId + "," + sellerId + ",'" + postingUserName + "','" + divName + "')\" class=\"blueSellerList\">Remove " + postingUserName + " from my Seller Watchlist</a>";
  			}
		}

		url="adds/addSellerToWatchlist.php?userId=" + userId + "&sellerId=" + sellerId;

		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	else{
		alert("You need to log in to use this feature");
	}
}

function removeSellerFromWatchlist1(userId,sellerId,postingUserName,divName)
{
	if(userId!=''){
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
		}
		else{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange=function(){
  			if (xmlhttp.readyState==4 && xmlhttp.status==200){
    			document.getElementById(divName).innerHTML="<a href=\"javascript:addSellerToWatchlist1(" + userId + "," + sellerId + ",'" + postingUserName + "','" + divName + "')\" class=\"blueSellerList\">Add " + postingUserName + " to my Seller Watchlist</a>";
  			}
		}

		url="adds/removeSellerFromWatchlist.php?userId=" + userId + "&sellerId=" + sellerId;

		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	else{
		alert("You need to log in to use this feature");
	}
}

function addSellerSubscription(userId,sellerId,postingUserName,divName)
{
	if(userId!=''){
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
		}
		else{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange=function(){
  			if (xmlhttp.readyState==4 && xmlhttp.status==200){
    			document.getElementById(divName).innerHTML="<a href=\"javascript:removeSellerSubscription(" + userId + "," + sellerId + ",'" + postingUserName + " ','" + divName + "')\" class=\"blueSellerList\">Remove my subscription to " + postingUserName + " bag postings</a>";
  			}
		}

		url="adds/addSellerSubscription.php?userId=" + userId + "&sellerId=" + sellerId;

		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	else{
		alert("You need to log in to use this feature");
	}
}

function removeSellerSubscription(userId,sellerId,postingUserName,divName)
{
	if(userId!=''){
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  			xmlhttp=new XMLHttpRequest();
		}
		else{// code for IE6, IE5
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange=function(){
  			if (xmlhttp.readyState==4 && xmlhttp.status==200){
    			document.getElementById(divName).innerHTML="<a href=\"javascript:addSellerSubscription(" + userId + "," + sellerId + ",'" + postingUserName + " ','" + divName + "')\" class=\"blueSellerList\">Inform me whenever " + postingUserName + " posts a bag</a>";
  			}
		}

		url="adds/removeSellerSubscription.php?userId=" + userId + "&sellerId=" + sellerId;

		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	else{
		alert("You need to log in to use this feature");
	}
}

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");
}
