/*
Filename : Landing_script.js
Date of creation : 01/09/09
Created by : Akhilesh
*/


//function for the drop downs
function selectChange(control, controlToPopulate, ItemArray, ItemValues, GroupArray,  GroupLabel) {
    
  var myEle ;
  var x ;
  var tmp_str_newLabel="";
  var tmp_str_oldLabel="";
  
  if(typeof(GroupLabel)!="undefined")
  {	//for drop down with labels		
		var sel = document.LandingForm.frm_str_program;
		while (sel.firstChild)
		{
		sel.removeChild(sel.firstChild);
		}

		  if (control.name == "firstChoice") {
			// Empty the third drop down box of any choices
			for (var q=form.thirdChoice.options.length;q>=0;q--) form.thirdChoice.options[q] = null;
		  }
		  // ADD Default Choice - in case there are no values
		  myEle=document.createElement("option");
		  theText=document.createTextNode("[SELECT]");
		  myEle.appendChild(theText);
		  myEle.setAttribute("value","");
		  controlToPopulate.appendChild(myEle);
		  // Now loop through the array of individual items
		  // Any containing the same child id are added to
		  // the second dropdown box
		  var tmp_int_count=0;
		  var tmp_int_countX=0;
		  
		  for ( x = 0 ; x < ItemArray.length  ; x++ ) {
			
			if (GroupArray[x] == control.value) 
			{
				  //var optGroup = document.createElement('optgroup');
							
				  if(tmp_int_count==0)
				  {
					var optGroup = document.createElement('optgroup');
				  }
				  else if((GroupLabel[x] != tmp_str_oldLabel) && (GroupLabel[x] != null))
				  {
					var optGroup = document.createElement('optgroup');
				  }

				 //alert(ItemArray[x]+"~"+ItemValues[x]);

				  myEle = document.createElement("option") ;
				  myEle.setAttribute("value",ItemArray[x]+"~"+ItemValues[x]);
				  var txt = document.createTextNode(ItemArray[x]);
				  myEle.appendChild(txt);
						  
				  // controlToPopulate.add(myEle) ;
				  if((GroupLabel[x]!=tmp_str_oldLabel) && (GroupLabel[x] != null))
				  {
					optGroup.label = GroupLabel[x];
				  }

				  optGroup.appendChild(myEle);
				  controlToPopulate.appendChild(optGroup);

				  tmp_str_oldLabel=GroupLabel[x];
				  tmp_int_count++;
			  
			}

		 }
  
  }
  else
  { 	  
	  // Empty the second drop down box of any choices
	  for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
	  if (control.name == "firstChoice") {
		// Empty the third drop down box of any choices
		for (var q=form.thirdChoice.options.length;q>=0;q--) form.thirdChoice.options[q] = null;
	  }
	  // ADD Default Choice - in case there are no values
	  myEle=document.createElement("option");
	  theText=document.createTextNode("[SELECT]");
	  myEle.appendChild(theText);
	  myEle.setAttribute("value","");
	  controlToPopulate.appendChild(myEle);
	  // Now loop through the array of individual items
	  // Any containing the same child id are added to
	  // the second dropdown box
	  for ( x = 0 ; x < ItemArray.length  ; x++ ) {
		if ( GroupArray[x] == control.value ) {
		  myEle = document.createElement("option") ;
		  //myEle.value = x ;
		  myEle.setAttribute("value",ItemArray[x]+"~"+ItemValues[x]);
		  // myEle.text = ItemArray[x] ;
		  var txt = document.createTextNode(ItemArray[x]);
		  myEle.appendChild(txt)
		  // controlToPopulate.add(myEle) ;
		  controlToPopulate.appendChild(myEle)
		}
	  }
  }
}

//function for opening the window on click 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/**************function for tool-tip*****************************/

/***********************************************
* Fixed ToolTip script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
		
var tipwidth='150px' //default tooltip width
var tipbgcolor='lightyellow'  //tooltip bgcolor
var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="0px" //horizontal offset of tooltip from anchor link
var horizontal_offset="-3px" //horizontal offset of tooltip from anchor link

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="fixedtipdiv" style="visibility:hidden;width:'+tipwidth+';background-color:'+tipbgcolor+'" ></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, tipwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
}
return edgeoffset
}

function fixedtooltip(menucontents, obj, e, tipwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidetip()
dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
dropmenuobj.innerHTML=menucontents

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
}

function hidetip(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidetip(){
if (ie4||ns6)
delayhide=setTimeout("hidetip()",disappeardelay)
}

function clearhidetip(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

/**************function for tool-tip*****************************/

//function to move cursors on tab press
function move(currentField,nextField) 
{
	if(currentField.value.length >= currentField.maxLength)
	{
		eval('document.LandingForm.'+nextField+'.focus();');
	}
}

//function to validate the landing forms
function validateForm(age)
{
	var tmp_alert = '';
	

	if(document.LandingForm.frm_str_program)
	{
	   if(document.LandingForm.frm_str_program.value == '')
	   {tmp_alert = "Please select Program " + "\n";}
	}
	
	
	if(document.LandingForm.frm_str_fname)
	{
	   if(document.LandingForm.frm_str_fname.value == '')
	   {tmp_alert = tmp_alert + "Please enter First Name" + "\n";}
	}
	
    if(document.LandingForm.frm_str_lname)
	{
	    if(document.LandingForm.frm_str_lname.value == '')
	    {tmp_alert = tmp_alert + "Please enter Last Name" + "\n";}
	}
	

	if(document.LandingForm.frm_str_dphone1)
	{
	   if(document.LandingForm.frm_str_dphone1.value == '' || document.LandingForm.frm_str_dphone2.value == '' ||      document.LandingForm.frm_str_dphone3.value == '' )
	   {tmp_alert = tmp_alert + "Please enter Day Phone" + "\n";}
	   
	   if(document.LandingForm.frm_str_dphone1.value != '' && document.LandingForm.frm_str_dphone2.value != '' &&      document.LandingForm.frm_str_dphone3.value != '' )
		{ 
			var checkOK = "0123456789";
			var val1 = document.LandingForm.frm_str_dphone1.value;
			var val2 = document.LandingForm.frm_str_dphone2.value;
			var val3 = document.LandingForm.frm_str_dphone3.value;

			var IsFound1 = /^-?\d+$/.test(val1);
			var IsFound2 = /^-?\d+$/.test(val2);
			var IsFound3 = /^-?\d+$/.test(val3);
			
			if(!IsFound1 || !IsFound2 || !IsFound3)
			{
				tmp_alert = tmp_alert + "Please enter Valid Day Phone Number" + "\n";
			}
			else
			{
				 document.LandingForm.frm_str_dphone.value = val1+"-"+val2+"-"+val3;
			}

		}
	
	}
	
	
	
	
	
    if(document.LandingForm.frm_str_ephone1)
	{
	  if((document.LandingForm.frm_str_ephone1.value != "" ) || (document.LandingForm.frm_str_ephone2.value != "") ||
	(document.LandingForm.frm_str_ephone3.value != "") )
		{
			
			var checkOK = "0123456789";
			var val_1 = document.LandingForm.frm_str_ephone1.value;
			var val_2 = document.LandingForm.frm_str_ephone2.value;
			var val_3 = document.LandingForm.frm_str_ephone3.value;

			var IsFound_1 = /^-?\d+$/.test(val_1);
			var IsFound_2 = /^-?\d+$/.test(val_2);
			var IsFound_3 = /^-?\d+$/.test(val_3);
			
			if(!IsFound_1 || !IsFound_2 || !IsFound_3)
			{
				tmp_alert = tmp_alert + "Please enter Valid Secondary Phone Number" + "\n";
			}
			else
			{
				 document.LandingForm.frm_str_ephone.value = val_1+"-"+val_2+"-"+val_3;
			}
		} 
	}
	
	
	if(document.LandingForm.frm_str_email)
	{
	   if(document.LandingForm.frm_str_email.value == '')
	   {tmp_alert = tmp_alert + "Please enter Email" + "\n";}
	   
	   if(document.LandingForm.frm_str_email.value != '')
		{
			var email_field = document.LandingForm.frm_str_email.value;
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if(reg.test(email_field) == false) 
			{
				tmp_alert = tmp_alert + "Please enter Valid Email" + "\n";
			}

		}
	}
	

	if(document.LandingForm.frm_str_street)
	{
	   if(document.LandingForm.frm_str_street.value == '')
	   {tmp_alert = tmp_alert + "Please enter Street" + "\n";}
	}

	
    if(document.LandingForm.selState)
	{
	    if(document.LandingForm.selState.value == '')
	    {tmp_alert = tmp_alert + "Please select State" + "\n";}
	}
	
    if(document.LandingForm.selCity)
	{
	   if(document.LandingForm.selCity.value == '')
	   {tmp_alert = tmp_alert + "Please enter City" + "\n";}

	}
	

	
	if(document.LandingForm.selZip)
	{
	    if(document.LandingForm.selZip.value == '')
	    {tmp_alert = tmp_alert + "Please enter Zip" + "\n";}
	}
	
	
	
	if(document.LandingForm.frm_chk_ageReq)
	{
	   if(document.LandingForm.frm_chk_ageReq.value == '')
	   {tmp_alert = tmp_alert + "Please tell us if you are "+age+" years of age or older" + "\n";}
	}
	
	
	
	if(tmp_alert == '')
	{	   
	   return true;
	}
	else
	{
	   alert(tmp_alert);
	   return false;
	}
}

