function clearDateField(formField) {
	if (isNaN(formField.value))
	{
		formField.value='';
	}
}
function validateFollowUs(theForm)
{
	var dob = theForm.dob;
	var checkMM = (dob[0].value != "" && dob[0].value != "mm" && dob[0].value != "MM");
	var checkDD = (dob[1].value != "" && dob[1].value != "dd" && dob[1].value != "DD");
	var checkYY = (dob[2].value != "" && dob[2].value != "yyyy" && dob[2].value != "YYYY");
	if (!validRequired(theForm.name,"First Name") ||
		!validEmail(theForm.email,"Email Address",true) ||
		(checkMM && !validNum(dob[0],"DOB(MM)",false)) ||
		(checkDD && !validNum(dob[1],"DOB(DD)",false)) ||
		(checkYY && !validNum(dob[2],"DOB(YYYY)",false)))
		return false;
	//validate DOB
	if (checkMM && checkDD && checkYY) {
		var month = parseInt(dob[0].value,10);
		var day = parseInt(dob[1].value,10);
		var	result = (month > 0) && (month < 13) &&
					 (day > 0) && (day < 32) &&
					 (dob[2].value.length == 4);
		if (!result) {
			alert('Please enter a valid Date Of Birth (DOB).');
			dob[0].focus();	
			return false;
		}	
	}
	if(theForm.useAjax==null){
		theForm.submit(); //if called from community.jsp
	} else {
		return true;
	}
}
function validateSignIn(theForm)
{
	if (!validEmail(theForm.email,"Email",true) ||
		!validRequired(theForm.password,"Password"))
		return false;
	//theForm.submit();
	return true;
}
function validateNewUser(theForm)
{
	if (!validEmail(theForm.email,"Email",true) ||
		!validEmail(theForm.confirmemail,"Confirm Email",true))
		return false;
		
	if (theForm.email.value != theForm.confirmemail.value){
		alert("The Email does not match with the Confirmation")
		return false
	}
	theForm.submit();
}
function validateForgotPasswordForm(formToSubmit, formToValidate)
{
	if (!validEmail(formToValidate.email,"Email Address",true))
		return false;
	formToSubmit.email.value = formToValidate.email.value;
	//pass the url if any
	if (formToValidate.url!=undefined) {
		formToSubmit.url.value = formToValidate.url.value;
	}
	//pass the checkout attribute if any
	if (formToValidate.checkout!=undefined) {
		formToSubmit.checkout.value = formToValidate.checkout.value;
	}
	formToSubmit.submit();	
}
function setAddress(oFormName, dFormName, isChecked) {
	if (isChecked) { //do Same as ...
		swapAddress(document.forms[dFormName],document.forms[dFormName+'Temp']);//saves values in temp form
		swapAddress(document.forms[oFormName],document.forms[dFormName]); //copies values from orig to dest
	} else { //reset as original
		swapAddress(document.forms[dFormName+'Temp'],document.forms[dFormName]);//copies values from temp to dest
	}
}
function swapAddress(originalForm,destinationForm)
{
	destinationForm.firstName.value = originalForm.firstName.value;
	destinationForm.lastName.value = originalForm.lastName.value;
	destinationForm.care.value = originalForm.care.value;
	destinationForm.address.value = originalForm.address.value;
	destinationForm.city.value = originalForm.city.value;
	destinationForm.state.value = originalForm.state.value;
	destinationForm.zip.value = originalForm.zip.value;
	destinationForm.telephone.value = originalForm.telephone.value;
}
function validateRecoverForm(theForm, loggedUserEmail)
{
	if (!validEmail(theForm.email,"Email Address",true))
		return false;
	
	if (loggedUserEmail != '' && theForm.email.value != loggedUserEmail){
		alert("The Email Does Not Match The One From Your Account");
		theForm.email.focus();
		return false;
	}
    var goTo = theForm.action + "?op=" + theForm.op.value + "&email=" + theForm.email.value;
	askChange2(goTo,'passwordRecovery');
}
function handleHttpResponse2(http, param) {
  if (http.readyState == 4) {
  	if (param == 'passwordRecovery') {
	    var result = http.responseText;
	    var pos = result.indexOf('^');
	    var message = result.substring(pos + 1);
	    
	    if(result.substring(0, pos)=='0'){ //if no error
	    	$('.password_recovery .step1').addClass('preload');
	    	$('.password_recovery .step2').removeClass('preload');
	    	//$('.password_recovery').addClass('none');
	    	//$('.password_recovery .text').val('');
	    } else {
	    	alert(message);
	    }
  	}
  } 
}
function openShippingReturn(webAppPath){
	return true;
	//window.open(webAppPath+"/utility/checkout_shipping_return_policy.html",
	//		"shipReturn","width=500, height=400, scrollbars=1, menubar=0, resizable=1, location=0, toolbar=0, status=0, directories=0"+
	//		", left="+ (window.screen.availWidth/2 - 500/2) +
	//		", top="+(window.screen.availHeight/2 - 400/2));
	//return false;
}
