
/*****************************************************************
   functions for GCD soft lead capture.
******************************************************************/
function SoftLeadStart(obj){
	//alert('OnFocus fired');
	var s=s_gi(s_account); 
	s.linkTrackVars='events,eVar26';
	s.linkTrackEvents='event14';//Non-Inquiry Form Start event
	s.events="event14"
	s.eVar26="CourseDescription"
	s.tl(obj,'o','VC:Get Course Descriptions form start');
	//alert('sent');
}

/*****************************************************************
   Existing functions for Requesting Course Info.
******************************************************************/

// to get around postback not working with our CMS setup include these handlers with each control that needs
// to communicate asynchronously.

// The method that is called when the RequestCourseInfo control is in it's 'stage1'
function RequestCourseInfoSubmit_Stage1(){
    if(validateStage1() == true){
		jQuery('#imgSendToMe_Stage1').hide();
		jQuery('#imgSendToMe_Stage1').after('<img src="/Image/ajax_load_spinner.gif" alt="Loading" />');
    
        var firstName = getRCIFirstNameElement().value;
        var lastName = getRCILastNameElement().value;
        var userEmail = getRCIEmailElement().value;
        
        var currentTime = new Date()
        var month = currentTime.getMonth() + 1
        var day = currentTime.getDate()
        var year = currentTime.getFullYear()
        var signupDate = year + "/" + month + "/" + day;
        
        var source = document.location.pathname;
        var requestNewsLetter = $("chkRequestCourseInfoNewsLetter").checked;

			//Omniture Tracking
			if (requestNewsLetter){
				var s=s_gi(s_account); s.tl(this,'o','VC:Newsletter Signup form submit');//omni
			}
      	var s=s_gi(s_account); 
      	s.linkTrackVars='events,eVar26';
      	s.linkTrackEvents='event15';//Soft lead capture
      	s.events="event15"
      	s.eVar26="CourseDescription"
			s.tl(this,'o','VC:Get Course Descriptions form submit');//omni


        
        // Instantiate the WebRequest object.
        var wRequest =  new Sys.Net.WebRequest();
        // Set the request Url.  
        wRequest.set_url("/Handler/RequestCourseInfoHandler.ashx"); 
         
        // Set the request verb.
        wRequest.set_httpVerb("POST");
        
        var body = ""; 
        body += "RequestCourseInfoStage=1&";
        body += "firstName=" + firstName + "&";
        body += "lastName=" + lastName + "&";
        body += "userEmail=" + userEmail + "&";
        body += "requestNewsLetter=" + requestNewsLetter + "&";
        body += "source=" + source + "&";
        body += "signupDate=" + signupDate + "&";
        body += "path=" + document.location.pathname + "&";
        
        wRequest.set_body(body);
        wRequest.get_headers()["Content-Length"] = body.length;
        
        // Set the web request completed event handler,
        // for processing return data.
        wRequest.add_completed(OnRequestCourseInfoWebRequestCompleted);
           
        // Execute the request.
        wRequest.invoke();
    }
}

// This the handler for the Web request completed event
// that is used to display return data.
function OnRequestCourseInfoWebRequestCompleted(executor, eventArgs) 
{
    if(executor.get_responseAvailable()) 
    {
        GetStage1Div().style.display = "none";
        GetStage2Div().style.display = "block";
    }
    else
    {
        if (executor.get_timedOut())
            alert("Timed Out");
        else
            if (executor.get_aborted())
                alert("Aborted");
    }
}
    
// do client side validations, if passes validation return true, else return false
function validateStage1()
{
	var noErrors = true;
	
	// first name must have value
	if (getRCIFirstNameElement().value == null || getRCIFirstNameElement().value.length == 0) {
		$("txtFirstNameValidatorMsg").style.display = "block";
		noErrors = false;
	} else {
		$("txtFirstNameValidatorMsg").style.display = "none";
	}
	
	// last name must have value
	if (getRCILastNameElement().value == null || getRCILastNameElement().value.length == 0) {
		$("txtLastNameValidatorMsg").style.display = "block";
		noErrors = false;
	} else {
		$("txtLastNameValidatorMsg").style.display = "none";
	}
	
	// email must have value
	if (getRCIEmailElement().value == null || getRCIEmailElement().value.length == 0) {
		$("txtEmailValidatorMsg").style.display = "block";
		$("txtEmailValidatorMsg_InvalidFormat").style.display = "none";
		noErrors = false;
	} else {
		$("txtEmailValidatorMsg").style.display = "none";
		
		//var reg = new RegExp("\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); // not validating, not sure why
		//var reg = new RegExp("^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$");				// not validating, not sure why
		var reg = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");
		
		// email has value, check format
		if(getRCIEmailElement().value.match(reg)) {
			$("txtEmailValidatorMsg_InvalidFormat").style.display = "none";
			
		} else {
			$("txtEmailValidatorMsg_InvalidFormat").style.display = "block";
			noErrors = false;
		}
	}
	return noErrors;
}