function isValidEmail(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){		   
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){		   
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		    
		    return false
		}
		if (str.indexOf(at,(lat+1))!=-1){		    
		   return false
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){		    
		    return false
		}
		if (str.indexOf(dot,(lat+2))==-1){		    
		    return false
		}
		if (str.indexOf(" ")!=-1){		    
		    return false
		}
	 return true					
}

function isBlank(fieldName){
	if ((document.getElementById(fieldName).value).replace(/^\s+|\s+$/,'')==""){
		return true;
	}else{
		return false;
	}
}

function isNumber(fieldName){
	if (isNaN((document.getElementById(fieldName).value).replace(/^\s+|\s+$/,''))){
		return false;
	}else{
		return true;
	}
}

function validateQty(){
	if (document.getElementById("prodQty").value == 0){
		alert("Quantity must be more than 0")
		return false;
	}else{
		return true;
	}
}

function validateCheckoutDetails(){
	errorTxt = ""	
	if (isBlank('firstname')){
		errorTxt = errorTxt + "Please enter your firstname<br />" 
	}
	if (isBlank('surname')){
		errorTxt = errorTxt + "Please enter your surname<br />" 
	}
	if (isBlank('add1')){
		errorTxt = errorTxt + "Please enter your full address<br />" 
	}
	if (isBlank('add4')){
		errorTxt = errorTxt + "Please enter your town/city name<br />" 
	}
	if (isBlank('postcode')){
		errorTxt = errorTxt + "Please enter your postcode<br />" 
	}	
	if (isBlank('email')){
		errorTxt = errorTxt + "Please enter your email<br />" 
	}else{
		email = document.getElementById('email').value
		if (isValidEmail(email)==false){
			errorTxt = errorTxt + "Please enter a valid email<br />" 
		}	
	}	
	if (isBlank('ncpassword')){
		errorTxt = errorTxt + "Please enter a password<br />" 
	}else{
		if ((document.getElementById('ncpassword').value).length < 6){
			errorTxt = errorTxt + "Your password must be at least 6 characters long<br />" 
		}
	}	
	if (isBlank('ncpasswordcfm')){
		errorTxt = errorTxt + "Please confirm your password<br />" 
	}else{		
		if ((document.getElementById('ncpassword').value) != (document.getElementById('ncpasswordcfm').value)){
			errorTxt = errorTxt + "Please ensure your password and confirm password values are the same<br />" 		
		}
	}
	
	
/*	if (errorTxt!=""){
		document.getElementById("detailErrorTxt").innerHTML = errorTxt
		return false;
	}else{
		return true;
	}	
}

function validateCheckoutDeliveryDetails(){
	errorTxt = ""		
*/	
	if (document.getElementById("useMainAddress").checked==false){	
		if (isBlank("delName")){	
			errorTxt = errorTxt + "Please enter a delivery name<br />" 
		}
		if (isBlank("delAdd1")){	
			errorTxt = errorTxt + "Please enter a full delivery address<br />" 
		}	
		if (isBlank('delAdd4')){
			errorTxt = errorTxt + "Please enter a delivery town/city name<br />" 
		}
		if (isBlank('delPostcode')){
			errorTxt = errorTxt + "Please enter a delivery postcode<br />" 
		}	
	}
	if (errorTxt!=""){
		//document.getElementById("deliveryErrorTxt").innerHTML = errorTxt
		document.getElementById("detailErrorTxt").innerHTML = errorTxt
		return false;
	}else{
		return true;
	}	
}

function validateECCheckoutDetails(){
	errorTxt = ""		
	if (isBlank('ecemail')){
		errorTxt = errorTxt + "Please enter your email<br />" 
	}else{
		email = document.getElementById('ecemail').value
		if (isValidEmail(email)==false){
			errorTxt = errorTxt + "Please enter a valid email<br />" 
		}	
	}	
	if (isBlank('ecpassword')){
			errorTxt = errorTxt + "Please enter a password<br />" 
	}
	if (errorTxt!=""){
		//document.getElementById("deliveryErrorTxt").innerHTML = errorTxt
		document.getElementById("detailErrorTxt").innerHTML = errorTxt
		return false;
	}else{
		return true;
	}	
}
