﻿
//init=========================================================================================
window.onload = initCommon;

function initCommon(){
	DynamicForms();	
	CustomValidators();
}
//=============================================================================================

//global variables=============================================================================
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var isMSIE = /*@cc_on!@*/false;

//=============================================================================================

//stop submit by return key====================================================================
function stopRKey(evt) {
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text")) { return false; }
}
document.onkeypress = stopRKey;
//=============================================================================================

//Dynamic Forms================================================================================
function DynamicForms(){
	var inputs = document.getElementsByTagName('input');
	for(i=0; i < inputs.length; i++)
	{
		if(inputs[i].type == 'text')
		{
		    if(inputs[i].className == "req")
		    {
		      inputs[i].className = "text-field-req";  
		    }
		    else
		    {
			    inputs[i].className = "text-field";
			}
			inputs[i].onfocus = textFieldOver;
			inputs[i].onblur = textFieldOut;			
		}
		else if(inputs[i].type == 'button' || inputs[i].type == 'submit')
		{
			inputs[i].className = "btn"; 
			inputs[i].onmouseover = buttonRollOver;
			inputs[i].onmouseout = buttonRollOut			
		}
		else if(inputs[i].type == 'checkbox')
		{
			inputs[i].className="chkBox";
		}
		/*
		else if(inputs[i].type == "radio")
		{
		    if(inputs[i].className == "req"
		    {
		        inputs[i].className = "radio-req"
		    }
		    else
		    {
		        inputs[i].className = "radio"
		    }
		}*/

	}	
	function textFieldOver()
	{   
	    if(this.className != "text-field-req")
	    {
	        this.className = "text-field-over";
	    }
	}
    function textFieldOut()
    {
        if(this.className != "text-field-req"){
        this.className = "text-field";}
    }
	function buttonRollOver(){this.className = "btn-over";}
	function buttonRollOut(){this.className = "btn";}
	
	var txt = document.getElementsByTagName('textarea');
	for(i=0;i < txt.length; i++){
		txt[i].onfocus = textAreaOver;
		txt[i].onblur = textAreaOut;
	} 
	function textAreaOver(){this.className = "textarea-over";}
	function textAreaOut(){this.className = "";}
	
	if(!isMSIE)
	{
		var selects = document.getElementsByTagName('select');
		for(i=0; i < selects.length; i++){
		    if(selects[i].className == "req")
		    {
		        selects[i].className = "select-req";
		    }
			selects[i].onfocus = selectOver;
			selects[i].onblur = selectOut;
		}
	}
    function selectOver()
    {
        if(this.className != "select-req")
        {
            this.className = "select-over";
        }
    }
	function selectOut()
	{
	    if(this.className != "select-req")
        {
	    this.className = "";
	    }
	}	
};
//=============================================================================================

function CustomValidators()
{  

    //State and County------------------------------------------------------------------------

    var txcounties = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_ddlCounty');
    var ddlStates = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_ddlStates');
    ddlStates.onchange = HideShowTxCounties;
    
    //necessary only in the event of a user page refresh
    if(ddlStates.options[ddlStates.selectedIndex].value == "TX")
    {txcounties.style.visibility = "";}
    
    function HideShowTxCounties()
    {
        var obj = this;
        if(obj.options[obj.selectedIndex].value == "TX")
        {txcounties.style.visibility = "";}  
        else{txcounties.style.visibility = "hidden";}   
    }

    //----------------------------------------------------------------------------------------
     
    //rdHearAboutUs Radio Button List---------------------------------------------------------    
    var rdHearAboutUs = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_rdHearAbout');
    rdHearAboutUs.onclick = valHearAboutUs;
    rdHearAboutUs.onblur = valHearAboutUs;
    
    function valHearAboutUs()
    {
        var txtHearAboutText = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtHearAboutText');
        txtHearAboutText.style.width = "300px";
        var lblHearAbout = document.getElementById('lblHearAbout');
        lblHearAbout.style.color = "#FF0000";
        var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdHearAbout;
        
        for(var i=0; i<btn.length; i++)
        {
            if(btn[i].checked && btn[i].value == "Newspaper Ad")
            {
                txtHearAboutText.className = "text-field-req";
                txtHearAboutText.style.visibility = "";
                lblHearAbout.innerHTML = "Which Newspaper Ad? ";
            }
            else if(btn[i].checked && btn[i].value == "Walk-in")
            {
                txtHearAboutText.className = "text-field";
                txtHearAboutText.style.visibility = "hidden";
                lblHearAbout.innerHTML = "";
            }
            else if(btn[i].checked && btn[i].value == "Internet posting")
            {
                txtHearAboutText.className = "text-field";
                txtHearAboutText.style.visibility = "hidden";
                lblHearAbout.innerHTML = "";
            }
            else if(btn[i].checked && btn[i].value == "Current Employee")
            {
                txtHearAboutText.className = "text-field-req";
                txtHearAboutText.style.visibility = "";
                lblHearAbout.innerHTML = "If current employee, who? ";
            }
            else if(btn[i].checked && btn[i].value == "Other")
            {
                txtHearAboutText.className = "text-field-req";
                txtHearAboutText.style.visibility = "";
                lblHearAbout.innerHTML = "Other source? ";
            }
        }    
    }
    //---------------------------------------------------------------------------------------- 
    var rdFelony = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_rdFelony');
    rdFelony.onclick = valFelony;
    
    function valFelony()
    {
        var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdFelony;
        var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtFelonyExplain');
        
        for(var i=0; i<btn.length; i++)
        {
            if(btn[i].checked && btn[i].value == "Yes")
            {
               txt.className = "textarea-req";
            }
            else if(btn[i].checked && btn[i].value == "No")
            {
                txt.className = "";
            }
        }
    }   
    
    var rdEmployedByAgency = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_rdEmployedByAgency');
    rdEmployedByAgency.onclick = valEmployedByAgencyWhen;
    
    function valEmployedByAgencyWhen()
    {
        var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdEmployedByAgency;
        var txtFrom = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtEmployedByAgencyFrom');
        var txtTo = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtEmployedByAgencyTo');
        var txtWhatPosition = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtWhatPosition');
        var txtReasonForLeaving = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtReasonForLeaving');
        for(var i=0; i<btn.length; i++)
        {
            if(btn[i].checked && btn[i].value == "Yes")
            {
               txtFrom.className = "text-field-req";
               txtTo.className = "text-field-req";
               txtWhatPosition.className = "text-field-req";
               txtReasonForLeaving.className = "textarea-req";
            }
            else if(btn[i].checked && btn[i].value == "No")
            {
               txt.className = "text-field";
               txtWhatPosition.className = "text-field";
               txtReasonForLeaving.className = "";
            }            
        } 
    }
    
    var relativesEmployed = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_rdRelativesEmployed');
    relativesEmployed.onclick = valRelativesEmployed;
    
    function valRelativesEmployed()
    {
        var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdRelativesEmployed;
        var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtRelativeNames');

        for(var i=0; i<btn.length; i++)
        {
            if(btn[i].checked && btn[i].value == "Yes")
            {
               txt.className = "textarea-req";
            }
            else if(btn[i].checked && btn[i].value == "No")
            {
               txt.className = "";
            }            
        }           
    }
    
    var rdLicenseRevoked = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_rdLicenseRevoked');
    rdLicenseRevoked.onclick = valLicenseRevoked;
    
    function valLicenseRevoked()
    {
        var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdLicenseRevoked;
        var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtLicExplain');
        
        for(var i=0; i<btn.length; i++)
        {
            if(btn[i].checked && btn[i].value == "Yes")
            {
               txt.className = "textarea-req";
               txt.style.borderColor = "#FF0000";
            }
            else
            {
                txt.className = "";
            }
        }
    }
    
    var rdFired = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_rdFired');
    rdFired.onclick = valFired;
    
    function valFired()
    {
        var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdFired;
        var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtFiredExplain');
        
        for(var i=0; i<btn.length; i++)
        {
            if(btn[i].checked && btn[i].value == "Yes")
            {
               txt.className = "textarea-req";
            }
            else
            {
                txt.className = "";
            }
        }
    }

};

//asp.net client side custom validators=======================================================

function checkForTexasCounty(source, args)
{  
    var ddlStates = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_ddlStates');
    var ddlCounty = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_ddlCounty');
     
    if(ddlStates.options[ddlStates.selectedIndex].value == "TX" && ddlCounty.options[ddlCounty.selectedIndex].value == "")
    {args.IsValid = false;}
    else
    {args.IsValid = true;}
}

function valHearAboutUs(source, args)
{
    var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdHearAbout;
    var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtHearAboutText');
    
    for(var i=0; i<btn.length; i++)
    {
        if(btn[i].checked && btn[i].value != "Walk-in" && btn[i].checked && btn[i].value != "Internet posting")
        {
           if(txt.value == ""){args.IsValid = false;}
           else{args.IsValid = true;}
        }
    }
}

function valFelony(source, args)
{
    var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdFelony;
    var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtFelonyExplain');
    
    for(var i=0; i<btn.length; i++)
    {
        if(btn[i].checked && btn[i].value == "Yes")
        {
           if(txt.value == ""){args.IsValid = false;}
           else{args.IsValid = true;}
        }
    }
}

function valEmployedByAgencyFrom(source, args)
{
    var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdEmployedByAgency;
    var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtEmployedByAgencyFrom');
    
    for(var i=0; i<btn.length; i++)
    {
        if(btn[i].checked && btn[i].value == "Yes")
        {
           if(txt.value == ""){args.IsValid = false; txt.className="text-field-req";}
           else{args.IsValid = true;}
        }
    } 
}

function valEmployedByAgencyTo(source, args)
{
    var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdEmployedByAgency;
    var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtEmployedByAgencyTo');
    
    for(var i=0; i<btn.length; i++)
    {
        if(btn[i].checked && btn[i].value == "Yes")
        {
           if(txt.value == ""){args.IsValid = false; txt.className="text-field-req";}
           else{args.IsValid = true;}
        }
    } 
}

function valEmployedByAgencyPosition(source, args)
{
    var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdEmployedByAgency;
    var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtWhatPosition');
    
    for(var i=0; i<btn.length; i++)
    {
        if(btn[i].checked && btn[i].value == "Yes")
        {
           if(txt.value == ""){args.IsValid = false;}
           else{args.IsValid = true;}
        }
    } 
}

function valReasonForLeaving(source, args)
{
    var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdEmployedByAgency;
    var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtReasonForLeaving');
    
    for(var i=0; i<btn.length; i++)
    {
        if(btn[i].checked && btn[i].value == "Yes")
        {
           if(txt.value == ""){args.IsValid = false;}
           else{args.IsValid = true;}
        }
    }
}

function valRelativesEmployed(source, args)
{
    var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdRelativesEmployed;
    var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtRelativeNames');
    
    for(var i=0; i<btn.length; i++)
    {
        if(btn[i].checked && btn[i].value == "Yes")
        {
           if(txt.value == ""){args.IsValid = false;}
           else{args.IsValid = true;}
        }
    }
}

function valLicenseExplain(source, args)
{
    var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdLicenseRevoked;
    var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtLicExplain');
    
    for(var i=0; i<btn.length; i++)
    {
        if(btn[i].checked && btn[i].value == "Yes")
        {
           if(txt.value == ""){args.IsValid = false;}
           else{args.IsValid = true;}
        }
    }
}

function valFired(source, args)
{
    var btn = document.forms[0].ctl00$ContentPlaceHolder1$Wizard1$rdFired;
    var txt = document.getElementById('ctl00_ContentPlaceHolder1_Wizard1_txtFiredExplain');
    
    for(var i=0; i<btn.length; i++)
    {
        if(btn[i].checked && btn[i].value == "Yes")
        {
           if(txt.value == ""){args.IsValid = false;}
           else{args.IsValid = true;}
        }
    }
}

//=============================================================================================




