// JavaScript Document 


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
// handler called via onajaxload() when cfwindow with video is loaded
initVideo = function(){myWindow = ColdFusion.Window.getWindowObject('VideoVaultVideo');myWindow.setTitle(ColdFusion.getElementValue('pagetitle'));}

// handler called via onajaxload() when regisrtaion cfwindow is loaded
initRegWindow = function(){var myWindow1 = ColdFusion.Window.getWindowObject('VideoVaultVideo');myWindow1.setTitle('Demo Library Registration');myWindow1.setContentSize(450,450);}

// used by ajaxproxy to set default country displayed in registration_form.cfm
var imdone5 = false;
function setCountry1(x,val) {
//alert(123);
if(!imdone5) {
var dd = document.getElementById('country1');

for(var i = 0; i < dd.length; i++){
if(dd.options[i].value == val){
dd.selectedIndex = i;

}
}
imdone5 = true;
}
}

// method to set cookie.  this is only called whena  form is sucessfully submitted to siebel and with the valude user will have unlimited views of vidoes.
	
function SetCookie(cookieName,cookieValue,nDays,pa) {

 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;

 expire.setTime(today.getTime() + 3600000*24*nDays);

 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString()+";path="+pa;

}

//form submition method with validaion

function doSubmitForm(msg_fname,msg_lname,msg_addr,msg_city,msg_company,msg_phone,msg_email,msg_emailinvalid,msg_siebelphone,msg_title,msg_timeframe,msg_hearabout) {
	
	if (validate_regform(document.registerform,msg_fname,msg_lname,msg_addr,msg_city,msg_company,msg_phone,msg_email,msg_emailinvalid,msg_siebelphone,msg_title,msg_timeframe,msg_hearabout))

		{
			document.getElementById("registerform").Register3.style.display='none'; // hide register button
			document.getElementById("registerform").Register4.style.display='none'; // hide cancel button
			
ColdFusion.Ajax.submitForm('registerform','/includes/CFC/videovault/videovault.cfc?method=submitCampaignRegistration', resultRegHandler, editErrorHandler);
		}
		
	}

// call back handler for method=submitCampaignRegistration

function resultRegHandler(objResultRegHandler) {
	//alert(objResultRegHandler);
		
		//var myDataBody =  objResultRegHandler;	
		//var myDataTitle =  "Video Vault";
		
		
		var ResponseStructure = ColdFusion.JSON.decode(objResultRegHandler);
		var myDataBody =  ResponseStructure.BODY;	
		var myDataTitle =  ResponseStructure.TITLE;	
		var myDataVH =  ResponseStructure.VH;	
		var myDataVW =  ResponseStructure.VW;	
		SetCookie(ColdFusion.getElementValue('pagecookie'),parseInt(ColdFusion.getElementValue('hitsallowed'))+1,1000,'/');
		myWindow = ColdFusion.Window.getWindowObject('VideoVaultVideo');
		myWindow.setTitle(myDataTitle);
		//alert(ColdFusion.getElementValue('vw'));
		 myWindow.setContentSize(myDataVW,myDataVH);
		myWindow.body.update(myDataBody);
		
		
		
		
	}
	
//	error handler for method=submitCampaignRegistration
function editErrorHandler() {
		document.getElementById("registerform").Register4.style.display='block'; // hide cancel button
		myWindow.body.update("Error processing page. Please try back later");
	}	




//////////////////////////////////////////////
////// form specific validation          /////
////// individual functions are here:    /////
////// /includes/js/form_validation.js   /////
//////////////////////////////////////////////
var gotFocus = '';		
function validate_regform(thisform,ms_fname,ms_lname,ms_addr,ms_city,ms_company,ms_phone,ms_email,ms_emailinvalid,ms_siebelphone,ms_title,ms_timeframe,ms_hearabout) {
	with (thisform)
	{
	var errormsg='';
	var errorflag=false;
	

if (validate_required(FName,errormsg)==false)
 {
 errormsg=errormsg + ms_fname + '\n';
 var errorflag=true;
 if (gotFocus.length == 0)
 gotFocus = 'FName';
}  


  
if (validate_required(LName,errormsg)==false)
 {
 errormsg=errormsg + ms_lname + '\n';
 var errorflag=true;
 if (gotFocus.length == 0)
 gotFocus = 'LName';
} 
if (validate_required(Company,errormsg)==false)
 {
 errormsg=errormsg + ms_company + '\n';
 var errorflag=true;
 if (gotFocus.length == 0)
 gotFocus = 'Company';
} 
if (validate_required(Address,errormsg)==false)
 {
 errormsg=errormsg + ms_addr + '\n';
 var errorflag=true;
 if (gotFocus.length == 0)
 gotFocus = 'Address';
}  
if (validate_required(City,errormsg)==false)
 {
 errormsg=errormsg + ms_city + '\n';
 var errorflag=true;
 if (gotFocus.length == 0)
 gotFocus = 'City';
}  

if ((SingleSelectValue(country1,'USA') == true || SingleSelectValue(country1,'Canada') ==true) && validate_required(zip)==false )
 {
 errormsg=errormsg + 'Zip Code / Postal Code Required for Country  = "USA" or "Canada"\n';
 var errorflag=true;
 if (gotFocus.length == 0)
 gotFocus = 'zip';
} 

if ((SingleSelectValue(country1,'USA') == true || SingleSelectValue(country1,'Canada') ==true) && SingleSelectRequired(state1)==false)
 {
 errormsg=errormsg + 'State / Province Required for Country  = "USA" or "Canada"\n';
 var errorflag=true;
 if (gotFocus.length == 0)
 gotFocus = 'state1';
} 




if (validate_required(Phone,errormsg)==false)
    {
    errormsg=errormsg + ms_phone + '\n';
    var errorflag=true;
    if (gotFocus.length == 0)
    gotFocus = 'Phone';

    } else {
     if (validate_siebelphone(Phone,errormsg)==false)
    {
    errormsg=errormsg + ms_siebelphone+ '\n';
    var errorflag=true;
    if (gotFocus.length == 0)
    gotFocus = 'Phone';
    }
  
  }

if (validate_required(email,errormsg)==false)
    {
    errormsg=errormsg + ms_email + '\n';
    var errorflag=true;
    if (gotFocus.length == 0)
    gotFocus = 'email';

    } else {
     if (validate_email(email,errormsg)==false)
    {
    errormsg=errormsg + ms_emailinvalid+ '\n';
    var errorflag=true;
    if (gotFocus.length == 0)
    gotFocus = 'email';
    }
  
  }

if (SingleSelectRequired(jobTitle)==false)
 {
 errormsg=errormsg + ms_title + '\n';
 var errorflag=true;
 if (gotFocus.length == 0)
 gotFocus = 'jobTitle';
} 
if (SingleSelectRequired(TimeFrame)==false)
 {
 errormsg=errormsg + ms_timeframe + '\n';
 var errorflag=true;
 if (gotFocus.length == 0)
 gotFocus = 'TimeFrame';
} 
if (SingleSelectRequired(HearAbout)==false)
 {
 errormsg=errormsg + ms_hearabout + '\n';
 var errorflag=true;
 if (gotFocus.length == 0)
 gotFocus = 'HearAbout';
} 


if (errorflag==true) {
		eval(gotFocus + ".focus()");
		gotFocus = '';
		{alert(errormsg);return false;}
		} 
		 return true;
		}
			
		}


