
function redirectToInviteFriends(emailId,sweepId){
	document.location.href="/d/promotions/promo3/promo_invite_friends.jsp?emailId="+emailId+"&promoID="+sweepId+"&userExistFlag="+true;
	//document.enrollform.method ="POST";
}

function registerForPromo(){

	if(promoEnrollValidate()){	
		
		document.promo_login_form.action="/d/promotions/promo3/promo_enroll.jsp?action=submit";
		document.promo_login_form.method ="POST";
		document.promo_login_form.submit();
	}
	
}


function promoEnrollValidate()

{	

	var emailAddress=document.getElementById("promo_email_id");
	var confirmEmailAddress=document.getElementById("promo_confirm_email_id");
	var firstName = document.getElementById("promo_first_name_id");
	var lastName = document.getElementById("promo_last_name_id");
	
	//var middleInitial=document.getElementById("promo_middle_name_id");
	
	
	var emailAddressValue=document.getElementById("promo_email_id").value;


	var zipcode1=document.getElementById("promo_zip_code_id");
	
	//Email Id validation
	var email = document.getElementById("promo_email_id").value;
	var confirmEmail = document.getElementById("promo_confirm_email_id").value;

	
	if(email.toLowerCase() == confirmEmail.toLowerCase())
	{
		if(email!='')
		{
			email1 = checkEmail(email);
			if(!email1)
			{                                                                                                           
				displayErrorMessage("The e-mail address you have entered is not valid. Email should be of the form abc@xyz.com");
				emailAddress.select();
				emailAddress.focus();
				return false;
			}
		}
		else
		{
			displayErrorMessage("Error-Please enter a valid email");    
			emailAddress.select();
			emailAddress.focus();
			return false;
		}

	}
	else
	{
		displayErrorMessage("Error-Email addresses don't match.Please re-enter the same email address in the confirm email textbox.");
		confirmEmailAddress.focus();
		confirmEmailAddress.select();
		return false;
	}

	
	//First Name Validation
	if(firstName.value != null && trimStr(firstName.value) != "")
	{	if(nameValidation(firstName.value) == 0)
		{  displayErrorMessage("A valid First name may only contain alphas, numerics, and the following special characters: hyphen, space, apostrophe, and period. A name should not start with a special character or a number.");
		firstName.focus();
		firstName.select();
			return false;
		}
	}
	else
		
	{
		displayErrorMessage("Please enter a first name.");
		firstName.focus();
		firstName.select();
		return false;
	}
	
	//Middle Initial Validation 
	//if(middleInitial.value!='')
	//{
	//	if( nameValidation(middleInitial.value)==0)        
		
	//	{
	//		displayErrorMessage("Middle Name can Contain only alphabets.");
	//		middleInitial.focus();
	//		middleInitial.select();
	//		return false;
	//	}     
	//}

	//Last Name validation
	if(lastName.value != null && trimStr(lastName.value) != "")
	{	if(nameValidation(lastName.value) == 0)
		{  displayErrorMessage("A valid Last name may only contain alphas, numerics, and the following special characters: hyphen, space, apostrophe, and period. A name should not start with a special character or a number.");
		lastName.focus();
		lastName.select();
			return false;
		}
	}
	else
		
	{
		displayErrorMessage("Please enter a last  name.");
		lastName.focus();
		lastName.select();
		return false;
	}
	
	//Zip code Validation
	
	var zipcode=document.getElementById("promo_zip_code_id");
	
	
	
	if(zipcode.value == "")
 	{
 		displayErrorMessage( "Please enter a Zip code.");	
 		zipcode.focus();
 		zipcode.select();
	return false;
	}
	var zip = fnIsNumeric(zipcode.value);
	
	if(!zip)
	{
		displayErrorMessage("Please enter a valid 5-digit ZIP code. ");
		zipcode.focus();
		zipcode.select();
		return false;
	}
	
	if(zipcode.value.length != 5)
	{
		displayErrorMessage("Please enter a valid 5-digit ZIP code. ");
		zipcode.focus();
		zipcode.select();
		return false;
	}
	
	
	return true;
}


function validatePromoFriendsDetails(){
	
	var textArea=document.getElementById("recipient_list").value;
	var emailAddress1=document.getElementById("id_email_1").value;
	
	var emailAddress2=document.getElementById("id_email_2").value;
	
	var emailAddress3=document.getElementById("id_email_3").value;
	
	var emailAddress4=document.getElementById("id_email_4").value;
	
	
	var emailId1=document.getElementById("id_email_1");
	var emailId2=document.getElementById("id_email_2");
	var emailId3=document.getElementById("id_email_3");
	var emailId4=document.getElementById("id_email_4");
	if(textArea=="" && emailAddress1=="" && emailAddress2=="" && emailAddress3=="" && emailAddress4=="" )
	{
		displayErrorMessage("Please enter your friends list from address book or enter it manually.");
		return false;
	}
	
	if(emailAddress1!=""){
		var emailCheck1=checkEmail(emailAddress1);
		if(!emailCheck1){
			displayErrorMessage("The e-mail address you have entered is not valid. Email should be of the form abc@xyz.com");
			emailId1.focus();
			emailId1.select();
		return false;
	}
}
	if(emailAddress2!=""){
	var emailCheck2=checkEmail(emailAddress2);
	if(!emailCheck2){
		displayErrorMessage("The e-mail address you have entered is not valid. Email should be of the form abc@xyz.com");
		document.getElementById("id_email_2").focus();
		document.getElementById("id_email_2").select();
		return false;
	}}
	if(emailAddress3!=""){
	var emailCheck3=checkEmail(emailAddress3);
	if(!emailCheck3){
		displayErrorMessage("The e-mail address you have entered is not valid. Email should be of the form abc@xyz.com");
		document.getElementById("id_email_3").focus();
		document.getElementById("id_email_3").select();
		return false;
	}}
	
	if(emailAddress4!=""){
	var emailCheck4=checkEmail(emailAddress4);
	if(!emailCheck4){
		displayErrorMessage("The e-mail address you have entered is not valid. Email should be of the form abc@xyz.com");
		emailId4.focus();
		emailId4.select();
		return false;
	}}
	
	return true;
}

function validateFrendsDetailsForPromo(){

	if(validatePromoFriendsDetails())
		{
		var recipientList = document.getElementById("recipient_list").value;
		var emailValue = "";
		if(recipientList!=null && recipientList!="") {
			var temp = new Array();
			temp =recipientList.split(",");
			for(var i=0;i<temp.length;i++){
				if (i==0) {
					emailValue=emailValue+temp[i].substring(temp[i].indexOf("<")+1, temp[i].indexOf(">"));	
				} else {
					emailValue=emailValue+","+temp[i].substring(temp[i].indexOf("<")+1, temp[i].indexOf(">"));
				}
			}
		}
		document.promo_frends_invite_form.recipientMails.value=emailValue;
		document.promo_frends_invite_form.action="/d/promotions/promo3/promo_invite_friends.jsp?action=submit";
			document.promo_frends_invite_form.method ="POST";
			document.promo_frends_invite_form.submit();
	}
}


function sendPromoEmail(){
	document.friends_send_email_form.action="/d/promotions/promo3/promo_send_email.jsp?action=submit";
	document.friends_send_email_form.method ="POST";
	document.friends_send_email_form.submit();
	
}

function navigateToPromoShare(emailId,promoId,userId){
	document.location.href="/d/promotions/promo3/promo_print.jsp";
}
