// JS for Contact US and Request Info page

// Form Web Service Call
try{
	var xmlhttp;  // for forms

	var TYreq = GetXmlHttpObject();  //For thank you
	
		function sendRequest(frm, file, SubjectOfInterest) {  
		 var rnd982g = Math.random();  
		 var str = "";  
			if (FormSubmitCheck(SubjectOfInterest))
			{
				if(str = getForm(frm)) { 
				YAHOO.RIForm.container.RICUform.setHeader('Please wait...');
				document.getElementById('WrapCU').innerHTML = "<div id=waiter style='text-align: center;'><img src='/img/wait-loader.gif'></div>";
				   //alert('get' + file+'?'+str+'&rnd982g='+rnd982g);
				 TYreq.open('GET', file+'?'+str+'&rnd982g='+rnd982g);  
				 TYreq.onreadystatechange = handleResponse;  
				 TYreq.send(null);  
				}  
				return false;  
			}
			else
			{
				return false; // missing required field(s)
			}  
		}
		}
		catch(e){}
	
		function PreviewRequest(file, SubjectOfInterest, GUID) {  
		 var rnd982g = Math.random();  
		 var str = "";  
				YAHOO.RIForm.container.RICUform.setHeader('Please wait...');
				document.getElementById('WrapCU').innerHTML = "<div id=waiter style='text-align: center;'><img src='/img/wait-loader.gif'></div>";
				   //alert('get' + file+'?PrevView='+str+'&rnd982g='+rnd982g);
				 TYreq.open('GET', file+'?PrevView=Yes&Subject=CSI&CommGUID='+ GUID+'&'+str+'&rnd982g='+rnd982g);  
				 TYreq.onreadystatechange = handleResponse;  
				 TYreq.send(null);  
		}
		  
		function handleResponse() {  
		 if(TYreq.readyState == 4){  
		  var response = TYreq.responseText; 
		  document.getElementById('WrapCU').innerHTML = '';
		  pageTracker._trackPageview('/Home/Forms/ThankYou.htm');
		  // center thank you so they can see it.
		  YAHOO.RIForm.container.RICUform.cfg.setProperty("fixedcenter",true); 
				YAHOO.RIForm.container.RICUform.setHeader('Thank You.');
				    if(document.getElementById('WrapCU') == null){alert('no div')}
				    document.getElementById('WrapCU').innerHTML = TYreq.responseText;
					document.getElementById('WrapCU').style.display='block';
					YAHOO.RIForm.container.RICUform.show();
		 }  
		}  
		  
		function getForm(fobj) {  
		 var str = "";  
		 var ft = "";  
		 var fv = "";  
		 var fn = "";  
		 var els = "";  
		 for(var i = 0;i < fobj.elements.length;i++) {  
		  els = fobj.elements[i];  
		  ft = els.title;  
		  fv = els.value;  
		  fn = els.name;  
		 switch(els.type) {  
		  case "text":  
		  case "hidden":  
		  case "password":  
		  case "textarea":  
		  // is it a required field?  
		 // if(encodeURI(ft) == "required" && encodeURI(fv).length < 1) {  
		 //   alert('\''+fn+'\' is a required field, please complete.');  
		 //   els.focus();  
		 //   return false;  
		 // }  
		  str += fn + "=" + encodeURI(fv) + "&";  
		  break;   
		  
		  case "checkbox":  
		  case "radio":  
		   if(els.checked) str += fn + "=" + encodeURI(fv) + "&";  
		  break;      
		  
		  case "select-one":  
		    str += fn + "=" +  
		    els.options[els.selectedIndex].value + "&";  
		  break;  
		  } // switch  
		 } // for  
		 str = str.substr(0,(str.length - 1));  
		 return str;  
		}  


		function GetXmlHttpObject()
		{
		if (window.XMLHttpRequest)
		  {
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		  return new XMLHttpRequest();
		  }
		if (window.ActiveXObject)
		  {
		  // code for IE6, IE5
		  return new ActiveXObject("Microsoft.XMLHTTP");
		  }
		return null;
		}

		function GetFormHTML(url)
		{
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
		  {
		  alert ("Your browser does not support XMLHTTP!");
		  return;
		  }
		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		}

		function stateChanged()
		{
		if (xmlhttp.readyState==4)
		  {
		  if (xmlhttp.status==200)
		    {
		    //alert('return' + xmlhttp.responseText.substr(xmlhttp.responseText.length - 6500, 6500));
		    //if(document.getElementById('WrapCU') == null){alert('no div')}
		    document.getElementById('WrapCU').innerHTML=xmlhttp.responseText;
		    //YAHOO.RIForm.container.RICUform.setBody(xmlhttp.responseText);
		    //document.getElementById('WrapCU').innerHTML='new text';
		    }
		  else
		    {
		    alert("Problem retrieving XML data:" + xmlhttp.statusText);
		    }
		  }
		}

	
// get value of Contact us radio button
	function get_radio_value()
	{
	if(document.RIForm.radio1 != null) {
		for (var i=0; i < document.RIForm.radio1.length; i++)
		   {
		   if (document.RIForm.radio1[i].checked)
		      {
		      return document.RIForm.radio1[i].value;
		      }
		   }
		}
		else {return 'CU'}
	}
	
	
	
// Create form base on contact us radio button

	function ContactUs(Subject, State, Brand, Region, BrandName, CommCode, CommName, CommGUID, FromWhere){
		var QString, KeepSubject,OmnitureDone;
		fnCallback1();
		KeepSubject = '';
		
		
		//alert('ContactUs');
		
		if(Subject == 'CU')
		{
		KeepSubject = Subject;
		Subject = get_radio_value();}

		QString = '?Subject=' + Subject + '&State=' + State + '&Brand=' + Brand + '&Region=' + Region + '&BrandName=' + BrandName + '&CommCode=' + CommCode + '&CommName=' + CommName + '&CommGUID=' + CommGUID
		QString = QString + '&nocache=' + new Date().getTime() + Math.random()*1234567;
		//alert('ContactUs=  ' + '/pageinclude/RequestInformationWS.asp' + QString);
		
		OmnitureDone=false;

		switch (Subject) 
			{ 
			case 'CSI' : 
				YAHOO.RIForm.container.RICUform.setHeader('HOW CAN WE HELP YOU?');
				GetFormHTML('/pageinclude/RequestInformationWS.asp' + QString)

			break; 

			case 'MTG' : 
				YAHOO.RIForm.container.RICUform.setHeader('HOW CAN WE HELP YOU?');
				GetFormHTML('/pageinclude/RequestInformationWS.asp' + QString)
			break; 

			case 'WS' : 
			if(KeepSubject == 'CU') {
				//var sHomeOwnerSvcURL;
				//sHomeOwnerSvcURL='/Home/Brands/KHV/AboutUs/OCT2009/ADBlock20091026135814.htm';
				//window.location = sHomeOwnerSvcURL
				// Add delay before page transimission for omniture beacon
				CUOmniture(State,Subject,"",FromWhere,CommName,true)
				OmnitureDone=true;
				setTimeout("var sHomeOwnerSvcURL; sHomeOwnerSvcURL='/Home/Brands/KHV/AboutUs/OCT2009/ADBlock20091026135814.htm'; window.location = sHomeOwnerSvcURL",500);
			}
			else{
				OmnitureDone=false;
				YAHOO.RIForm.container.RICUform.setHeader('Homeowner Service<BR>Request for Username and Password');
				GetFormHTML('/pageinclude/RequestInformationWS.asp' + QString)}
			 break; 

			case 'PC' : 
				//window.location = '/Home/Forms/CorporatePhoneDirectory.htm'
				// Add delay before page transimission for omniture beacon
				CUOmniture(State,Subject,"",FromWhere,CommName,true)
				OmnitureDone=true;
				setTimeout("window.location = '/Home/Forms/CorporatePhoneDirectory.htm'",750);
				YAHOO.RIForm.container.RICUform.hide();
			break; 
			
			case 'CAR' : 
				//window.location = '/Home/Careers/CareerOpportunities/CareerOpportunities.htm'
				// Add delay before page transimission for omniture beacon
				CUOmniture(State,Subject,"",FromWhere,CommName,true)
				OmnitureDone=true;
				setTimeout("window.location = '/Home/Careers/CareerOpportunities/CareerOpportunities.htm'",750);
				YAHOO.RIForm.container.RICUform.hide();
			break; 
			
			case 'LFS' : 
				YAHOO.RIForm.container.RICUform.setHeader('HOW CAN WE HELP YOU?');
				GetFormHTML('/pageinclude/RequestInformationWS.asp' + QString)
			break; 

			case 'RTR' : 
				YAHOO.RIForm.container.RICUform.setHeader('HOW CAN WE HELP YOU?');
				GetFormHTML('/pageinclude/RequestInformationWS.asp' + QString)
			break; 

			case 'SCI' : 
				YAHOO.RIForm.container.RICUform.setHeader('HOW CAN WE HELP YOU?');
				GetFormHTML('/pageinclude/RequestInformationWS.asp' + QString)
			break; 

			case 'IRI' : 
				//window.location = '/Home/IR/InformationRequest/InformationRequest2.htm'
				// Add delay before page transimission for omniture beacon
				CUOmniture(State,Subject,"",FromWhere,CommName,true)
				OmnitureDone=true;
				setTimeout("window.location = '/Home/IR/InformationRequest/InformationRequest2.htm'",750);
				YAHOO.RIForm.container.RICUform.hide();
			break; 

			default : 
				Subject = 'CU';
				YAHOO.RIForm.container.RICUform.setHeader('Contact Us');
				GetFormHTML('/pageinclude/RequestInformationWS.asp' + QString)
			} 
		 YAHOO.RIForm.container.RICUform.cfg.setProperty("fixedcenter",false); 
		 YAHOO.RIForm.container.RICUform.show();
		 
		//alert('start  ' + Subject);
		// Call Omniture code to set vals
		//if(Subject == 'CU'){// if you want on submit then put this back this will do on load
		if(!OmnitureDone){
		CUOmniture(State,Subject,"",FromWhere,CommName,false);}

		 

	}



// for left nav	
	function HowCanWeHelp(){
	//alert('how can');
		fnCallback1(); 
		YAHOO.RIForm.container.RICUform.setHeader('HOW CAN WE HELP YOU?');
		GetFormHTML('/pageinclude/RequestInformationWS.asp?Subject=CSI')
		YAHOO.RIForm.container.RICUform.show();}
	
	

// appt and CSI logic
	function ItsaAPPT(){
	document.getElementById('AorBTextA').style.display='block';
	document.getElementById('AorBTextB').style.display='none';
	document.getElementById('AorBTextB1').style.display='block';
	document.getElementById('AorBTextB2').style.display='none';}

	function ItsaQORC(){
	document.getElementById('AorBTextA').style.display='none';
	document.getElementById('AorBTextB').style.display='block';
	document.getElementById('AorBTextB1').style.display='none';
	document.getElementById('AorBTextB2').style.display='block';}
	
 	function loadXMLDoc(url) {
	// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send(null);
			// branch for IE/Windows ActiveX version
			} else if (window.ActiveXObject) {
			isIE = true;
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) 
			{
				req.onreadystatechange = processReqChange;
				req.open("GET", url, true);
				req.send(null);
			}
		}
	}

	// handle onreadystatechange event of req object
	 function processReqChange() 
	{
	    // only if req shows "loaded"
	    if (req.readyState == 4) 
	    {
	        // only if "OK"
	        if (req.status == 200)
	        {
				//Rebuild Region Dropdown using AJAX
				RepopulateMktAreaDropDown(); 
	        } 
	        else 
	        {
				//If for some reason the AJAX call didn't work, use the old method of refreshing (redirecting back to) the page
	            //alert("There was a problem retrieving the XML data:\n"+req.statusText);
				RepopulateMktAreaDropDownByRefresh();
	        }
	    }
	}

	//Repopulates Region Dropdown List by redirecting the user back to the page with new QS variables
	 function RepopulateMktAreaDropDownByRefresh()
	{
			myString = new String(window.location.search)
			splitString = myString.split("&")
			for (var i=0; i< splitString.length; i++) 
			{
				piece = new String(splitString[i])
				if(piece.indexOf("NewArea=") >= 0) {
					splitString[i] = ""}
				if(piece.indexOf("KHOVState=") >= 0) {
					splitString[i] = ""}
				if(piece.indexOf("KHOVCity=") >= 0) {
					splitString[i] = ""}
				//alert("checking " + piece) 
			}
			Qstring = ""
			for (var i=0; i< splitString.length; i++) 
			{
				if (splitString[i].length != 0){
					Qstring = Qstring + splitString[i]
					Qstring = Qstring + "&"}
			}
	}

	//Repopulates Region Dropdown List by using Asynchronous Methods
	function RepopulateMktAreaDropDown()
	{
		var arrRegions;
		var sTmpHTML;
		var tmpOption;
		//Get Regions returned from MapDataService
		arrRegions=req.responseXML.getElementsByTagName('Region');
		//alert(arrRegions);
		//Clear Select Options
		document.getElementById('KhovCity').innerHTML='';
		//Add Default Option
		tmpOption = new Option("Select a Region","Select a County/Area/City");
		document.getElementById('KhovCity').options[0] = tmpOption;
		//Add Regions as Options
		for(i=0; i<arrRegions.length; i++)
		{
			tmpOption = new Option(arrRegions[i].getAttribute('Name'),arrRegions[i].getAttribute('Code'));
			document.getElementById('KhovCity').options[i+1] = tmpOption;
		}
		//Re-enable Select List
		document.getElementById('KhovCity').disabled=false;
	}

	 function FillRegionDropDown(Brand,State,Region,Subject)
	{
		var sTmpURL;
		//alert(Brand);
		//alert(State);
		//alert(Region);
	//Temporarily Disable the Select List
		document.getElementById('KhovCity').disabled=true;
	//In case of any latency provide some notice
		tmpOption = new Option("Loading Regions...","");
		document.getElementById('KhovCity').options[0] = tmpOption;
		sTmpURL='/PageInclude/KhovMapDataService.asp?Query=GetRegionsInState&State='+State+'&Brand='+Brand;
	//Make Ajax call to service
		loadXMLDoc(sTmpURL);
	}

	 function GetStateDropDown()
	{
		return document.all("KhovState").options[document.all("KhovState").selectedIndex].value;
	}

	//function SubmitForm()
	//{alert('test');
	//document.getElementById('WrapCU').style.display='none';
	////YAHOO.RIForm.container.RICUform.setHeader("Thank You.");
	////document.getElementById('WrapCU').innerHTML=TY1;
	//JSThanks();
	////document.RIForm.submit();
	//}
		
	function FormSubmitCheck(SubjectOfInterest)
	{
	var CommunityNamesandIds="";
	var RadioValue="";
	var ErrorEmail1;
	var ErrorEmail2;
	var ErrorP;
	var ErrorE;

	//SubjectOfInterest = document.forms['RIForm'].elements['Subject'].value
	Error = ""
		switch (SubjectOfInterest)
		{
		case  "CSI":
			document.getElementById('ErrorFname').style.display='none';
			document.getElementById('ErrorLname').style.display='none';
			document.getElementById('ErrorEmail').style.display='none';
			document.getElementById('ErrorPhone').style.display='none';
			document.getElementById('ErrorApptDay').style.display='none';
			document.getElementById('ErrorApptTime').style.display='none';
			document.getElementById('ErrorState').innerHTML = '';
			document.getElementById('ErrorState').style.display='none';
			document.getElementById('ErrorRegion').innerHTML = '';
			document.getElementById('ErrorRegion').style.display='none';

			//alert("CSI")
			//State
				ErrorE = CheckForBlankDropDown(document.forms['RIForm'].elements['KhovState'].value,"This field must be entered");
				if(ErrorE.length != 0){
				document.getElementById('ErrorState').innerHTML = ErrorE;
				document.getElementById('ErrorState').style.display='block';
				Error = "All required fields were not entered.";}
			//County
				ErrorE = CheckForBlankDropDown(document.forms['RIForm'].elements['KhovCity'].value,"This field must be entered");
				if(ErrorE.length != 0){
				document.getElementById('ErrorRegion').innerHTML = ErrorE;
				document.getElementById('ErrorRegion').style.display='block';
				Error = "All required fields were not entered.";}
			// First Name
				if(document.forms['RIForm'].elements['FirstName'].value.length == 0)
				{document.getElementById('ErrorFname').style.display='block';
				Error = "All required fields were not entered.";}
			//Last Name
				if(document.forms['RIForm'].elements['LastName'].value.length == 0)
				{document.getElementById('ErrorLname').style.display='block';
				Error = "All required fields were not entered.";}
			//Email
				if(document.forms['RIForm'].elements['EMailAddress'].value.length != 0){
					ErrorE = EmailValidate(document.forms['RIForm'].elements['EMailAddress'].value)
					if(ErrorE.length != 0){
					document.getElementById('ErrorEmail').innerHTML = ErrorE;
					document.getElementById('ErrorEmail').style.display='block';
					Error = "All required fields were not entered.";}}
				else
					{document.getElementById('ErrorEmail').style.display='block';
					Error = "All required fields were not entered.";}
			//Cemail
				//Error = Error + CheckForBlank(document.forms['RIForm'].elements['ConfirmEMailAdddress'].value,"Confirmation EMail Address");
				//ErrorEmail1 = EmailValidate(document.forms['RIForm'].elements['EMailAddress'].value);
				//ErrorEmail2 = EmailCompare(document.forms['RIForm'].elements['EMailAddress'].value,document.forms['RIForm'].elements['ConfirmEMailAdddress'].value);
				//var TEST;
			//Phone
				if(document.forms['RIForm'].elements['PhoneNumber'].value.length != 0){
					ErrorP = PhoneValidate(document.forms['RIForm'].elements['PhoneNumber'].value)
					if(ErrorP.length != 0){
					document.getElementById('ErrorPhone').innerHTML = ErrorP;
					document.getElementById('ErrorPhone').style.display='block';
					Error = "Phone Data Invalid.";}}
				//else
				//	{document.getElementById('ErrorPhone').style.display='block';
				//	Error = "All required fields were not entered.";}
				// Appt Data.
				
				if(document.RIForm.HowRadio != null) {
				for (var i=0; i < document.RIForm.HowRadio.length; i++)
				   {
				   if (document.RIForm.HowRadio[i].checked)
				      {
				      RadioValue = document.RIForm.HowRadio[i].value;
				      }
				   }
				}

				//CheckRadio(document.RIForm.HowRadio, ErrorMessage, RadioValue)
					if (RadioValue == 'APPT'){
					//Appt Day
						if(document.forms['RIForm'].elements['ApptDay'].value.length == 0)
						{document.getElementById('ErrorApptDay').style.display='block';
					Error = "All required fields were not entered.";}
					//Appt Time
					if(document.forms['RIForm'].elements['ApptTimeOfDay'].value.length == 0)
					{document.getElementById('ErrorApptTime').style.display='block';
					Error = "All required fields were not entered.";}
				}
			break;
		case  "WS":
		//alert("WS")
		// First Name
			Error = CheckForBlank(document.forms['RIForm'].elements['FirstName'].value,"First Name");
		//Last Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['LastName'].value,"Last Name");
		//Day Phone
			//if (document.forms['RIForm'].elements['WSPerfContact'].value == "Phone"){
			//Day Phone
			//	Error = Error + CheckForBlank(document.forms['RIForm'].elements['PhoneNumber'].value,"Phone to be reached");
			//}
		//State
			Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['WSState'].value,"Property State");
			document.forms['RIForm'].elements['KhovState'].value = document.forms['RIForm'].elements['WSState'].value
		//City
		if(document.forms['RIForm'].elements['WSState'].value == "TX"){
			Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['WSCityS'].value,"Property City");
			document.forms['RIForm'].elements['WSCity'].value = document.forms['RIForm'].elements['WSCityS'].value
			document.forms['RIForm'].elements['KhovCity'].value = document.forms['RIForm'].elements['WSCityS'].value
			}
		//County
		//	Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['KhovCity'].value,"City on top of form");
		//Community Name
		//	Error = Error + CheckForBlank(document.forms['RIForm'].elements['CommunityorSC'].value,"Community Name");
		//Move in month
		//	Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['WSMoveinMonth'].value,"Move in date month");
		//Move in month
		//	Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['WSMoveinYear'].value,"Move in date year");
		//Lot Number
		//	Error = Error + CheckForBlank(document.forms['RIForm'].elements['WSLotNo'].value,"Lot Number");
		//Email
		//	Error = Error + CheckForBlank(document.forms['RIForm'].elements['EMailAddress'].value,"EMail Address");
		//Cemail
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['ConfirmEMailAdddress'].value,"Confirmation EMail Address");
			ErrorEmail1 = EmailValidate(document.forms['RIForm'].elements['EMailAddress'].value);
			ErrorEmail2 = EmailCompare(document.forms['RIForm'].elements['EMailAddress'].value,document.forms['RIForm'].elements['ConfirmEMailAdddress'].value);
		//Phone
		//	if (document.forms['RIForm'].elements['PhoneNumber'].value != "") {
		//		Error = Error + PhoneValidate(document.forms['RIForm'].elements['PhoneNumber'].value)}
		//	if (document.forms['RIForm'].elements['WSAltPhoneNumber'].value != "") {
		//		Error = Error + PhoneValidate(document.forms['RIForm'].elements['WSAltPhoneNumber'].value)}

			break; 
		case  "TI":
		//alert("TI")
		// First Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['FirstName'].value,"First Name");
		//Last Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['LastName'].value,"Last Name");
		//State
			Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['State'].value,"Your address State");
		//County
			Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['City'].value,"Your address City");
		//Email
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['EMailAddress'].value,"EMail Address");
		//Cemail
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['ConfirmEMailAdddress'].value,"Confirmation EMail Address");
			ErrorEmail1 = EmailValidate(document.forms['RIForm'].elements['EMailAddress'].value);
			ErrorEmail2 = EmailCompare(document.forms['RIForm'].elements['EMailAddress'].value,document.forms['RIForm'].elements['ConfirmEMailAdddress'].value)
			//alert("Error is " + Error + ErrorEmail1 + ErrorEmail1)
			break; 
		case  "SCI":
		//alert("SCI")
		// Company Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['CompanyName'].value,"Company Name");
		// First Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['FirstName'].value,"First Name");
		//Last Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['LastName'].value,"Last Name");
		//State
			Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['KhovState'].value,"State on top of form");
		//County
			Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['KhovCity'].value,"City on top of form");
		//Email
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['EMailAddress'].value,"EMail Address");
		//Cemail
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['ConfirmEMailAdddress'].value,"Confirmation EMail Address");
			ErrorEmail1 = EmailValidate(document.forms['RIForm'].elements['EMailAddress'].value);
			ErrorEmail2 = EmailCompare(document.forms['RIForm'].elements['EMailAddress'].value,document.forms['RIForm'].elements['ConfirmEMailAdddress'].value);
		//Phone
			if (document.forms['RIForm'].elements['PhoneNumber'].value != "") {
				Error = Error + PhoneValidate(document.forms['RIForm'].elements['PhoneNumber'].value)}
			break; 
		case  "RTR":
		//alert("SCI")
		// Company Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['CompanyName'].value,"Company Name");
		// First Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['FirstName'].value,"First Name");
		//Last Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['LastName'].value,"Last Name");
		//State
			Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['KhovState'].value,"State on top of form");
		//County
			Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['KhovCity'].value,"City on top of form");
		//Email
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['EMailAddress'].value,"EMail Address");
		//Cemail
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['ConfirmEMailAdddress'].value,"Confirmation EMail Address");
			ErrorEmail1 = EmailValidate(document.forms['RIForm'].elements['EMailAddress'].value);
			ErrorEmail2 = EmailCompare(document.forms['RIForm'].elements['EMailAddress'].value,document.forms['RIForm'].elements['ConfirmEMailAdddress'].value);
		//Phone
			if (document.forms['RIForm'].elements['PhoneNumber'].value != "") {
				Error = Error + PhoneValidate(document.forms['RIForm'].elements['PhoneNumber'].value)}
			break; 
		case  "MTG":
		//alert("MTG")
		// First Name
			Error = CheckForBlank(document.forms['RIForm'].elements['FirstName'].value,"First Name");
		//Last Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['LastName'].value,"Last Name");
		//State
			//Error = Error + CheckForBlankDropDown(RIForm.State.value,"State");
			// clear out unselected data
			//if (document.forms['RIForm'].elements['State'].value == "Select a State") {
			//	document.forms['RIForm'].elements['State'].value = ""}
		//MortState
			Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['MortState'].value,"State where obtaining Mortgage");
		//County
			//Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['City'].value,"City on top of form");
		//Email
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['EMailAddress'].value,"EMail Address");
		//Cemail
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['ConfirmEMailAdddress'].value,"Confirmation EMail Address");
			ErrorEmail1 = EmailValidate(document.forms['RIForm'].elements['EMailAddress'].value);
			ErrorEmail2 = EmailCompare(document.forms['RIForm'].elements['EMailAddress'].value,document.forms['RIForm'].elements['ConfirmEMailAdddress'].value);
		//Phone
			if (document.forms['RIForm'].elements['PhoneNumber'].value != "") {
				Error = Error + PhoneValidate(document.forms['RIForm'].elements['PhoneNumber'].value)}
			break; 
		case  "LFS":
		//alert("LFS")
		//Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['FirstName'].value,"First Name");
		//Name
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['LastName'].value,"Last Name");
		//Day Phone
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['PhoneNumber'].value,"Phone Number");
			if (document.forms['RIForm'].elements['PhoneNumber'].value != "") {
				Error = Error + PhoneValidate(document.forms['RIForm'].elements['PhoneNumber'].value)}
		//Relationship
			//Error = Error + CheckForBlank(RIForm.Relationship.value,"Relationship");
		//State
			Error = Error + CheckForBlankDropDown(document.forms['RIForm'].elements['State'].value," State of property location");
		//County
			//Error = Error + CheckForBlank(RIForm.County.value,"County");
		//TownCity
			//Error = Error + CheckForBlank(RIForm.TownCity.value,"Town/City");
		//Email
			Error = Error + CheckForBlank(document.forms['RIForm'].elements['EMailAddress'].value,"EMail Address");
		//Validate Email
			ErrorEmail1 = EmailValidate(document.forms['RIForm'].elements['EMailAddress'].value);
			ErrorEmail2 = '';
		//owner Phone
			if (document.forms['RIForm'].elements['OPhoneNumber'].value != "") {
				Error = Error + PhoneValidate(document.forms['RIForm'].elements['OPhoneNumber'].value)}
			break; 
		}
		ErrrorString = ""
		if (SubjectOfInterest != 'CSI'){
			if (Error != "")
			{
				ErrrorString = "All mandatory fields have not been entered: " + Error + " is/are missing. "
			}
		
			if (ErrorEmail1 != "")
			{
				ErrrorString = ErrrorString + ErrorEmail1
			}

			if (ErrorEmail2 != "")
			{
			ErrrorString = ErrrorString + ErrorEmail2
			}
			//if (ErrorPhone != "")
			//{
			//ErrrorString = ErrrorString + ErrorPhone
			//}
		}
		else  // CSI uses form higlighted values
		{
			ErrrorString = Error
		}
		if (ErrrorString != "")
		{
			alert(ErrrorString + " Please correct entry(ies) and re-submit")
			return false
		}
		else
		{
			return true

		}
		//alert("here")
		return false	//update comtlist
	}
	function CheckForBlank(Value, Name)
	{
	//alert("Checking for blank" + Name)
		if (Value == "")
		{
		  return Name + ", ";
		}
		else
		{
		  return "";
		}
	}	  
	function CheckForBlankDropDown(Value, Name)
	{
	rexp = /Select a/ 
	if(rexp.test(Value) || Value=="") 
		{
		  return Name + ", ";
		}
		else
		{
		  return "";
		}
	}	  
	function PhoneValidate(Value)
	{
		if(Value != "")
		{
			if (Value.length < 13) {
				if (/((\(\d{3}\) ?)|(\d{3}[- \.]))?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/.test(Value))
				{
				//alert("Pass1");
					return ""
				}
				return "Invalid Phone Number! Expecting (###)###-#### or (###)###-#### x#### Please re-enter."
			}
			else
			{
				if (/^[\\(]{0,1}([0-9]){3}[\\)]{0,1}[ ]?([^0-1]){1}([0-9]){2}[ ]?[-]?[ ]?([0-9]){4}[ ]*((x){0,1}([0-9]){1,5}){0,1}$/.test(Value))
				{
				//alert("Pass2");
					return ""
				}
				return "Invalid Phone Number! Expecting (###)###-#### or (###)###-#### x#### Please re-enter."
			
			}
		}
		else
		{
			return ""
		}
	}
	  
	function EmailValidate(Value)
	{
		if(Value != "")
		{
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Value))
			{
				return ""
			}
			return "Invalid E-mail Address! Please re-enter."
		}
		else
		{
			return ""
		}
	}
		  
	function EmailCompare(Email1, Email2)
	{
	//alert("Checking for blank" + Name)
		if (Email1 == Email2)
		{
		  return "";
		}
		else
		{
		  return "E-Mail and Confirm E-Mail do not match.  ";
		}
	}	  
	function ReplaceAt(value)
	{
		myString = new String(value)
		rExp = /\./gi;
		newString = new String ("\%2E")
		return myString.replace(rExp, newString)
	}
	function CheckRadio(FormObject, ErrorMessage, RadioValue)
	// Check that one of the radio buttons was checed prior to continuing
	{
	for( var i = 0; i < FormObject.length ; i++ ) 
	{
		if (FormObject[i].checked)
			{
				RadioValue = FormObject[i].value
				return ""
			}
	}
	return ErrorMessage
	}
	
