var intervalID = 0;			// time for polling https cookie (add cc info)
var wnd;					// https pop up

/* Omniture analytics tracking */
var OmnitureEvent = new YAHOO.util.CustomEvent('OmnitureEvent');	

/* Sign up customer type */
/* 1 Clearwire, 2 Clearmedia, 6 Clear */
var customerType; 

/* Invalid field error messages */
var invalidZipMsg = 'This field must be a 5 digit U.S. ZIP code. Please try again.';
var invalidEmailMsg = 'Invalid email address. Please try again.';
var invalidPasswordMsg = 'This field must be between 6-16 characters and may contain letters, numbers, periods and/or dashes.';
var invalidUsernameMsg = 'This field must start with at least two letters, may not contain any special character and must be between 4 and 16 characters long.';

/* String trim method */
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
}

/* Ensure credit card is valid number and matches card type selected */
function isValidCC(type,num) {
	var valid = true;	
	if (!isCreditCard(num)) {
		return false;
	}	
	if (type == 'Amex') {
		if (!isAmericanExpress(num)) {
			valid = false;
		}
	} else if (type == 'Discover') {
		if (!isDiscover(num)) {
			valid = false;
		}	
	} else if (type == 'MasterCard') {
		if (!isMasterCard(num)) {
			valid = false;
		}
	} else if (type == 'Visa') {
		if (!isVisa(num)) {
			valid = false;
		}
	}
	return valid;
}

/* Ensure credit card CVV matches card type selected */
function isValidCVV(type,num) {
	var valid = true;	

	if (type == 'Amex') {
		if (num.length != 4) {
			valid = false;
		}
	} else if (type == 'Discover' || type == 'MasterCard' || type == 'Visa') {
		if (num.length != 3) {
			valid = false;
		}
	} 
	return valid;
}

/* Ensure valid username */
/* First 2 characters are alphabetic, followed by any length of alphanumeric */
function isValidUserName(un) {
	var regExpr = /^[a-zA-Z]{2}[a-zA-Z0-9]{2,14}$/;
    if ( ! regExpr.test(un) ){
        return false;
    } else {
		return true;
	}
}

/* Ensure age of customer > 13 */
function verifyBirthDate(form){
	var month = form.elements["signUpDOBMonth"].value;
	var day = form.elements["signUpDOBDate"].value;
	var year = form.elements["signUpDOBYear"].value;
	if(parseInt(day, 10) < 10){
		day = "0" + parseInt(day, 10); 
	}
	if(parseInt(month, 10) < 10){
		month = "0" + parseInt(month, 10); 
	}
	var bday = parseInt(year+month+day);

	var currentTime = new Date();
	var currentMonth = (currentTime.getMonth() + 1);
	var currentDay = currentTime.getDate(); 
	var currentYear = (currentTime.getFullYear()) + "";	
	if(parseInt(currentDay, 10) < 10){
		currentDay = "0" + parseInt(currentDay, 10); 
	}
	if(parseInt(currentMonth, 10) < 10){
		currentMonth = "0" + parseInt(currentMonth, 10); 
	}	
	var currentDate = parseInt(currentYear+currentMonth+currentDay);
	if((currentDate - bday) <130000){
		return false;
	}else{
		return true;
	}
}

/* Ensure valid password */
/* Minimum length of 6, maximum length of 16 alphanumeric w/ '.' and '-' allowed */
function isValidPassword(pw) {
	var regExpr = /^[a-zA-Z0-9\.\-]{6,16}$/;
    if ( ! regExpr.test(pw) ){
        return false;
    } else {
		return true;
	}
}

/* Ensure properly formatted phone number */
/* Acceptable formats: 1234567890, 123-456-7890, (123) 456-7890 */
function isValidPhone(phoneNumber){
    var regExpr = /^[\d]{10}$|^[\d]{3}-[\d]{3}-[\d]{4}$|^\([\d]{3}\) {0,}[\d]{3}-[\d]{4}$/ ;
    var valid = true ;
    if ( ! regExpr.test(phoneNumber) ){
        valid = false ;
    }
    return valid ;
}

/* Ensure properly formatted zip code */
/* Acceptable formats: 12345, 12345-1234 */
function isValidZipCode(zip) {
	var regExpr = /^[\d]{5}$|^[\d]{5}-[\d]{4}$/;	
	var valid = true;	
	if ( ! regExpr.test(zip) ) {
		valid = false;
	}	
	return valid;
}

/* Ensure expiration date is in the future */
function isValidExpDate(month,year) {
	var valid = true;	
	var currentDate = new Date();	
	var expDate = new Date();
	expDate.setMonth(month-1);
	expDate.setYear(20+year);		
	if (expDate < currentDate) {
		valid = false;
	}	
	return valid;
}

/* Create cookie (used for https add credit card process) */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/;domain=clear365.com";
}

/* Read cookie (used for https add credit card process) */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/* Erase cookie (used for https add credit card process) */
function eraseCookie(name) {
	createCookie(name,"",-1);
}

/* Create https pop up for add credit card process */
function httpsPop(url,form) {
	wnd = window.open(url,"child_wnd","location=no,width=500,height=200");
	wnd.location.href = url + '?bn=' + escape(form.billingName.value) + 
							  '&ba=' + escape(form.billingAddress.value) +
							  '&ba2=' + escape(form.billingAddress2.value) +
							  '&bc=' + escape(form.billingCity.value) +
							  '&bs=' + escape(form.billingState.value) +
							  '&bz=' + escape(form.billingZip.value) +
							  '&bp=' + escape(form.billingPhone.value) +
							  '&bcct=' + escape(form.billingCCType.value) +
							  '&bccn=' + escape(form.billingCCNumber.value) +
							  '&bccedm=' + escape(form.billingCCExpDateMonth.value) +
							  '&bccedy=' + escape(form.billingCCExpDateYear.value) +
							  '&bcvv=' + escape(form.billingCVV.value) +
							  '&accountId=' + escape(form.accountId.value) +
							  '&guid=' + escape(form.guid.value) +
							  '&email=' + escape(form.email.value);
}

/* Have parent window constantly poll client system for cookie with add credit card response */
function httpsPoll(scenario) {
	switch(scenario){
		case 0:	
			intervalID = setInterval("httpsResponse(0)",1000);
			break;
		case 1:
			intervalID = setInterval("httpsResponse(1)",1000);		
			break;
        case 2:
			intervalID = setInterval("httpsResponse(2)",1000);        
			break;
			
	}
}

/* Process https add credit card response */
/* case 0: sign up (DEPRECIATED 02/09) */
/* case 1: purchase process */
/* case 2: my account */
function httpsResponse(scenario) {
	switch(scenario){
		case 0:	
	if (readCookie('ADDCCCODE') == 0) {
		clearInterval(intervalID);
		wnd.close();
		eraseCookie('ADDCCCODE');
		eraseCookie('ADDCCMSG');
		signUpBillingSubmit();
	} else if (readCookie('ADDCCCODE') != null){
		clearInterval(intervalID);	
		wnd.close();		
		document.getElementById('addCCSignUpProcessing').innerHTML = '';	
		throwPromoFeedback('addCCSignUp', readCookie('ADDCCMSG'));
		eraseCookie('ADDCCCODE');
		eraseCookie('ADDCCMSG');				
	}
	break;
	case 1:
	if (readCookie('ADDCCCODE') == 0) {
		clearInterval(intervalID);
		wnd.close();
		eraseCookie('ADDCCCODE');
		eraseCookie('ADDCCMSG');		
		document.getElementById('addCCProcessing').innerHTML = '';
		YAHOO.CLWRBuyProcess.clearMediaCCInfo.hide();		
		YAHOO.CLWRBuyProcess.songPurchaseConf.show();
		document.getElementById('songPurchFt').style.display = 'none';					
		document.getElementById('songPurchaseConfProcessing').innerHTML = '<img src="http://cache1.clear365.com/images/loading.gif" height="20" width="20" />&nbsp; Processing...';
		document.getElementById('finalSongTitle').innerHTML=hrefTrim(document.getElementById('songTitle_'+currentSong).innerHTML);
		document.getElementById('finalArtist').innerHTML=hrefTrim(document.getElementById('songArtist_'+currentSong).innerHTML);
		document.getElementById('finalCost').innerHTML=document.getElementById('songPrice_'+currentSong).innerHTML;	
		var finalSongID = document.getElementById('songID_'+currentSong).innerHTML;
		
		/* Omniture Begin */
		var s = s_gi(s_account);
		s.templtv=s.linkTrackVars;
		s.templte=s.linkTrackEvents;
		s.linkTrackVars="eVar10,eVar11,eVar16,prop8";
		s.linkTrackEvents="event11,event18";
		s.eVar10="PurchaseWithBilling";
		s.prop8=s.eVar16="music:"+finalSongID;
		s.eVar16="Music Purchase Billing Information";
		s.eVar11='new customer';
		s.events='event18,event11';
		s.tl(OmnitureEvent,'o','Purchase');
		if(s.templtv)s.linkTrackVars=s.templtv;
		if(s.templte)s.linkTrackEvents=s.templte;
		/* Omniture End */		
		
		contentPurchase(finalSongID);	
	} else if (readCookie('ADDCCCODE') != null){
		clearInterval(intervalID);	
		wnd.close();		
		document.getElementById('addCCProcessing').innerHTML = '';	
		throwPromoFeedback('addCC', readCookie('ADDCCMSG'));
		eraseCookie('ADDCCCODE');
		eraseCookie('ADDCCMSG');				
	}	
	break;
	
	case 2:
    if (readCookie('ADDCCCODE') == 0) {
        clearInterval(intervalID);
        wnd.close();
        eraseCookie('ADDCCCODE');
        eraseCookie('ADDCCMSG');        
        //successful logic here (i.e. Display success message on parent window)   
        errorMessage('creditErrorMessage', "");
 		setInputValue('set_cvv', "");
		errorMessage('successUpdateCredit', "Your credit card information has been successfully updated."); 
		document.getElementById('ccSetCardExMonth').value =""; 
		document.getElementById('ccSetCardExYear').value ="";
 		getPaymentInfo();
		  	 		
    } else if (readCookie('ADDCCCODE') != null){
        clearInterval(intervalID);    
        wnd.close();        
       //failure logic here (i.e. Display error message on parent window)          
        errorMessage('creditErrorMessage', readCookie('ADDCCMSG'));
		document.getElementById('paymentInfoSaveButton').disabled = false;		  	 		
        eraseCookie('ADDCCCODE');
        eraseCookie('ADDCCMSG');                
    }    
    break;
		
	}
}

/* Form validation - check for empty string */
function cwCheckInvalidString (theField) {   
    if (isWhitespace(theField.value)) 
		return true;
	else return false;
}

/* Ensure valid email format */
function cwCheckInvalidEmail (theField) {   
    if (isEmpty(theField.value)) return true;
    else if (!isEmail(theField.value, false)) 
       return true;
    else return false;
}

/* Render and show yui panel for sign up process */
function signUp() {	
	YAHOO.CLWRBuyProcess.clearMediaLogin.hide();
	YAHOO.CLWRBuyProcess.clearMediaLogin.hideMask();	
	YAHOO.CLWRBuyProcess.clearMediaThankYou.hide();
	YAHOO.CLWRBuyProcess.clearMediaThankYou.hideMask();	
	divRender('clearMediaSignUp1');	
	YAHOO.CLWRBuyProcess.clearMediaSignUp1.show();	
	document.getElementById('cbSignUpType').focus();	
}

/* Render appropriate yui panel for clearwire or clearmedia customer during sign up */
function signUpPre() {
	// if current ClearWire subscriber show username/password panel
	// cbSignUpType[0] - Clear
	// cbSignUpType[1] - Clearwire
	// cbSignUpType[2] - Clear365
	if (document.clearMediaSignUp1.cbSignUpType[0].checked || document.clearMediaSignUp1.cbSignUpType[1].checked) {		
		YAHOO.CLWRBuyProcess.clearMediaSignUp1.hide();
		YAHOO.CLWRBuyProcess.clearMediaSignUp1.hideMask();		
		divRender('clearMediaCurrentSubscriberLogin');
		if (document.clearMediaSignUp1.cbSignUpType[0].checked) {
			customerType = 6;
			document.getElementById('clearMediaLoginHeader').innerHTML = '<img src="images/box/onlyClear_logo.gif" border="0"><br><br><h4>Please enter your Clear account information:</h4>';
	 		document.getElementById('clearMediaLoginFooter').innerHTML = '<div class="clearfix"><div class="buttons" style="float:left;"><p>If you have not set up your Clear password and account info, <a href="https://www.clear.com/my_account/signin.php" target="_blank" tabindex="6">Click Here.</a><br/></div></div>';			
		} else if (document.clearMediaSignUp1.cbSignUpType[1].checked) {
			customerType = 1;
			document.getElementById('clearMediaLoginHeader').innerHTML = '<img src="images/box/onlyClearwire.gif" border="0"><br><br><h4>Please enter your Clearwire account information:</h4>';
			document.getElementById('clearMediaLoginFooter').innerHTML = '<div class="clearfix"><div class="buttons" style="float:left;"><p>If you have not set up your Clearwire password and account info, <a href="https://www.clearwire.com/my_account/signin.php" target="_blank" tabindex="6">Click Here.</a><br/></div></div>';			
		}		
		/* Hide any previously displayed info messages */
		document.getElementById('signLoginInfoTextMsgClearwire').style.display = 'none';
		document.getElementById('signLoginInfoTextMsgClear').style.display = 'none';
		
		YAHOO.CLWRBuyProcess.clearMediaCurrentSubscriberLogin.show();
		clearFieldError('clearMediaCurrentSubscriberLogin');
		document.getElementById('subscriberUsernameText').focus();	
		
		//Add omniture tag call for clearwire customer
		var s = s_gi(s_account);
		s.templtv=s.linkTrackVars;
		s.templte=s.linkTrackEvents;
		s.linkTrackVars='eVar10,eVar11,events';
		s.linkTrackEvents='event8,event11';
		s.eVar10='initialSignUp';
		s.eVar11='existingClearwire';	
		s.events='event8,event11';		
		s.tl(OmnitureEvent,'o','Sign-Up');
		if(s.templtv)s.linkTrackVars=s.templtv;
		if(s.templte)s.linkTrackEvents=s.templte;		
		//End omniture tag
		
	// if not a ClearWire subscriber show registration form
	} else if (document.clearMediaSignUp1.cbSignUpType[2].checked) {		
		customerType = 2;
		YAHOO.CLWRBuyProcess.clearMediaSignUp1.hide();
		YAHOO.CLWRBuyProcess.clearMediaSignUp1.hideMask();		
		divRender('clearMediaSignUp2');
		/* Mark notification opt-in checkbox as checked */
		document.getElementById('clear365Yes').checked = true;		
		YAHOO.CLWRBuyProcess.clearMediaSignUp2.show();
		YAHOO.CLWRBuyProcess.clearMediaSignUp2.center();
		document.getElementById('signUpFirstName').focus();
		
		//Add omniture tag call for non clearwire customer		
		var s = s_gi(s_account);
		s.templtv=s.linkTrackVars;
		s.templte=s.linkTrackEvents;
		s.linkTrackVars='eVar10,eVar11,events';
		s.linkTrackEvents='event8,event11';
		s.eVar10='initialSignUp';
		s.eVar11='new customer';	
		s.events='event8,event11';	
		s.tl(OmnitureEvent,'o','Sign-Up');
		if(s.templtv)s.linkTrackVars=s.templtv;
		if(s.templte)s.linkTrackEvents=s.templte;	
		//End omniture tag
		
	}
}

/* Form validation - sso login */
function ssoLoginValidation(form) {
	var errorCount = 0;
	
	if (cwCheckInvalidString(form.elements["j_username"])) {
		throwFieldError('loginUsernameText', 'This field is required.');
		document.getElementById('loginUsernameText').focus();
		errorCount++;
	} else {
		clearFieldError('loginUsernameText');
	}	
	
	if (cwCheckInvalidString(form.elements["j_password"])) {
		throwFieldError('loginPasswordText', 'This field is required.');	
		document.getElementById('loginPasswordText').focus();	
		errorCount++;
	} else {
		clearFieldError('loginPasswordText');
	}
	
	/* If both username and password have errors, place focus on username */
	if (errorCount == 2) {
		document.getElementById('loginUsernameText').focus();
	}
	
	if (errorCount == 0) {
		ssoLoginSubmission();
	} 
}

/* Form validation - existing username check */
function existingUsernameValidation(form) {
	clearPromoFeedback('clearMediaCurrentSubscriberLogin');

	var errorCount = 0;
	
	if (cwCheckInvalidString(form.elements["subscriberUsernameText"])) {
		throwFieldError('subscriberUsernameText', 'This field is required.');	
		document.getElementById('subscriberUsernameText').focus();
		errorCount++;
	} else {
		clearFieldError('subscriberUsernameText');	
	}
	
	if (cwCheckInvalidString(form.elements["subscriberPasswordText"])) {
		throwFieldError('subscriberPasswordText', 'This field is required.');
		document.getElementById('subscriberPasswordText').focus();	
		errorCount++;
	} else {
		clearFieldError('subscriberPasswordText');	
	}
	
	if (errorCount == 0) {
		checkDuplicateUsername();
	}
}

/* Form validation - clearmedia sign up */
function signUpSubmit(form) {
	var errorCount = 0;
	clearFieldError('signUpFirstName');
	clearFieldError('signUpLastName');
	clearFieldErrorById('signUpDOBMonth','signUpDOBError');
	clearFieldErrorById('signUpDOBDate','signUpDOBError');	
	clearFieldErrorById('signUpDOBYear','signUpDOBError');		
	clearFieldError('signUpZip');
	clearFieldError('signUpSecurityQuestion');
	clearFieldError('signUpSecurityQuestionAnswer');
	clearFieldError('signUpEmail');
	clearFieldError('signUpEmailVerify');
	clearFieldError('signUpUserName');
	clearFieldError('signUpPassword');
	clearFieldError('signUpPasswordVerify');
	clearFieldError('c365AgreeTerms');

	if(verifyBirthDate(form) == false){
		throwFieldErrorById('signUpDOBYear', 'signUpDOBError', 'You must be 13 or older to join.')
		errorCount++;		
	}		
	if (cwCheckInvalidString(form.elements["signUpFirstName"])) {
		throwFieldError('signUpFirstName', 'This field is required.')
		errorCount++;
	} else if (!isAlphabetic(form.elements["signUpFirstName"].value)) {
		throwFieldError('signUpFirstName', 'This field only accepts alphabetic characters.')
		errorCount++;	
	}
	if (cwCheckInvalidString(form.elements["signUpLastName"])) {
		throwFieldError('signUpLastName', 'This field is required.')
		errorCount++;
	} else if (!isAlphabetic(form.elements["signUpLastName"].value)) {
		throwFieldError('signUpLastName', 'This field only accepts alphabetic characters.')
		errorCount++;	
	}
	if (cwCheckInvalidString(form.elements["signUpDOBMonth"])) {
		throwFieldErrorById('signUpDOBMonth', 'signUpDOBError', 'This field is required.')
		errorCount++;
	} else if (cwCheckInvalidString(form.elements["signUpDOBDate"])) {
		throwFieldErrorById('signUpDOBDate', 'signUpDOBError', 'This field is required.')
		errorCount++;
	} else if (cwCheckInvalidString(form.elements["signUpDOBYear"])) {
		throwFieldErrorById('signUpDOBYear', 'signUpDOBError', 'This field is required.')
		errorCount++;
	} else if (!isDate(form.elements["signUpDOBYear"].value,form.elements["signUpDOBMonth"].value,form.elements["signUpDOBDate"].value)) {
		throwFieldErrorById('signUpDOBMonth', 'signUpDOBError', 'This is not a valid calendar date.')
		errorCount++;	
	}
	if (cwCheckInvalidString(form.elements["signUpZip"])) {
		throwFieldError('signUpZip', 'This field is required.')
		errorCount++;
	} else if (!isValidZipCode(form.elements["signUpZip"].value)) {
		throwFieldError('signUpZip', invalidZipMsg)
		errorCount++;		
	} else if (form.elements["signUpZip"].value.length > 5) {
		form.elements["signUpZip"].value = form.elements["signUpZip"].value.substring(0,5);
	}
	if (cwCheckInvalidString(form.elements["signUpSecurityQuestion"])) {
		throwFieldError('signUpSecurityQuestion', 'This field is required.')
		errorCount++;
	} 
	if (cwCheckInvalidString(form.elements["signUpSecurityQuestionAnswer"])) {
		throwFieldError('signUpSecurityQuestionAnswer', 'This field is required.')
		errorCount++;
	} 
	if (cwCheckInvalidString(form.elements["signUpEmail"])) {
		throwFieldError('signUpEmail', 'This field is required.')
		errorCount++;
	} else if (cwCheckInvalidEmail(form.elements["signUpEmail"])) {
		throwFieldError('signUpEmail', invalidEmailMsg)
		errorCount++;
	} 
	if (cwCheckInvalidString(form.elements["signUpEmailVerify"])) {
		throwFieldError('signUpEmailVerify', 'This field is required.')
		errorCount++;
	} else if (cwCheckInvalidEmail(form.elements["signUpEmailVerify"])) {
		throwFieldError('signUpEmailVerify', invalidEmailMsg)
		errorCount++;
	} 
	if (cwCheckInvalidString(form.elements["signUpUserName"])) {
		throwFieldError('signUpUserName', 'This field is required.')
		errorCount++;
	} else if (!isValidUserName(form.elements["signUpUserName"].value)) {
		throwFieldError('signUpUserName', invalidUsernameMsg)
		errorCount++;	
	}
	if (cwCheckInvalidString(form.elements["signUpPassword"])) {
		throwFieldError('signUpPassword', 'This field is required.')
		errorCount++;
	} else if (!isValidPassword(form.elements["signUpPassword"].value)) {
		throwFieldError('signUpPassword', invalidPasswordMsg)
		errorCount++;	
	}
	if (cwCheckInvalidString(form.elements["signUpPasswordVerify"])) {
		throwFieldError('signUpPasswordVerify', 'This field is required.')
		errorCount++;
	} 
	if(form.elements["signUpEmail"].value != form.elements["signUpEmailVerify"].value) {
		throwFieldError("signUpEmailVerify","Email does not match");
		errorCount++;
	}
	if (form.elements["signUpPassword"].value != form.elements["signUpPasswordVerify"].value) {
		throwFieldError("signUpPasswordVerify","Password does not match");
		errorCount++;
	}
	if (!document.getElementById('c365AgreeTerms').checked) {
		throwFieldError('c365AgreeTerms', 'You must agree to the Terms of Use before proceeding.')
		errorCount++;		
	}	
	if (errorCount == 0) {
		createUser(form);
	} 
}

/* Form validation - clearwire.com existing member sign up */
function cwSignUpSubmit(form) {	
	/* Remove all existing error messages from form */
	clearFieldError('cwSignUpFirstName');
	clearFieldError('cwSignUpLastName');
	clearFieldErrorById('cwSignUpDOBMonth','cwSignUpDOBError');
	clearFieldErrorById('cwSignUpDOBDate','cwSignUpDOBError');	
	clearFieldErrorById('cwSignUpDOBYear','cwSignUpDOBError');		
	clearFieldError('cwSignUpZip');
	clearFieldError('cwSignUpSecurityQuestion');
	clearFieldError('cwSignUpSecurityQuestionAnswer');
	clearFieldError('cwSignUpEmail');
	clearFieldError('cwAgreeTerms');
			
	var errorCount = 0;

	if (cwCheckInvalidString(form.elements["signUpFirstName"])) {
		throwFieldError('cwSignUpFirstName', 'This field is required.')
		errorCount++;
	} else if (!isAlphabetic(form.elements["signUpFirstName"].value)) {
		throwFieldError('cwSignUpFirstName', 'This field only accepts alphabetic characters.')
		errorCount++;	
	}
	if (cwCheckInvalidString(form.elements["signUpLastName"])) {
		throwFieldError('cwSignUpLastName', 'This field is required.')
		errorCount++;		
	} else if (!isAlphabetic(form.elements["signUpLastName"].value)) {
		throwFieldError('cwSignUpLastName', 'This field only accepts alphabetic characters.')
		errorCount++;	
	}
	if(verifyBirthDate(form) == false){
		throwFieldErrorById('cwSignUpDOBYear', 'cwSignUpDOBError', 'You must be 13 or older to join.')
		errorCount++;		
	} else if (cwCheckInvalidString(form.elements["signUpDOBMonth"])) {
		throwFieldErrorById('cwSignUpDOBMonth', 'cwSignUpDOBError', 'This field is required.')
		errorCount++;
	} else if (cwCheckInvalidString(form.elements["signUpDOBDate"])) {
		throwFieldErrorById('cwSignUpDOBDate', 'cwSignUpDOBError', 'This field is required.')
		errorCount++;
	} else if (cwCheckInvalidString(form.elements["signUpDOBYear"])) {
		throwFieldErrorById('cwSignUpDOBYear', 'cwSignUpDOBError', 'This field is required.')
		errorCount++;
	} else if (!isDate(form.elements["signUpDOBYear"].value,form.elements["signUpDOBMonth"].value,form.elements["signUpDOBDate"].value)) {
		throwFieldErrorById('cwSignUpDOBMonth', 'cwSignUpDOBError', 'This is not a valid calendar date.')
		errorCount++;	
	}
	if (cwCheckInvalidString(form.elements["signUpZip"])) {
		throwFieldError('cwSignUpZip', 'This field is required.')
		errorCount++;
	} else if (!isValidZipCode(form.elements["signUpZip"].value)) {
		throwFieldError('cwSignUpZip', invalidZipMsg)
		errorCount++;		
	} else if (form.elements["signUpZip"].value.length > 5) {
		form.elements["signUpZip"].value = form.elements["signUpZip"].value.substring(0,5);
	}
	if (cwCheckInvalidString(form.elements["signUpSecurityQuestion"])) {
		throwFieldError('cwSignUpSecurityQuestion', 'This field is required.')
		errorCount++;
	} 
	if (cwCheckInvalidString(form.elements["signUpSecurityQuestionAnswer"])) {
		throwFieldError('cwSignUpSecurityQuestionAnswer', 'This field is required.')
		errorCount++;
	} 
	if (cwCheckInvalidString(form.elements["signUpEmail"])) {
		throwFieldError('cwSignUpEmail', 'This field is required.')
		errorCount++;
	} else if (cwCheckInvalidEmail(form.elements["signUpEmail"])) {
		throwFieldError('cwSignUpEmail', invalidEmailMsg)
		errorCount++;
	}
	if (!document.getElementById('cwAgreeTerms').checked) {
		throwFieldError('cwAgreeTerms', 'You must agree to the Terms of Use before proceeding.')
		errorCount++;		
	}
	if (errorCount == 0) {
		createUser(form);
	} 
}

/* Form validation - Add CC (Sign Up) */
function addCCSignUpValidation(url,form) {
	/* Remove all existing error messages from form */
	clearFieldError('billingFirstName');
	clearFieldError('billingLastName');
	clearFieldError('billingAddress');
	clearFieldError('billingCity');
	clearFieldError('billingState');
	clearFieldError('billingZip');
	clearFieldError('billingPhone');
	clearFieldError('billingCCType');
	clearFieldError('billingCCNumber');
	clearFieldErrorById('billingCCExpDateMonth','billingCCExpError');
	clearFieldErrorById('billingCCExpDateYear','billingCCExpError');		
	clearFieldError('billingCVV');
	
	var errorCount = 0;
	
	if (cwCheckInvalidString(form.elements["billingFirstName"])) {
		throwFieldError('billingFirstName', 'This field is required.')
		errorCount++;
	} else if (!isAlphabetic(form.elements["billingFirstName"].value)) {
		throwFieldError('billingFirstName', 'This field only accepts alphabetic characters.')
		errorCount++;	
	} 	
	if (cwCheckInvalidString(form.elements["billingLastName"])) {
		throwFieldError('billingLastName', 'This field is required.')
		errorCount++;
	} else if (!isAlphabetic(form.elements["billingLastName"].value)) {
		throwFieldError('billingLastName', 'This field only accepts alphabetic characters.')
		errorCount++;	
	} 	
	if (cwCheckInvalidString(form.elements["billingAddress"])) {
		throwFieldError('billingAddress', 'This field is required.')
		errorCount++;
	} 	
	if (cwCheckInvalidString(form.elements["billingCity"])) {
		throwFieldError('billingCity', 'This field is required.')
		errorCount++;
	} 	
	if (cwCheckInvalidString(form.elements["billingState"])) {
		throwFieldError('billingState', 'This field is required.')
		errorCount++;
	} 	
	if (cwCheckInvalidString(form.elements["billingZip"])) {
		throwFieldError('billingZip', 'This field is required.')
		errorCount++;
	} else if (!isValidZipCode(form.elements["billingZip"].value)) {
		throwFieldError('billingZip', 'A valid zip code is required.')
		errorCount++;		
	} else if (form.elements["billingZip"].value.length > 5) {
		form.elements["billingZip"].value = form.elements["billingZip"].value.substring(0,5);
	}
	if (cwCheckInvalidString(form.elements["billingPhone"])) {
		throwFieldError('billingPhone', 'This field is required.')
		errorCount++;
	} else if (!isValidPhone(form.elements["billingPhone"].value)) {
		throwFieldError('billingPhone', 'A valid phone number is required')
		errorCount++;	
	}
	if (cwCheckInvalidString(form.elements["billingCCType"])) {
		throwFieldError('billingCCType', 'This field is required.')
		errorCount++;
	} 		
	if (cwCheckInvalidString(form.elements["billingCCNumber"])) {
		throwFieldError('billingCCNumber', 'This field is required.')
		errorCount++;
	} else if (!isNonnegativeInteger(form.elements["billingCCNumber"].value)){
		throwFieldError('billingCCNumber', 'This field only accepts numeric characters.')
		errorCount++;	
	} else if (!isValidCC(form.elements["billingCCType"].value,form.elements["billingCCNumber"].value)) {
		throwFieldError('billingCCNumber', 'Please enter a valid credit card number.')
		errorCount++;	
	}	
	if (cwCheckInvalidString(form.elements["billingCCExpDateMonth"])) {
		throwFieldErrorById('billingCCExpDateMonth', 'billingCCExpError', 'This field is required.')
		errorCount++;
	} else if (cwCheckInvalidString(form.elements["billingCCExpDateYear"])) {
		throwFieldErrorById('billingCCExpDateYear', 'billingCCExpError', 'This field is required.')		
		errorCount++;
	} else if (!isValidExpDate(form.elements["billingCCExpDateMonth"].value,form.elements["billingCCExpDateYear"].value)) {
		throwFieldErrorById('billingCCExpDateMonth', 'billingCCExpError', 'Expiration date invalid.')
		errorCount++;		
	}
	if (cwCheckInvalidString(form.elements["billingCVV"])) {
		throwFieldError('billingCVV', 'This field is required.')
		errorCount++;
	} else if (!isNonnegativeInteger(form.elements["billingCVV"].value)){
		throwFieldError('billingCVV', 'This field only accepts numeric characters.')
		errorCount++;	
	}				
	if (errorCount == 0) {
		document.getElementById('addCCSignUpProcessing').innerHTML = '<img src="http://cache1.clear365.com/images/loading.gif" height="20" width="20" />&nbsp; Processing...';	
		httpsPop(url,form);
		httpsPoll(0);
	} 		
}

/* Form validation - Add CC (Purchase) */
function addCCPurchaseValidation(url,form) {
	/* Remove all existing error messages from form */
	clearFieldError('billNameText');
	clearFieldError('billAddressText');
	clearFieldError('cityText');
	clearFieldError('zipText');
	clearFieldError('billingCCTypeText');
	clearFieldError('ccNumberText');
	clearFieldErrorById('expMonthObj','expError');
	clearFieldErrorById('expYearObj','expError');		
	clearFieldError('ccSecurityText');
	clearFieldError('phoneNumberText');	
	
	var errorCount = 0;

	if (cwCheckInvalidString(form.elements["billNameText"])) {
		throwFieldError('billNameText', 'This field is required.');
		errorCount++;
	} else if (!isAlphabetic(stripCharsInBag(stripWhitespace(form.elements["billNameText"].value),'.-'))) {
		throwFieldError('billNameText', 'This field only accepts alphabetic characters.');
		errorCount++;	
	}
	if (cwCheckInvalidString(form.elements["billAddressText"])) {
		throwFieldError('billAddressText', 'This field is required.');
		errorCount++;
	} 	
	if (cwCheckInvalidString(form.elements["cityText"])) {
		throwFieldError('cityText', 'This field is required.');
		errorCount++;
	}
	if (cwCheckInvalidString(form.elements["zipText"])) {
		throwFieldError('zipText', 'This field is required.');
		errorCount++;
	} else if (!isValidZipCode(form.elements["zipText"].value)) {
		throwFieldError('zipText', 'A valid zip code is required.');
		errorCount++;		
	} else if (form.elements["zipText"].value.length > 5) {
		form.elements["zipText"].value = form.elements["zipText"].value.substring(0,5);
	}
	if (!cwCheckInvalidString(form.elements["phoneNumberText"]) && !isValidPhone(form.elements["phoneNumberText"].value)) {
		throwFieldError('phoneNumberText', 'Please enter a valid phone number or leave this field empty.');
		errorCount++;	
	}		
	if (cwCheckInvalidString(form.elements["billingCCTypeText"])) {
		throwFieldError('billingCCTypeText', 'This field is required.');
		errorCount++;
	} 		
	if (cwCheckInvalidString(form.elements["ccNumberText"])) {
		throwFieldError('ccNumberText', 'This field is required.');
		errorCount++;
	} else if (!isNonnegativeInteger(form.elements["ccNumberText"].value)){
		throwFieldError('ccNumberText', 'This field only accepts numeric characters.');
		errorCount++;	
	} else if (!isValidCC(form.elements["billingCCTypeText"].value,form.elements["ccNumberText"].value)) {
		throwFieldError('ccNumberText', 'Please enter a valid credit card number.');
		errorCount++;	
	} 		
	if (cwCheckInvalidString(form.elements["expMonthObj"])) {
		throwFieldErrorById('expMonthObj', 'expError', 'This field is required.');
		errorCount++;
	} else if (cwCheckInvalidString(form.elements["expYearObj"])) {
		throwFieldErrorById('expYearObj', 'expError', 'This field is required.');		
		errorCount++;
	}  else if (!isValidExpDate(form.elements["expMonthObj"].value,form.elements["expYearObj"].value)) {
		throwFieldErrorById('expMonthObj', 'expError', 'Expiration date invalid.');
		errorCount++;		
	}		
	if (cwCheckInvalidString(form.elements["ccSecurityText"])) {
		throwFieldError('ccSecurityText', 'This field is required.');
		errorCount++;
	} else if (!isNonnegativeInteger(form.elements["ccSecurityText"].value)){
		throwFieldError('ccSecurityText', 'This field only accepts numeric characters.');
		errorCount++;	
	} else if (!isValidCVV(form.elements["billingCCTypeText"].value,form.elements["ccSecurityText"].value)) {
		throwFieldError('ccSecurityText', 'Please enter a valid credit card security code.');
		errorCount++;
	}
	if (errorCount == 0) {
		document.getElementById('addCCProcessing').innerHTML = '<img src="http://cache1.clear365.com/images/loading.gif" height="20" width="20" />&nbsp; Processing...';		
		httpsPop(url,form);
		httpsPoll(1);	
	} 		
}

/* Form validation - Forgot password username */
function verifyForgotPassUsername(form) {
	var errorCount = 0;	
	if (cwCheckInvalidString(form.elements["subscriberUsernameText"])) {
		errorCount++;
	} 						
	if (errorCount == 0) {
		getForgotPassEmail();
	} else {
		throwPromoFeedback('forgotPass', 'This field is required.');	
	}	
}

/* Form validation - DOB */
function verifyDOBValidation(form) {
	var errorCount = 0;	
	if (cwCheckInvalidString(form.elements["confirmDOBMonth"]) ||
		cwCheckInvalidString(form.elements["confirmDOBDate"]) ||
		cwCheckInvalidString(form.elements["confirmDOBYear"])) {
		errorCount++;
	} 						
	if (errorCount == 0) {
		verifyDOB();
	} else {
		throwPromoFeedback('confirmDOB', 'We are unable to verify the information you provided. Please try again.');	
	}
}

/* Form validation - Security answer */
function verifySecurityAnswerValidation(form) {
	var errorCount = 0;	
	if (cwCheckInvalidString(form.elements["answer"])) {
		errorCount++;
	} 						
	if (errorCount == 0) {
		verifySecurityAnswer();
	} else {
		throwPromoFeedback('forgotPassQuestion', 'This field is required.');	
	}
}

/* Form validation - Reset password */
function newPasswordValidation(form) {
	if (!isValidPassword(form.elements["pw"].value)){
		throwPromoFeedback('newPassword', invalidPasswordMsg);			
	} else if (cwCheckInvalidString(form.elements["pw"]) || cwCheckInvalidString(form.elements["pw2"])) {
		throwPromoFeedback('newPassword', 'These fields are required.');
	} else if (form.elements["pw"].value != form.elements["pw2"].value) {
		throwPromoFeedback('newPassword', 'Passwords do not match. Please try again.');			
	} else {
		resetPassword();
	}
}

/* Form validation - Promo code */
function validatePromoCodeValidation(form) {
	clearPromoFeedback('promoFeedback');
	clearPromoFeedback('promoFeedback2');
	clearPromoFeedback('promoLongDesc');	var errorCount = 0;	
	if (cwCheckInvalidString(form.elements["promoCode"])) {
		errorCount++;
	} 						
	if (errorCount == 0) {
		validatePromoCode();
	} else {
		throwPromoFeedback('promoFeedback2', 'Please enter a promo code.');
	}
}

/* Render yui panel for add cc form (sign up) */
/* DEPRECIATED 02/09 */
function provideBillingNow() {

	//Add Omniture tag
	var s = s_gi(s_account);
	s.templtv=s.linkTrackVars;
	s.templte=s.linkTrackEvents;
	s.linkTrackVars="eVar10,eVar11,events";
	s.linkTrackEvents="event11";
	s.eVar10="Sign Up Billing Information";
	if(customerType == 1){
		s.eVar11="existingClearwire";		
	}
	if(customerType == 2){
		s.eVar11="new customer";
	}
	s.events="event11";				
	s.tl(OmnitureEvent,'o','Sign-Up');
	//End Omniture tag
	
	document.getElementById('closeClearMediaThankYou').href = "javascript:ssoLoginValidation(document.clearMediaLoginForm);";
	YAHOO.CLWRBuyProcess.clearMediaThankYou.hide();
	YAHOO.CLWRBuyProcess.clearMediaThankYou.hideMask();	
	divRender('clearMediaBilling');
	YAHOO.CLWRBuyProcess.clearMediaBilling.show();
	YAHOO.CLWRBuyProcess.clearMediaBilling.center();
	document.getElementById('billingFirstName').focus();
}

/* Render yui panel for thank you w/out adding cc info (sign up) */
/* DEPRECIATED 02/09 */
function provideBillingLater() {

	//Add Omniture tag
	var s = s_gi(s_account);
	s.templtv=s.linkTrackVars;
	s.templte=s.linkTrackEvents;
	s.linkTrackVars='eVar10,eVar11,events';
	s.linkTrackEvents='event11,event9';
	s.eVar10='endSignUpNoBilling';
	if(customerType == 1){s.eVar11='existingClearwire';}
	if(customerType == 2){s.eVar11='new customer';}
	s.events='event9,event11';
	s.tl(OmnitureEvent,'o','Sign-Up');
	if(s.templtv)s.linkTrackVars=s.templtv;
	if(s.templte)s.linkTrackEvents=s.templte;
	//End Omniture tag
	
	document.getElementById('closeClearMediaThankYou').href = "javascript:ssoLoginValidation(document.clearMediaLoginForm);";
	document.getElementById('clearMediaThankYouContent').innerHTML = '<p>Thank you!</p><p>Your account has been set up. An email validation has been sent to you at ' + document.getElementById('cmSignUpEmail').innerHTML + '.  You must validate your email address in order to purchase items from Clear365.</p><p>Add your billing information any time in My Account.</p>';
	if (customerType == 1) {
		document.getElementById('clearMediaThankYouContent').innerHTML += '<p><b>Do you want to link your Clear.net or Clearwire.net Email Now?</b> <a href="javascript: showHide2(\'signupTip3\');"><img src="yui/build/container/assets/info16_1.gif" /></a></p>';
		document.getElementById('clearMediaThankYouFooter').innerHTML = '<div class="clearfix"><a href="javascript:loginRedirect(\'myAccountConnect.htm\'); ssoLoginValidation(document.clearMediaLoginForm);">YES, I WOULD LIKE TO LINK MY EMAIL NOW &gt;</a></div><div class="clearfix"><a href="javascript:ssoLoginValidation(document.clearMediaLoginForm);">NO THANKS, I\'LL LINK MY EMAIL LATER. &gt;</a></div>';
	} else {
		document.getElementById('clearMediaThankYouFooter').innerHTML = "";
	}
	document.getElementById('closeClearMediaThankYou').focus();	
}

/* Render yui panel for thank you after adding cc info (sign up) */
/* DEPRECIATED 02/09 */
function signUpBillingSubmit() {

	//Add Omniture tag End of complete signup process
	var s = s_gi(s_account);
	s.templtv=s.linkTrackVars;
	s.templte=s.linkTrackEvents;
	s.linkTrackVars="eVar10,eVar11";
	s.linkTrackEvents="event11,event9";
	s.eVar10="endSignUpWithBilling";
	if(customerType == 1){s.eVar11="existingClearwire";}
	if(customerType == 2){s.eVar11='new customer';}
	s.events='event9,event11';
	s.tl(OmnitureEvent,'o','Sign-Up');
	if(s.templtv)s.linkTrackVars=s.templtv;
	if(s.templte)s.linkTrackEvents=s.templte;
	//End Omniture tag
	
	document.getElementById('clearMediaThankYouContent').innerHTML = '<p>Thank you!</p><p>Your account has been set up. An email validation has been sent to you at ' + document.getElementById('cmSignUpEmail').innerHTML + '.  You must validate your email address in order to purchase items from Clear365.</p>';
	if (customerType == 1) {
		document.getElementById('clearMediaThankYouContent').innerHTML += '<p><b>Do you want to link your Clear.net or Clearwire.net Email Now?</b> <a href="javascript: showHide2(\'signupTip3\');"><img src="yui/build/container/assets/info16_1.gif" /></a></p>';
		document.getElementById('clearMediaThankYouFooter').innerHTML = '<div class="clearfix"><a href="javascript:loginRedirect(\'myAccountConnect.htm\'); ssoLoginValidation(document.clearMediaLoginForm);">YES, I WOULD LIKE TO LINK MY EMAIL NOW &gt;</a></div><div class="clearfix"><a href="javascript:ssoLoginValidation(document.clearMediaLoginForm);">NO THANKS, I\'LL LINK MY EMAIL LATER. &gt;</a></div>';
	} else {
		document.getElementById('clearMediaThankYouFooter').innerHTML = "";
	}
	/* 10/08/09 - have to destroy billing panel for ie focus fix */
	//YAHOO.CLWRBuyProcess.clearMediaBilling.hide();
	//YAHOO.CLWRBuyProcess.clearMediaBilling.hideMask();	
	document.getElementById('addCCSignUpProcessing').innerHTML = '';
	YAHOO.CLWRBuyProcess.clearMediaBilling.destroy();
	YAHOO.CLWRBuyProcess.clearMediaThankYou.show();
	YAHOO.CLWRBuyProcess.clearMediaThankYou.buildMask();
	document.getElementById('closeClearMediaThankYou').focus();	
}

/* Copy username/password to login form for seamless login after acct creation */
function seamlessClearmediaLogin() {
	divRender('clearMediaLogin');
	document.getElementById('clearMediaLoginForm').j_username.value = document.getElementById('clearMediaSignUp2Form').signUpUserName.value;
	document.getElementById('clearMediaLoginForm').j_password.value = document.getElementById('clearMediaSignUp2Form').signUpPassword.value;
	document.getElementById('cwSignUpPrev').innerHTML = '';
}

/* On failed login attempts for existing clearwire customers, auto load clearwire sign up form */
function seamlessClearwireLogin(un, pw) {
	cwSignUp_render();
	divRender('clearMediaLogin');
	/* auto populate sso login form */
	document.getElementById('clearMediaLoginForm').j_username.value = un;
	document.getElementById('clearMediaLoginForm').j_password.value = pw;	
	divRender('clearMediaCurrentSubscriberLogin');
	/* auto populate existing clearwire customer login form */
	document.getElementById('clearMediaCurrentSubscriberLoginForm').subscriberUsernameText.value = un;
	document.getElementById('clearMediaCurrentSubscriberLoginForm').subscriberPasswordText.value = pw;	
	/* copy username/password to email auto linking form for linking after acct creation */
	document.getElementById('emailAutoLinkForm').j_username.value = un;
	document.getElementById('emailAutoLinkForm').j_password.value = pw;	
	document.getElementById('emailAutoLinkForm').clear365user.value = un;	
	clearwireCustomer();
	divRender('clearWireSignUp2');
	document.getElementById('cwSignUpPrev').innerHTML = '';
}

/* Copy subuser username/password to login for seamless login after subuser acct creation */
function seamlessSubuserLogin(){
	divRender('clearMediaLogin');
	document.getElementById('clearMediaLoginForm').j_username.value = document.getElementById("un").value;
	document.getElementById('clearMediaLoginForm').j_password.value = document.getElementById("pw").value;
	document.forms['clearMediaLoginForm'].submit();
}

/* Replace redirct url in login form */
/* Used for gated pages that are only displayed if customer is logged in (i.e. my account) */
function loginRedirect(url) {
	document.getElementById('clearMediaLoginForm').redirect.value = url;	
}

/* After sign up email auto link attempt, auto load thank you panel */
function emailAutoLinkResult(result,signupEmail,ssoLinkedEmail,providerName,userType,un,pw) {
	thankYou_render();
	divRender('clearMediaLogin');
	/* auto populate sso login form */
	document.getElementById('clearMediaLoginForm').j_username.value = un;
	document.getElementById('clearMediaLoginForm').j_password.value = pw;	
	divRender('clearMediaThankYou');
	document.getElementById('clearMediaThankYouHeader').innerHTML = '<img src="images/box/onlyClearwire.gif" border="0">';
	if (userType == 6) {
		document.getElementById('clearMediaThankYouHeader').innerHTML = '<img src="images/box/onlyClear_logo.gif" border="0">';	
	}
	if (result == 'success') {
		/* Determine linked email */
		linkedEmail = ssoLinkedEmail + '@';
		if (providerName == 'googleclear') {
			linkedEmail += 'clear.net';
		} else {
			linkedEmail += 'clearwire.net';
		}
		
		document.getElementById('clearMediaThankYouContent').innerHTML = '<p>Your account has been set up and your email <b>' + linkedEmail + '</b> is linked to Clear365.  An email has been sent to you at <b>' + signupEmail + '</b>.<br><br><p>Thank you for joining Clear365!</p>';
		document.getElementById('clearMediaThankYouFooter').innerHTML = '<div class="clearfix"><div class="buttons" style="float:right;"><a href="javascript:ssoLoginValidation(document.clearMediaLoginForm);" id="thankYouGetStartedLink" ><img src="images/box/getstart_btn.gif" border="0" tabindex="2"></a></div><div>';			
	} else {
		document.getElementById('emailAutoLinkFailEmailField').innerHTML = signupEmail;
		document.getElementById('emailAutoLinkFailForm').clear365user.value = un;
		document.getElementById('clearMediaThankYouContent').innerHTML = document.getElementById('emailAutoLinkFail').innerHTML;
		if (userType == 1) {
			//document.getElementById('emailAutoLinkFailEmailType').innerHTML = 'Clearwire';
			document.getElementById('clearMediaThankYouFooter').innerHTML = '<div class="buttons" style="height:50px;"><br /><p>&nbsp;Not sure of your Clearwire email address?<br />&nbsp;<a href="https://www.clearwire.com/my_account/signin.php" target="_blank">Click here to set up your Clearwire email.</a></p><br /></div>';	
		} else {
			//document.getElementById('emailAutoLinkFailEmailType').innerHTML = 'Clear';
			document.getElementById('clearMediaThankYouFooter').innerHTML = '<div class="buttons" style="height:50px;"><br /><p>&nbsp;Not sure of your Clear email address?<br />&nbsp;<a href="https://www.clear.com/my_account/signin.php" target="_blank">Click here to set up your Clear email.</a></p><br /></div>';	
		}		
		document.getElementById('errorEmailValidError').innerHTML= 'We were unable to link your email.';
		document.getElementById('errorEmailValidError').style.display = 'block';		
	}
	
	/* Close button on panel will activate auto sso log in */		
	document.getElementById('closeClearMediaThankYou').href = "javascript:ssoLoginValidation(document.clearMediaLoginForm);";
		
	YAHOO.CLWRBuyProcess.clearMediaThankYou.show();	
	/* On success, set auto focus to get started button */
	if (result == 'success') {
		document.getElementById('thankYouGetStartedLink').focus();
	} else {
		document.getElementById('emailAutoLinkFailLink').focus();
	}
}

/* Validate auto email link retry form */
function validateEmailAutoLinkFail(form) {
	var errorCount = 0;
	
	if (cwCheckInvalidString(form.elements["j_username"])) {
		errorCount++;
	} else if (cwCheckInvalidString(form.elements["j_password"])) {
		errorCount++;
	} else if (cwCheckInvalidString(form.elements["provider"])) {
		errorCount++;
	}
	
	if (errorCount == 0) {
		document.getElementById('errorEmailUserError').innerHTML= '';
		document.getElementById('errorEmailUserError').style.display = 'none';		
		document.getElementById('emailAutoLinkFailForm').submit();
	} else {
		document.getElementById('errorEmailUserError').innerHTML= 'These fields are required.';
		document.getElementById('errorEmailUserError').style.display = 'block';		
	}	
}

function closePanel(panelId) {
	eval('YAHOO.CLWRBuyProcess.' + panelId + '.hide()');
}

function forgotPass(whichStep){
	switch(whichStep){
		case 1:	
			YAHOO.CLWRBuyProcess.clearMediaLogin.hide();
			YAHOO.CLWRBuyProcess.clearMediaLogin.hideMask();
			divRender('forgotPass');			
			YAHOO.CLWRBuyProcess.forgotPass.show();
			document.getElementById('forgotPassUser').focus();
		break;
		case 2:
			YAHOO.CLWRBuyProcess.forgotPass.hide();
			divRender('passOptions');			
			YAHOO.CLWRBuyProcess.passOptions.show();			
		break;
		case 3:
			YAHOO.CLWRBuyProcess.passOptions.hide();
			divRender('clearMediaThankYou');
			document.getElementById('clearMediaThankYouContent').innerHTML = '<p>Thank you!</p><p>An email has been sent to your at <a href="#">smith@foo.com</a>. Please click on the link enclose in that email to reset your password.</p>';
			YAHOO.CLWRBuyProcess.clearMediaThankYou.show();
		break;
		case 4:
			YAHOO.CLWRBuyProcess.passOptions.hide();			
			divRender('confirmDOB');
			YAHOO.CLWRBuyProcess.confirmDOB.show();
			document.getElementById('confirmDOBMonth').focus();
		break;
	}
}

