//bcancel is not needed as we are not canceling search
//validate search form here



function validateForm() 
{

/*	RT	:	18055
	Author	:	Gagan
	*/
        if (!isExperienceValid("experienceMin","experienceMax"))             
            {
                    return false;
            }
        if(!checkJobSearch("skill","skillInput"))
                 return false;     

        if(!checkJobSearch("role","roleInput"))
            return false;

        //document.SearchForm.sectorName.value=document.SearchForm.JSHome_industry.value;    
        
        if(!validateMultipleSelectLength("skill","Skill(s)",100))
               return false;


         // Commented for RT 14814
         // Vijay
         // Date  :22/09/2005

        //else if(!CheckSpecialskillChars("skill","Skill(s)"))
        //       return false;

        //else if(!CheckSpecialskillChars("role","Role(s)"))
        //       return false;

         

        if(!validateMultipleSelectLength("role","Role(s)",100))
               return false;
       
                
        if(!validateMaxLength("freeText","Free Text",100))
               return false;
               
        if(!validateMinLength("freeText","Free Text",1))
                       return false;
       
        var obj = document.getElementById("LocationInvalidLocation");
        if(typeof(obj)!="undefined" && obj!=null)
        {
            if(obj.style.display == "inline")
            {
                showErrorMessage("Please enter a valid location to continue");
                var obj1 = document.getElementById("LocationSearchInput");
                if(typeof(obj1)!="undefined" && obj1!=null)
                    obj1.focus();
                 return false;
            }
        }
           return true;
}
    



   function loginJobSeekerRedirect(  )
   {
        if(c())
        {
            document.LoginJSForm.submit();
        }
    }

    function ProcessSubmitVote( )
    {
      if ( document.getElementById("PollAnswer").value != null && 
           document.getElementById("PollAnswer").value != "" )
      {
        document.getElementById( "PollTask" ).value= "Vote";
        document.PollForm.submit();
      }
    }

    function jobsearch( )
    {        

        document.SearchForm.sectorName.value=document.SearchForm.JSHome_industry.value;    
        var sTemp = document.getElementById( "roleInput" ).value;
        sTemp = sTemp.replace( /\s/gi, '' );
        if ( sTemp != "" )
        {
            addItem('role');
         }
         sTemp = document.getElementById( "skillInput" ).value;
         sTemp = sTemp.replace( /\s/gi, '' );
         if ( sTemp != "" )
         {
            addItem('skill')
         }
        
        
    }

//	RT	:	18055
//	Procedure shifted from Main.jsp to JS File


  // RT 14814
  // Author : Vijay 
  // Purpose : To validate the skill and role fields 

 //RT 18386
 // Author : Vijay 
 // Date   : 23/11/2005
 // Purpose :Addition special characters -(hypen),*(asterix) and :(colon) are introduced.
 
  
function checkJobSearch(type,check_id)
{    
       var checkStr;
       var temp;
       var rex=new RegExp();
       rex.compile("[^ A-Za-z0-9.+&\\/)(#}\\\\[{\\]*:-]");
       if (type=="skill")
       {    
        checkStr = document.getElementById(check_id).value;
        temp=checkStr; 
        
        if(temp.indexOf("]")!=-1)
       {
       temp=temp.replace( /\]/g, '#' );
       }
       var result=rex.exec(temp);       
          if(result!=null)
                   {
                showErrorMessage("Skill(s) can not contain special characters" );
                 document.getElementById( check_id ).value="";
                  document.getElementById( check_id ).focus();
                   return false;
              }
        else
        {
        addItem('skill');
        }
        }
    else if(type=="role")
    {  
     checkStr = document.getElementById(check_id).value;
       temp=checkStr;
       if(temp.indexOf("]")!=-1)
       {
        temp=temp.replace( /\]/g, '#' );
        }
       var result=rex.exec(temp);
        if(result!=null)
            {
                showErrorMessage("Role(s) can not contain special characters" );
                document.getElementById( check_id ).value="";
                document.getElementById( check_id ).focus();
return false;
                    }
               else
               {
               addItem('role');
               }
       }
return true;
   } 


    function JCSectorTree_OnSelectSector( sID, sName )
    {
      
      
      document.SearchForm.sectorID.value = sID;
    }
    
    function JS_ClearSectorFields(  )
    { 
      //document.getElementById("JSHome_industry").value="";
      document.getElementById("sector").value="";
      document.getElementById("sectorID").value = "";
    }

 //to show floating div for the skill and role tooltip 
 function showRollTip(msg, e,obj) {
      if ( typeof(RollTip) == "undefined" || !RollTip.ready ) return;
      RollTip.reveal(msg, e,obj);
    }
//to hide floating div for the skill and role tooltip 
    function hideRollTip() {
      if ( typeof(RollTip) == "undefined" || !RollTip.ready ) return;
      RollTip.conceal();
    }

  
  
  function validateLoginForm() 
{
   
    var sVal = "";
    var username="";
  	var password="";
	username=trim(document.getElementById("username").value);
	password=trim(document.getElementById("password").value);
        if(trim(username)=="")
        {
              showErrorMessage("User ID Required");
              return false;
         }
         else if(!checkEmail(username))
         {
         	showErrorMessage("Please enter valid email for User ID");
              return false;
         }
         else if(trim(password)=="")
         {
            showErrorMessage("Password Required");
            return false;
         }
         else if((username != "") && (password != "")  )
        {
          if ( (username.indexOf("'")>=0) || (username=="'") )
            {

				showErrorMessage("Invalid User ID");
				return false;
		
            }
        }
        return true;
   
}


 
function showErrorMessage(sMessage)
{
    var elem = document.getElementById("scripterrordivJS");
    var errortd = document.getElementById("errorJS");

    if(typeof(elem)!="undefined" && elem!=null)
    {
        errortd.innerHTML = sMessage;        
        elem.style.visibility="visible";
     
    }

   return;
}


function registerUser()
{ 
   var jobType = document.getElementsByName("type");
	if(jobType[1].checked)
	{ 
		location.href = "ADRegistration.do";
	}
	else
	{
	    location.href = "JSRegistration.do";
	}
}
function forgotPasswordLink()
{       
	if(event==null)
           return;

	var jobType = document.getElementsByName("type");
	if(jobType[1].checked)
	{ 
		location.href = "JS_ForgotPassword.do?type=AD";
	}
	else
	{
	    location.href = "JS_ForgotPassword.do?type=JS";
	}
}

function changeTableColor()
{
	var jobType = document.getElementsByName("type");
        
	if(jobType[1].checked)
	{ 
		document.getElementById("loginbox").className = "loginboxblue";
		document.getElementById("login").className = "buttonblue";
    	document.getElementById("register").className = "buttonblue";
    	document.getElementById("username").className = "fields";
    	document.getElementById("password").className = "fields";
	}
	else
	{
		document.getElementById("loginbox").className = "loginboxorange";
		document.getElementById("login").className = "buttonorange";
    	document.getElementById("register").className = "buttonorange";
    	document.getElementById("username").className = "fieldsjs";
    	document.getElementById("password").className = "fieldsjs";
	    
	}
}
function removeErrorDiv()
{
  var elem = document.getElementById("scripterrordivJS");
   if(typeof(elem)!="undefined" && elem!=null)
   {    
          document.getElementById("errorJS").innerHTML = ""
          elem.style.visibility="hidden";  
   }
}
  
function clearCookie(){                   
        document.getElementById("password").value="";
        document.getElementById("cookie").checked=false;              
  }

