﻿
var Page = {

    // urlencoded original query
    url: null,

    onload : function() { 
        if( this.load ){
            this.load();
        }
        
        
        if ( $('try_ufb') ){
            $('try_ufb').submit();
        }
        
        
    },
    
    
    onunload : function() { 
    if($('page3a')!= null)
        {         
        
//        if(window.event.clientX < 0 || window.event.clientY < 0)
//        {
//            func();
//         }
        }
        if(this.unload){
            this.unload();
        }
    },
    
    unSelect: function( selectId ) { 
        
        var oSelect = $(selectId);
        
        if( oSelect.selectedIndex > 0 ) { 
            oSelect.selectedIndex = 0;
        }
    },
    
    disableSelect: function( id, disable ) {
        if( disable ) {
            this.unSelect( id );
        }
        
        $(id).disabled = disable;
    },
    
     replaceOptions: function( selectId, objList ) {       
        var selectObj = $(selectId);       
        
        var currentValue = $F(selectId);
        //alert( "Current value of [" + selectId + "]: [" + currentValue  + "]");
        
        // remove all current options, except the first one
	    this.removeAllButFirst( selectObj );
        
        var selected = null;
        
        // add new options 
        for( i = 0; i < objList.length; i++ ) {
        
            var obj = objList[i];
            
            var optionElement = document.createElement( "option" );
            optionElement.value = obj.value;
   
            optionElement.appendChild( document.createTextNode( unescape( obj.text ) ) );
                  
            if( currentValue == obj.value ) { 
                optionElement.selected = "true";
                selected = currentValue;
            }     
                  
            selectObj.appendChild( optionElement );
        }   
        
        selectObj.disabled = (objList.length == 0);
        
        return selected;
    },
    
    replaceOptionswithtitle: function( selectId, objList ) {       
        var selectObj = $(selectId);       
        
        var currentValue = $F(selectId);
        //alert( "Current value of [" + selectId + "]: [" + currentValue  + "]");
        
        // remove all current options, except the first one
          this.removeAllButFirst( selectObj );
        
        var selected = null;
        
        // add new options 
        for( i = 0; i < objList.length; i++ ) {
        
            var obj = objList[i];
            
            var optionElement = document.createElement( "option" );
            optionElement.value = obj.value;
            optionElement.title = obj.value;
            optionElement.appendChild( document.createTextNode( unescape( obj.text ) ) );
                  
            if( currentValue == obj.value ) { 
                optionElement.selected = "true";
                selected = currentValue;
            }     
                  
            selectObj.appendChild( optionElement );
        }   
        
        selectObj.disabled = (objList.length == 0);
        
        return selected;
    },

    removeAllButFirst: function( node ) { 
    
        // remove all current child nodes, except the first one
	    while(node.childNodes.length > 1 ){ 
	        var removedNode = node.removeChild( node.lastChild );
	        
	        if (/MSIE/.test(navigator.userAgent)) {
	            removedNode.outerHTML = '';
	        }
	        
	    }
    
    }
    
}

var DomLib = {

    removeChildren : function(/*Element*/ node){
	    //	summary:
	    //		removes all children from node and returns the count of children removed.
	    //		The children nodes are not destroyed. Be sure to call destroyNode on them
	    //		after they are not used anymore.
	    var count = node.childNodes.length;
	    while(node.hasChildNodes()){ 
	        var node = node.firstChild.removeNode(); 
	        node.destroyNode();
	    }
	    return count;
    },
    
    
    removeNode : function(/*Node*/node){
	    // summary:
	    //		if node has a parent, removes node from parent and returns a
	    //		reference to the removed child.
	    //		To prevent IE memory leak, call destroyNode on the returned node when
	    //		it is no longer needed.
	    //	node:
	    //		the node to remove from its parent.

	    if(node && node.parentNode){
		    // return a ref to the removed child
		    return node.parentNode.removeChild(node); //Node
	    }
	}
}

// http://xavisys.com/blog/2007/03/01/using-prototype-javascript-to-get-the-value-of-a-radio-group/
function $RF(el, radioGroup) {
	if($(el).type == 'radio') {
		var el = $(el).form;
		var radioGroup = $(el).name;
	} else if ($(el).tagName.toLowerCase() != 'form') {
		return false;
	}
	
	return $F($(el).getInputs('radio', radioGroup).find(
		function(re) {return re.checked;}
	));
}


var PreSearch = {
    onKeywordsClick: function( input ) {
        if( input.value == 'Start search' ) {
            input.value = '';
        }       
    },
    
    submit: function() { 
     
        var form = $('site_search_form');
        
        var type = $F('site_search_form_type');
        
        var keywords = $F('presearch_keywords');
        
        if( keywords == 'Start search' || keywords == '' ) { 
            $('presearch_keywords').disabled = true;
        }
               
        if( type != '' ) { 
            if(type == 'companylistings')
            { 
            var url="/companylistings/";
             if( keywords != 'Start search' && keywords != '' ) { 
                       url = url + "-/-/-/" +  convertkeyword(keywords);
                }
               window.location.href =url;
            }
            else if(type == 'jobs')
            {
                //Start: Appending 'country' value to URL
                //CR Name: Jobs CR
                //Author: Vibhakar Pathak
                //Date:   25-July-2011
                var url="/jobs/-/" + convertName(splitCountry(readCookie("GeoIP")));
                
                if( keywords != 'Start search' && keywords != '' ) { 
                       url = url + "/" +  convertkeyword(keywords);
                    }
                //End: Appending 'country' value to URL
                //CR Name: Jobs CR
                //Author: Vibhakar Pathak
                //Date:   25-July-2011
                window.location.href =url;
            }
            else
            {
                form.action = '/search.html';
                 form.submit();
            }
        }
        else {
            $('site_search_form_type').disabled = true;
             form.submit();
        }
        
       
    }

}

function convertkeyword(val)
{
//replacing any nonaz09   character
   var test = /[^\*\+0-9a-zA-Z-]/g; 
   var val1 = val.replace(test, "-");
  
  //replacing multiple consecutive occurrence of '-' character
  var t1 = /-+/g;
  val1 = val1.replace(t1, "-")
  
  //removing last occurrence of '-' character
  var the_length=val1.length;
  var last_char=val1.charAt(the_length-1);

  if(last_char == '-')
  {
    val1 = val1.substring(0,the_length-1);
    
  }
  
  if(val1 == ''){  val1 = '-';}
  
  var test11 = /[\+]/g;
  val1 = val1.replace(test11,'%2B');
  return (val1);
}
function convertName(val){

    
   //replacing any nonaz09   character
   var test = /[^0-9a-zA-Z]/g; 
   var val1 = val.replace(test, "-");
  
  //replacing multiple consecutive occurrence of '-' character
  var t1 = /-+/g;
  val1 = val1.replace(t1, "-")
  
  //removing last occurrence of '-' character
  var the_length=val1.length;
  var last_char=val1.charAt(the_length-1);

  if(last_char == '-')
  {
    val1 = val1.substring(0,the_length-1);
    
  }
  
  if(val1 == ''){  val1 = '-';}
  
  return (val1);

}


var DataCache = {}



//start : added by Vibhakar on 14Mar11 for Spell Checker
//start: function for email validation
function emailFormatCheck(objVal,text)
{
   var reg;   
   if(text == "Email")
   {
        reg = /^(([^@.,][^@\s,]*[^@,.\s])|(&quot;[^@]+&quot;)|[^@,.\s])@[^@\s,.][^@\s,]*\.[^@\s,]*[^@,.\]]$/;
   }
   else if (text == "Contact number")
   {
        reg = /^([\-\+\,\;\/0-9]+ ?)*$/;
   }
   else if (text == "Maximum salary" || text == "Minimum salary")
   {
        reg =/^(-\d)?\d*(\.\d+)?$/;
   }
   var address = objVal;
   if(reg.test(address) == false) 
        return text + " is not in valid format." + '<br />';
   else
        return "";
}
//end: function for email validation
//start: function to show 'check'image
function showCheckSign(obj)
{
    
    obj.style.display = "inline";
    obj.src = "/assets/images/icon_check.gif";
    obj.alt = "Valid";
}
//end: function to show 'check'image
//start: function to show 'cross'image
function showCrossSign(obj)
{
    
    obj.style.display = "inline";
    obj.src = "/assets/images/icon_cross.gif";
    obj.alt = "Error";
}
//end: function to show 'cross'image
//start: function to hide image
function hideSign(obj)
{
     
    obj.style.display = "none";  
}
//end: function to hide image
//start: function to show messgae in div
function showhideMsgInDiv(obj,msg)
{    
    if(document.all)
    {
        $(obj).innerText = msg;
    }
    else
    {
        $(obj).textContent = msg;
    } 
}
//end: function to show messgae in div
//start: function to check blacklist words in a string
//also restricting to show 5 blacklist words at a time
function blackListWordCheck(objVal)

{//debugger;

var blwords = "";

var count = 0;

for( var m =0; m < BLW.length; m++) {

var blw = BLW[m];

if(blw.string_value.indexOf('+') == -1)
{
var reg = new RegExp("\\b" + blw.string_value + "\\b", "gi");

var val = objVal.toUpperCase();

if(reg.test(val) == true) 

{ 

if(count < 5) 

{ 

blwords = blwords + blw.string_value + ' ';

count = count + 1;

}

} 
}

} 

if(blwords != "")

return blwords + '<br />';

else

return blwords;

}
//end: function to check blacklist words in a string
//start: function to check minimum length
function min_Check(text,value,length)
{
    var add;
    if(length == 1)
        add = '';
    else
        add = 's';
    if (value.length < length)
        return 'Minimum ' + length + ' character' + add + ' required.';    
    else
        return "";
}
//end: function to check minimum length
//start: function to check maximum length
function max_Check(text,value,length)
{
    if (value.length > length)
        return 'Maximum ' + length + ' characters allowed.';    
    else
        return "";
}
//end: function to check maximum length
//start: function to check minimum/maximum length
function minmaxValidation(text,obj1,minLength,maxLength)
{ 
    var innerHTML = "";
    if(min_Check(text,obj1.value,minLength) != "")
    {
        innerHTML = min_Check(text,obj1.value,minLength) + '<br />';   
          
    }
    else if (max_Check(text,obj1.value,maxLength) != "")
    {
        innerHTML = max_Check(text,obj1.value,maxLength) + '<br />';
       
    }           
     
   return innerHTML;
    
}
//end: function to check minimum/maximum length
//start: function to call check/cross image
function showhideSignByFlag(flag,obj)
{
    if(flag == 1)
        showCheckSign(obj);
    else
        showCrossSign(obj);
}
//end: function to call check/cross image
//start: function to check space entered in a string
function singlespaceCheck(objVal,text)
{//debugger;
    var spaceCount = 0;
    var reg;
    var txtLength = objVal.length;    
    if(text == "Minimum salary" || text == "Maximum salary" || text == "Kilometers" || text == "Asking price" || text == "Password" || text == "Email")// && objVal.charAt(0) != " ")
    {       
        for(var i=0; i<txtLength; i++)
        {
            if(objVal.charAt(i) == " ")
            {
                spaceCount = 1;
                break;
            }
        } 
                
    }
    else if(text == "Contact number" || text == "First name" || text == "Last name")
    {
        for(var i=0; i<txtLength; i++)
        {
            if(objVal.charAt(i) == " " && objVal.charAt(i+1) == " ")
            {
                spaceCount = 2;
                break;
            }
        }              
    }
    else if(text == "Ad")
    {
        reWhiteSpace = new RegExp(/  +/);
         // Check for white space
         if (reWhiteSpace.test(objVal)) {
              spaceCount = 2;                            
         }
//        for(var i=0; i<txtLength; i++)
//        {
//            var val1 = objVal.charAt(i);
//            var val2 = objVal.charAt(i+1);
//            var reg = /[,<.>/?;:'{}|=+-_)(*&^%$#@!`~0-9a-zA-Z]/
//            if(txtLength != 1 && reg.test(val1) == false && reg.test(val2) == false)
//            {
//                spaceCount = 2;
//                break;
//            }
//        } 
//        objVal = objVal + "x";
//        txtLength = txtLength + 1;
//        if(txtLength != 1 && objVal.charAt(txtLength-1) == "x" && objVal.charAt(txtLength-2) == " ")
//        {
//            spaceCount = 2;           
//        }
    }
    if(spaceCount == 0)
        return "";  
    else if(spaceCount == 1)      
        return "No space allowed." + '<br />';
    else if(spaceCount == 2)
        return "Only single space allowed." + '<br />' 
}
//end: function to check space entered in a string
//start: function to numeric check in a string
function numericCheck(objVal,text)
{
   var reg;   
   if(text == "Contact number")
   {
        reg = /^([\s\,\-\+\;\/0-9]+?)*$/;
   } 
   else if(text == "First name" || text == "Last name")
   {
        reg = /^([\sa-zA-Z0-9]+?)*$/;
   } 
   else if(text == "Minimum salary" || text == "Maximum salary" || text == "Kilometers" || text == "Asking price")
   {
        reg = /^([\s\,\.0-9]+?)*$/;
   }
   var address = objVal;
   if(reg.test(address) == false) 
   {
       if(text == "Contact number")
       {
            return "Only numeric  characters allowed." + '<br />';
       } 
       else if(text == "First name" || text == "Last name")
       {
            return "Only alpha numeric's allowed." + '<br />';
       } 
       else if(text == "Minimum salary" || text == "Maximum salary" || text == "Kilometers" || text == "Asking price")
       {
            return "Only numeric characters allowed. Commas or dots, if used, will be removed." + '<br />';
       }
   }    
   else
   {
        return "";   
   }
}
//end: function to numeric check in a string
//start: function to special characters check in a string
function specialcharCheck(objVal,text)
{
   var reg;   
   if(text != "")
   {
        reg = /^[^<>%@$~!#&*(){}]*$/;
   }  
   var address = objVal;
   if(reg.test(address) == false) 
        return "Special characters not allowed." + '<br />';
   else
        return "";   
}
//end: function to special characters check in a string
//start: function to validate text fields
function fieldValidation(fieldId,imgId,divId,labelId,text,minLength,maxLength)
{ //debugger;       
    var flag = 1;   
    var obj1 = $(fieldId);var obj2 = $(imgId);var obj3 = $(divId);    
    
        var obj4 = $(labelId); 
       
    var errHtml = "";
    obj3.innerHTML = errHtml;  
    if(max_Check(text,obj1.value,maxLength) != "" && obj1.value != '')
    {      
        errHtml = errHtml + max_Check(text,obj1.value,maxLength) + '<br />';  
        flag = 0;
    }
    if(min_Check(text,obj1.value,minLength) != "")
    {      
        errHtml = errHtml + min_Check(text,obj1.value,minLength) + '<br />';  
        flag = 0;
    }
    var objVal = obj1.value.substring(0,maxLength);
    if(text == "Email" || text == "Contact number" || text == "Maximum salary" || text == "Minimum salary"  || text == "First name" || text == "Last name" || text == "Kilometers" || text == "Asking price")
    {
        
        if(text == "Email")
        {
            if (emailFormatCheck(objVal,text) != "")
            {
                errHtml = errHtml + emailFormatCheck(objVal,text);  
                flag = 0; 
            }
        }
        else
        {

                if (specialcharCheck(objVal,text) != "")
                {
                    errHtml = errHtml + specialcharCheck(objVal,text);  
                    flag = 0; 
                }
                if(numericCheck(objVal,text) != "")
                {
                    errHtml = errHtml + numericCheck(objVal,text);  
                    flag = 0;
                }
                if (singlespaceCheck(objVal,text) != "")
                {
                    errHtml = errHtml + singlespaceCheck(objVal,text);  
                    flag = 0; 
                }               

        }        
    }
    
    if(text == "Email")
    {
        if(blackListWordCheck(objVal) != "")
        {        
            errHtml = errHtml + 'BlackListed Words:- ' + blackListWordCheck(objVal); 
            flag = 0;       
        }    
    }    
    if(text == "Password" || text == "Email")
    {
        if (singlespaceCheck(objVal,text) != "")
        {
            errHtml = errHtml + singlespaceCheck(objVal,text);  
            flag = 0; 
        }      
    }
    //start: added by Vibhakar on 11May11 for Blacklist CR
    //checking for blacklist words in 'contact number' field
    if(text == "Contact number" || text == "First name" || text == "Last name")
    {
        if(blackListWordNumericCheck(objVal) != "")
        {        
            errHtml = errHtml + 'BlackListed Words:- ' + blackListWordNumericCheck(objVal); 
            flag = 0;       
        }   
    }
    //end: added by Vibhakar on 11May11 for Blacklist CR
    obj3.style.visibility = 'visible';
    obj3.innerHTML = errHtml; 
    if(obj3.innerHTML == '' || obj3.innerHTML == '<BR>')
    {
        obj3.style.visibility = 'hidden';
    }   
    showhideSignByFlag(flag,obj2);
    if(obj1.value == '' && obj4.innerHTML.indexOf("*") == -1)
    {
        obj3.style.visibility = 'visible';
        obj2.style.display = 'none';
        obj3.innerHTML = '';
        obj3.style.visibility = 'hidden';
    }  
    if(text == 'Password' && fieldId != 'pwd')
    {
        fieldComparision('rppw','pw','errPassword','passwordImg','Password','repeat password','equal','rppw');
    }
    else if(text == 'Maximum salary' || text == 'Minimum salary')
    {
        fieldComparision('maximumsalary','minimumsalary','minsalErr','minsalImg','Maximum salary','Minimum salary','greater','maxsal');
    }
}
//end: function to validate text fields
//start: function to compare two text fields
function fieldComparision(tofieldId,fromfieldId,divId,imgId,to,from,operator,chkfor)
{
    var obj1 = $(tofieldId);var obj2 = $(fromfieldId);var obj4 = $(divId);var obj5 = $(imgId);
    var maxLength = 15;//fixed for all comparision
    obj4.style.visibility = 'visible';    
    var innerHtml;var rppwflag = 1;var indexMatch = "";    
    var objVal1 = obj1.value.substring(0,maxLength); 
    var objVal2 = obj2.value.substring(0,maxLength);  
    if(obj1 != null && obj1.value != "")
    {           
          
        if(chkfor == 'pw' || chkfor == 'rppw')
        {
            indexMatch = eualCheck(objVal1,objVal2);
        }  
        else if(chkfor == 'minsal' || chkfor == 'maxsal')
        {
            indexMatch = greaterCheck(objVal1,objVal2);
        } 
        obj4.innerHTML = obj4.innerHTML.replace("Minimum salary cannot be more than Maximum salary<br />","");
        obj4.innerHTML = obj4.innerHTML.replace("Minimum salary cannot be more than Maximum salary<BR />","");
        obj4.innerHTML = obj4.innerHTML.replace("Minimum salary cannot be more than Maximum salary<br>","");
        obj4.innerHTML = obj4.innerHTML.replace("Minimum salary cannot be more than Maximum salary<BR>","");
        obj4.innerHTML = obj4.innerHTML.replace("Password and Repeat Password do not match.<BR>",""); 
        obj4.innerHTML = obj4.innerHTML.replace("Password and Repeat Password do not match.<br>","");
        obj4.innerHTML = obj4.innerHTML.replace("Password and Repeat Password do not match.<br />","");
        obj4.innerHTML = obj4.innerHTML.replace("Password and Repeat Password do not match.<BR />","");
        if(indexMatch == -1) 
        {            
              
            innerHtml = writeInnerHtmlAfterComparision(obj4,to,from,operator);
            obj4.innerHTML = obj4.innerHTML + innerHtml;
            rppwflag = 0;                             
            showhideSignByFlag(rppwflag,obj5);            
        }         
     }
    if(obj4.innerHTML == '')
    {
        rppwflag = 1;                             
        showhideSignByFlag(rppwflag,obj5); 
        if(objVal2 == '')  
            obj5.style.display = "none";  
    } 
    
}
//end: function to compare two text fields
//start: function to check greater value in between two text fields
function greaterCheck(objVal1,objVal2)
{
    if(parseInt(objVal2) > parseInt(objVal1))
        return -1;
    else
        return 0;
}
//end: function to check greater value in between two text fields
//start: function to compare value of two text fields
function eualCheck(objVal1,objVal2)
{
    if(objVal1 != objVal2)
        return -1;
    else
        return  0;    
}
//end: function to compare value of two text fields
//start: function to write message after two text field comparision
function writeInnerHtmlAfterComparision(obj,to,from,operator)
{
    var innerHtml = "";
    if(operator == 'equal')
    {
        innerHtml = 'Password and Repeat Password do not match.' + '<br />';
    }
    else if(operator == 'greater')
    {
        innerHtml = from + ' cannot be more than ' + to + '<br />';
    }
//    obj.innerHTML = obj.innerHTML + innerHtml; 
    return  innerHtml;              
}
//end: function to write message after two text field comparision
//start: function to validate checkbox field
function checkboxfieldValidation(fieldId,imgId,errId,text)
{
    var obj1 = $(fieldId);
    var obj2 = $(imgId);
    var obj3 = $(errId);
    obj3.style.display = 'inline';
    var flag = 1;
    if(obj1.checked == false)
        flag = 0;
    showhideSignByFlag(flag,obj2);
    writeInnerHtml(text,flag,obj3);   
    if(obj3.innerHTML == '' || obj3.innerHTML == '<BR>') 
        obj3.style.display = 'none';
}
//end: function to validate checkbox field
//start: function to validate dropdown field
function dropdownValidation(fieldId,imgId,errId,labelId,text)
{//debugger;
    var obj1 = $(fieldId);var obj2 = $(imgId);var obj3 = $(errId);var obj4 = $(labelId);
    var flag = 1;
    obj2.style.display = 'inline';
    obj3.style.visibility = 'visible';
    if($(fieldId).options[$(fieldId).selectedIndex].text == text && obj4.innerHTML.indexOf("*") != -1)
        flag = 0;    
    showhideSignByFlag(flag,obj2);
    writeddlInnerHtml(text,flag,obj3);  
    if(obj3.innerHTML == '' || obj3.innerHTML == '<BR>') 
        obj3.style.visibility = 'hidden';  
    if($F(fieldId) == '' && obj4.innerHTML.indexOf("*") == -1)
    {
        obj3.style.visibility = 'hidden';
        obj2.style.display = 'none';
    }
}
//end: function to validate dropdown field
//start: function to write message for dropdown field
function writeddlInnerHtml(text,flag,obj)
{    
    if(flag == 0)
            obj.innerHTML = 'Not a valid selection. ' + text;        
    else
            obj.innerHTML = '';    
}
//end: function to write message for dropdown field
//start: function to write message for checkbox field
function writeInnerHtml(text,flag,obj)
{    
    if(text == 'terms' && flag == 0)
            obj.innerHTML = ' Please accept the terms and conditions to continue.';        
    else    
        obj.innerHTML = '';    
}
//end: function to write message for checkbox field
//start: function to validate 'AdTitle' and 'AdText' fields
function onTextTitleOnBlur(fieldId,imgId,divId,labelId,text,minLength,maxLength)
{//debugger;
    var fieldValue;
    if(tinyMCEmode == true)
    {
        fieldValue = Blue.GnHelper.getContent(fieldId); 
        if(fieldValue.indexOf("&amp;") != -1)
        {
        fieldValue = fieldValue.replace(/&amp;/g,"&");
        }
        if(fieldValue.indexOf("&lt;") != -1)
        {
        fieldValue = fieldValue.replace(/&lt;/g,"<");
        }
        if(fieldValue.indexOf("&gt;") != -1)
        {
        fieldValue = fieldValue.replace(/&gt;/g,">");  
        }
    }
    else
    {
        fieldValue = document.getElementById(fieldId).value;
    }
    var flag = 1;   
    var obj1 = $(fieldId);var obj2 = $(imgId);var obj3 = $(divId);var obj4 = $(labelId);         
    var errHtml = "";
    if(obj3.innerHTML == '<BR>' || obj3.innerHTML == '<br>')    
        obj3.innerHTML = '';
    else
        errHtml = obj3.innerHTML;
    if(fieldValue.replace(/\s+$/,"") != '')
    {
        if (isAllNumeric(fieldValue,'onBlur') != "")
        {
            if(errHtml.indexOf("Not allowed to have all characters as numeric.") == -1)
                errHtml = errHtml + isAllNumeric(fieldValue,'onBlur');  
            flag = 0; 
        }
        if(isAllSpecialChar(fieldValue,'onBlur') != "")
        {
            if(errHtml.indexOf("All special characters not allowed.") == -1)
                errHtml = errHtml + isAllSpecialChar(fieldValue,'onBlur');  
            flag = 0;
        }
        if (isAllCaps(fieldValue,'onBlur') != "")
        {
            if(errHtml.indexOf("All capitals not allowed.") == -1)
                errHtml = errHtml + isAllCaps(fieldValue,'onBlur');  
            flag = 0; 
        }    
        if (isMoreSpecialChar(fieldValue,'onBlur',text) != "")
        {
            if(errHtml.indexOf("Reduce number of special characters in use.") == -1)
                errHtml = errHtml + isMoreSpecialChar(fieldValue,'onBlur',text);  
            flag = 0; 
        }  
    }    
    obj3.style.visibility = 'visible';
    obj3.innerHTML = errHtml; 
    if(obj3.innerHTML == '' || obj3.innerHTML == '<BR>')
        obj3.style.visibility = 'hidden';
    else if(obj3.innerHTML != '')  
        flag = 0;
    if(tinyMCEmode == true)
    {
        if(Blue.GnHelper.getBlacklistedWords(fieldId) != "")
        { 
            if(text == "Ad title")
            {
                $('adTitleBLWErr').innerHTML = 'BlackListed Word:- ' + collectionBlackListWords(fieldId); 
            }
            else
            {
                $('adtextBLWErr').innerHTML = 'BlackListed Word:- ' + collectionBlackListWords(fieldId); 
            }
            flag = 0;       
        }
        else
        {
            if(text == "Ad title")
                $('adTitleBLWErr').innerHTML = ''; 
            else
                $('adtextBLWErr').innerHTML = '';    
        }  
    }
    else
    {
        //start: modified by Vibhakar on 11May11 for Blacklist CR
        //blackListWordNumericCheck is used now to check blacklist words in 'Ad title' & 'Ad Text' fields
        if(blackListWordNumericCheck(obj1.value) != "")
        { 
            if(text == "Ad title")
                $('adTitleBLWErr').innerHTML = 'BlackListed Words:- ' + blackListWordNumericCheck(obj1.value); 
            else
                $('adtextBLWErr').innerHTML = 'BlackListed Words:- ' + blackListWordNumericCheck(obj1.value); 
            flag = 0;       
        }
        else
        {
            if(text == "Ad title")
                $('adTitleBLWErr').innerHTML = ''; 
            else
                $('adtextBLWErr').innerHTML = '';    
        }     
        //end: modified by Vibhakar on 11May11 for Blacklist CR
    }
    showhideSignByFlag(flag,obj2);   
//    fieldLengthValidation(fieldId,imgId,divId,labelId,text,minLength,maxLength);  
}
//end: function to validate 'AdTitle' and 'AdText' fields
//start: function to restrict repetition of blacklist words in error message
function collectionBlackListWords(fieldId)
{//debugger;
    var arrBlw = Blue.GnHelper.getBlacklistedWords(fieldId);
    var arrNewBlw = '';   
    var arrSplitBlw = '';
    var arrFiveBlw = '';
    for(var b=0; b<arrBlw.length; b++)
    {
        if(arrNewBlw != '' && arrNewBlw.toUpperCase().indexOf(arrBlw[b].toUpperCase()) == -1)
        {
            arrNewBlw = arrNewBlw + ',' + arrBlw[b];
        }
        else if(arrNewBlw == '')
        {
            arrNewBlw = arrBlw[b];
        }
    }
    arrSplitBlw = arrNewBlw.split(','); 
    if(arrSplitBlw.length == 1)
    {
        arrFiveBlw = arrSplitBlw;
    }
    else
    {
        for(var f=0; f<arrSplitBlw.length; f++)
        {
            if(arrFiveBlw != '' && arrFiveBlw.split(',').length < 5)
            {
                arrFiveBlw = arrFiveBlw + ',' + arrSplitBlw[f];
            }
            else if(arrFiveBlw == '')
            {
                arrFiveBlw = arrSplitBlw[f];
            }
        }
    }
    return arrFiveBlw;
}
//end: function to restrict repetition of blacklist words in error message
//start: function to validate 'AdTitle' and 'AdText' fields
function onTextTitleOnKeyUp(fieldId,imgId,divId,labelId,text,minLength,maxLength)
{//debugger;
    var fieldValue;
    if(tinyMCEmode == true)
    {
        fieldValue = Blue.GnHelper.getContent(fieldId); 
        if(fieldValue.indexOf("&amp;") != -1)
        {
        fieldValue = fieldValue.replace(/&amp;/g,"&");
        }
        if(fieldValue.indexOf("&lt;") != -1)
        {
        fieldValue = fieldValue.replace(/&lt;/g,"<");
        }
        if(fieldValue.indexOf("&gt;") != -1)
        {
        fieldValue = fieldValue.replace(/&gt;/g,">");  
        }  
    }
    else
    {
        fieldValue = document.getElementById(fieldId).value;
    }
    var flag = 1;   
    var obj1 = $(fieldId);var obj2 = $(imgId);var obj3 = $(divId);var obj4 = $(labelId);         
    var errHtml = "";
    obj3.innerHTML = errHtml;
    if(min_Check(text,fieldValue,minLength) != "")
    {      
        errHtml = errHtml + min_Check(text,fieldValue,minLength) + '<br />';  
        flag = 0;
    }
    if(fieldValue != '')
    {       
        if(max_Check(text,fieldValue,maxLength) != "")
        {            
            errHtml = errHtml + max_Check(text,fieldValue,maxLength) + '<br />';  
            flag = 0;
        }
        
        var objVal = fieldValue.substring(0,maxLength);
        if (isFirstSpecialChar(objVal,text) != "")
        {
            errHtml = errHtml + isFirstSpecialChar(objVal,text);  
            flag = 0; 
        } 
        if (isMoreConsecutiveSpecialChar(objVal,text) != "")
        {
            errHtml = errHtml + isMoreConsecutiveSpecialChar(objVal,text);  
            flag = 0; 
        }    
        if (isMoreConsecutiveNumeric(objVal,text) != "")
        {
            errHtml = errHtml + isMoreConsecutiveNumeric(objVal,text);  
            flag = 0; 
        }  
        if (isMoreConsecutiveIdenticalChar(objVal) != "")
        {
            errHtml = errHtml + isMoreConsecutiveIdenticalChar(objVal);  
            flag = 0; 
        } 
        if (isHttpExist(objVal) != "")
        {
            errHtml = errHtml + isHttpExist(objVal);  
            flag = 0; 
        } 
        if (isHtmlMarkUpExist(objVal) != "")
        {
            errHtml = errHtml + isHtmlMarkUpExist(objVal);  
            flag = 0; 
        } 
        if (singlespaceCheck(objVal,'Ad') != "")
        {
            errHtml = errHtml + singlespaceCheck(objVal,'Ad');  
            flag = 0; 
        } 
        
    }    
    obj3.style.visibility = 'visible';
    obj3.innerHTML = errHtml; 
    if(obj3.innerHTML == '' || obj3.innerHTML == '<BR>')
    {
        obj3.style.visibility = 'hidden';
    }   
    showhideSignByFlag(flag,obj2);  
    
}
//end: function to validate 'AdTitle' and 'AdText' fields
//start: function to validate 'AdTitle' and 'AdText' fields for html markup
function isHtmlMarkUpExist(sText)
{ //debugger;
   //var reg = /([\<])([^\>]{1,})*([\>])/i; 
   var newSText; 
   newSText = sText;
//   if(tinyMCEmode == true)
//   {
//   newSText = newSText.replace(/&gt;/g,">");
//   newSText = newSText.replace(/&lt;/g,"<");    
//   }
   var reg = /<\s*\/\s*\w\s*.*?>|<\s*br\s*>/g;
   if(reg.test(newSText) == false) 
        return "";
   else
        return "Usage of HTML markup not allowed." + '<br />';
}
//end: function to validate 'AdTitle' and 'AdText' fields for html markup
//start: function to validate 'AdTitle' and 'AdText' fields for http://
function isHttpExist(sText)
{
    if(sText.indexOf(" http://") != -1 || sText.substring(0,7) == "http://")
        return "Use of http:// not allowed." + '<br />';
    else
        return "";
}
//end: function to validate 'AdTitle' and 'AdText' fields for http://
//start: function to validate 'AdTitle' and 'AdText' fields for more consecutive characters
function isMoreConsecutiveIdenticalChar(sText)
{
    var txtLength = sText.length;   
    var found = 0;
    for(var i=0; i<txtLength; i++)
    {
        if(sText.charAt(i) == sText.charAt(i) && sText.charAt(i+1) == sText.charAt(i) && sText.charAt(i+2) == sText.charAt(i) && sText.charAt(i+3) == sText.charAt(i) && i+4 <= txtLength && isAllNumeric(sText.substring(i, i+4),'onKeyUp') == "" && isAllSpecialChar(sText.substring(i, i+4),'onKeyUp') == "")
        {
            found = 1;
            break;
        }           
    }  
    if(found > 0)
        return "More than 3 identical characters not allowed consecutively." + '<br />';
    else
        return "";
    
}
//end: function to validate 'AdTitle' and 'AdText' fields for more consecutive characters
//start: function to validate 'AdTitle' and 'AdText' fields for first special character
function isFirstSpecialChar(sText,text)
{
    var found = 0;
    if(isAllSpecialChar(sText.charAt(0),'onKeyUp') != "" && sText != '' && text == 'Ad title')    
        found = 1;
    else if(isAllSpecialChar(sText.substring(0,2),'onKeyUp') != "" && sText != '' && text == 'Ad text' && sText.length > 1) 
        found = 1;
    if(found && text == 'Ad title')
        return "First letter should not be a special character." + '<br />';
    else if(found && text == 'Ad text')
        return "Only one special character allowed at beginning." + '<br />';
    else
        return "";
}
//end: function to validate 'AdTitle' and 'AdText' fields for first special character
//start: function to validate 'AdTitle' and 'AdText' fields for more consecutive numerals
function isMoreConsecutiveNumeric(sText,text)
{
    var txtLength = sText.length;   
    var found = 0;
    var chkLength = 0;
    if(text == 'Ad title')
        chkLength = 5;
    else
        chkLength = 15;
    if(txtLength > chkLength)
    {
        for(var i=0; i<txtLength; i++)
        {
            if(isAllNumeric(sText.substring(i, i+chkLength+1),'onKeyUp') != "" && i+chkLength+1 <= txtLength)
            {
                found = 1;  
                break;          
            }
        }  
        if(found)
            return "More than " + chkLength + " numbers not allowed consecutively." + '<br />';
        else
            return "";
    } 
    return "";
}
//end: function to validate 'AdTitle' and 'AdText' fields for more consecutive numerals
//start: function to validate 'AdTitle' and 'AdText' fields for more consecutive special characters
function isMoreConsecutiveSpecialChar(sText,text)
{//debugger;
   var newSText; 
   newSText = sText;
//   if(tinyMCEmode == true)
//   {
//   newSText = newSText.replace(/&amp;/g,"&");
//   newSText = newSText.replace(/&lt;/g,"<");
//   newSText = newSText.replace(/&gt;/g,">");
//   }
    var txtLength = newSText.length;   
    var found = 0;
    var chkLength = 0;
    if(text == 'Ad title')
        chkLength = 3;
    else
        chkLength = 4;
    if(txtLength > chkLength)
    {
        for(var i=0; i<txtLength; i++)
        {
            if(isAllSpecialChar(newSText.substring(i, i+chkLength+1),'onKeyUp') != "" && i+chkLength+1 <= txtLength)
            {
                found = 1;    
                break;        
            }
        }  
        if(found)
            return "Not more than " + chkLength + " special characters consecutively." + '<br />';
        else
            return "";
    } 
    return "";
}
//end: function to validate 'AdTitle' and 'AdText' fields for more consecutive special characters
//start: function to validate 'AdTitle' and 'AdText' fields for all numerals
function isAllNumeric(sText,type)
{
//    var reg = /^[0-9\s]+$/;
//    if(reg.test(sText) == false) 
//        return "";
//    else
//        return "Not allowed to have all characters as numeric." + '<br />';
    var ValidChars;
    if(type == 'onBlur')
        ValidChars = "0123456789. ";
    else 
        ValidChars = "0123456789.";
    var IsNumber=true;
    var Char; 
    for (var i = 0; i < sText.length && IsNumber == true; i++) 
    { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) 
     {
     IsNumber = false;
     break;
     }
    }
    if(IsNumber)
        return "Not allowed to have all characters as numeric." + '<br />';
    else
        return "";  
}
//end: function to validate 'AdTitle' and 'AdText' fields for all numerals
//start: function to validate 'AdTitle' and 'AdText' fields for all special characters
function isAllSpecialChar(sText,type)
{//debugger;
    var newSText; 
   newSText = sText;
//   if(tinyMCEmode == true)
//   {
//   newSText = newSText.replace(/&amp;/g,"&");
//   newSText = newSText.replace(/&lt;/g,"<");
//   newSText = newSText.replace(/&gt;/g,">");
//   }
//   var reg = /^[\^\<\>\%\@\$\~\!\#\&\*\s]+$/;
//    if(reg.test(newSText) == false) 
//        return "";
//    else
//        return "All special characters not allowed." + '<br />';
    var ValidChars;
    if(type == 'onBlur')
    {
        ValidChars = "^<>%@$~!#&* ";
        
    }
    else 
    {
        ValidChars = "^<>%@$~!#&*";
    }
    var IsNumber=true;
    var Char; 
    for (var i = 0; i < newSText.length && IsNumber == true; i++) 
    { 
    Char = newSText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) 
     {
     IsNumber = false;
     break;
     }
    }
    if(IsNumber)
        return "All special characters not allowed." + '<br />';
    else
        return "";   
}
function isAllSpecialCharTemp(sText,type)
{
    var ValidChars;
    if(type == 'onBlur')
        ValidChars = "0123456789^<>%@$~!#&*()-_=+{[]};':,.?/\`| ";
    else 
        ValidChars = "0123456789^<>%@$~!#&*()-_=+{[]};':,.?/\`|";
    var IsNumber=true;
    var Char; 
    for (var i = 0; i < sText.length && IsNumber == true; i++) 
    { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) 
     {
     IsNumber = false;
     break;
     }
    }
    if(IsNumber)
        return "All special characters not allowed." + '<br />';
    else
        return "";   
}
//end: function to validate 'AdTitle' and 'AdText' fields for all special characters
//start: function to validate 'AdTitle' and 'AdText' fields for all characters in capitals
function isAllCaps(sText,type)
{
//    var reg = /^[A-Z\s]+$/;
//    if(reg.test(sText) == false) 
//        return "";
//    else
//        return "All capitals not allowed." + '<br />';

    var ValidChars;
    if(type == 'onBlur')
        ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789^<>%@$~!#&*()-_=+{[]};':,.?/\`| ";
    else 
        ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789^<>%@$~!#&*()-_=+{[]};':,.?/\`|";
    var IsNumber=true;
    var Char; 
    for (var i = 0; i < sText.length && IsNumber == true; i++)   
    { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) 
     {
     IsNumber = false;
     break;
     }
    }
    if(IsNumber && isAllNumeric(sText,type) == "" && isAllSpecialCharTemp(sText,type) == "")
        return "All capitals not allowed." + '<br />';
    else
        return "";
     
}
//end: function to validate 'AdTitle' and 'AdText' fields for all characters in capitals
//start: function to validate 'AdTitle' and 'AdText' fields for more special characters
function isMoreSpecialChar(sText,type,text) 
{//debugger;
    var chars = "";
    var chkLength = 0;
    if(type == 'onBlur')
        chars = "~!@#$%^&* ";
    else 
        chars = "~!@#$%^&*";  
    if(text == 'Ad title')
        chkLength = 2;
    else
        chkLength = 3;
    var txtval = sText;   
      
    if(txtval != "")
    {
        match = 0;
        space = 0;
        txtlength = txtval.length;        
                   
        for (i = 0; i < chars.length; i++) 
        {
            var pos = sText.indexOf(chars.charAt(i));
            while(pos > -1) {                
                pos = sText.indexOf(chars.charAt(i), pos+1);
                match = match +1;
            }

        }
        space = sText.split(' ').length - 1;
        var perMatch = ((match-space) / (txtlength)) * 100;        
        if (perMatch >= 10 && match-space > chkLength) 
        {        
            return "Reduce number of special characters in use." + '<br />';
        } 
        else 
        {
            return "";
        }
    }
}
//end: function to validate 'AdTitle' and 'AdText' fields for more special characters
//start: function to show/hide proceed button after all validation
function showhideProceedBut()
{//debugger;
    var flag = 1;
    if($('pwd').value.length < 4 || $('pwd').value.length > 15 || singlespaceCheck($('pwd').value,'Password') != "")
    {
        flag = 0;
    }
    if(flag == 0)
    {

            $('submitLink').disabled = true;
            $('submitLink').addClassName('disabled');
        
            
    }
    else
    {

            $('submitLink').disabled = false;
            $('submitLink').removeClassName('disabled');
        
            
    }
}
//end: function to show/hide proceed button after all validation
//start: function to restrict enter key in 'AdTitle' and 'AdText' fields
function checkEnterKey(evt,imgId,divId)
{//debugger;
    
    var flag = 1;    
    var k = evt.keyCode || evt.which;
    if(divId == 'formErr' || divId == 'chkErr' || divId == 'radioErr' || divId == 'emailErr' || divId == 'termsErr' || divId == 'specialErr' || divId == 'stylepaErr' || divId == 'stylepapErr' || divId == 'attributeErr')
        return k != 13;
    var obj1 = $(imgId);var obj2 = $(divId);
    if (k == 13) 
    {
        obj2.style.visibility = 'visible';
        if(obj2.innerHTML.indexOf("Enter key not allowed.") == -1)
        {
            obj2.innerHTML = obj2.innerHTML + "Enter key not allowed.";
        }
        flag = 0;        
        showhideSignByFlag(flag,obj1);
        return k != 13;
    }
    else 
    {
        obj2.innerHTML = obj2.innerHTML.replace("Enter key not allowed.",'');
        obj1.style.display = 'none';
        
    }     
         
}
//end: function to restrict enter key in 'AdTitle' and 'AdText' fields
//end : added by Vibhakar on 14Mar11 for Spell Checker
function page2aSubmit()
{//debugger;
    if($('submitLink').disabled)
    {
    
    }
    else
    { 
        $('page2a').submit();
        return false;
    }
}
function page1Submit()
{//debugger;
    if($('submitLink').disabled)
    {
        return false;
    }
    else
    { 
        $('placeAdForm').submit();
        return false;
    }
}

//start: added by Vibhakar on 11May11 for Blacklist CR
//function to check blacklist words using dynfiles
function blackListWordNumericCheck(objVal)
{//debugger;
var blwords = "";
var val = objVal.split(' ');
//looping object value to find blacklist words
    for( var l =0; l < val.length; l++) {
    //looping dynfiles blacklist words collection to match blacklist words in object value
        for( var m =0; m < BLW.length; m++) {
        var blw = BLW[m];
        var reg = blw.string_value;
            if(reg != "" && reg != " ")
            {
                if(reg.toUpperCase() == val[l].toUpperCase()) 
                { 
                blwords = blwords + blw.string_value + ' ';
                }
            } 
        } 
    }
if(blwords != "")
return collectionBlackListNumericWords(blwords) + '<br />';
else
return blwords;
}

//function to show 5 different blacklist words
function collectionBlackListNumericWords(blwords)
{//debugger;
    var arrBlw = blwords.split(' ');
    var arrNewBlw = '';   
    var splitarrNewBlw;
    var arrSplitBlw = '';
    var arrFiveBlw = '';
    var match = '';
    
    //looping all blacklist words
    //using it to find different blacklist words
    for(var b=0; b<arrBlw.length; b++)
    {
    match = 'n';
        if(arrNewBlw != '')
        {
            splitarrNewBlw = arrNewBlw.split(',');
            if(splitarrNewBlw.length > 1)
            {
               for(var c=0; c<splitarrNewBlw.length; c++)
                {
                    if(splitarrNewBlw[c].toUpperCase() == arrBlw[b].toUpperCase())
                    {
                        match = 'y';
                    }  
                }
                if(match == 'n')
                {
                    arrNewBlw = arrNewBlw + ',' + arrBlw[b];
                }
            }
            else
            {
                if(arrNewBlw.toUpperCase() != arrBlw[b].toUpperCase())
                {
                    arrNewBlw = arrNewBlw + ',' + arrBlw[b];
                }
            }
        }
        else if(arrNewBlw == '')
        {
            arrNewBlw = arrBlw[b];
        }
    }
    arrSplitBlw = arrNewBlw.split(','); 
    if(arrSplitBlw.length == 1)
    {
        arrFiveBlw = arrSplitBlw;
    }
    else
    {
        //using it to find 5 different blacklist words
        for(var f=0; f<arrSplitBlw.length-1; f++)
        {
            if(arrFiveBlw != '' && arrFiveBlw.split(',').length < 5)
            {
                arrFiveBlw = arrFiveBlw + ',' + arrSplitBlw[f];
            }
            else if(arrFiveBlw == '')
            {
                arrFiveBlw = arrSplitBlw[f];
            }
        }
    }
    return arrFiveBlw;
}
//end: added by Vibhakar on 11May11 for Blacklist CR

//Start: Adding cookie related functions
//CR Name: Jobs CR
//Author: Vibhakar Pathak
//Date:   25-July-2011

//function to check cookie i.e. it exists or not
//input parameters:
//obj: 'object value' from where function is calling
//action: 'pagename' or 'action name of control'
function isCookieExist(obj,action) {//debugger;

    var cookieName = 'GeoIP';
    var cookieExpiry = 30;
    
    if(readCookie(cookieName) == null)
    {
        //setting cookie default value to 'AE-UAE' 
        //when obj value is null or empty
        if(obj == null || obj == '')
            obj = 'AE-UAE';
        createCookie(cookieName,obj,cookieExpiry);
    }
        
    var countryValue = '';
    if(action == 'onchange' || action == 'search' || action == 'detail')
    {
        if(obj == 'Others')
            countryValue = obj + '-' + obj;
        else
            countryValue = obj + '-' + $(obj).innerHTML;
    }  
    
    if(readCookie(cookieName) != null)
    {        
        if(action == 'onchange' || action == 'search' || action == 'detail')
            createCookie(cookieName,countryValue,cookieExpiry);
        if(action == 'onload' || action == 'detail')
        {
            //setting 'cookie' and 'controls' value
            //if country in URL is differ from cookie value
            //avoiding to reset cookie value on 'Ad detail' page
//            if(action == 'onload' && window.location.pathname.indexOf('doc.html') == -1)
//            {//debugger;
//                var dirtyCheck = false;
//                var splitURL = window.location.pathname.split('/');
//                var countryVal = '';
//                if(splitURL[3] != undefined)
//                {
//                    splitURL = splitURL[3];
//                    if(splitURL == '-')
//                        dirtyCheck = true;
//                    else
//                        countryVal = getCountryWithCode(splitURL);
//                }
//                else
//                    dirtyCheck = true;
//                if(countryVal == '-')
//                        dirtyCheck = true;       
//                if(dirtyCheck == false && countryVal != readCookie(cookieName))
//                    createCookie(cookieName,countryVal,cookieExpiry);
//            }

            setAllCountryvalues(splitCountry(readCookie(cookieName)));
        }        
    }    
}

//getting country with ISO code to crate cookie
//when country in URL is differ from cookie value
//input parameter:
//splitURL: country name
function getCountryWithCode(splitURL)
{//debugger;
    var testCountry = '';
    var testCountryLength = 0;
    var origCountry = '';
    //getting all 'a' tags
    var headerCountry = $('headerCountry').getElementsByTagName("a");
    //looing to get country value with ISO code
    for(var i=0; i < headerCountry.length; i++)
    {
        origCountry = headerCountry[i].innerHTML;
        if(splitURL.indexOf('-') != -1)
        {
            var test = /[\s]/g; 
            var testCountry = origCountry.replace(test, "-");
            testCountryLength = testCountry.length;  
            if(testCountry == splitURL.substring(0,testCountryLength))
                return headerCountry[i].id + '-' + headerCountry[i].innerHTML;          
        }
        else
        {
            testCountry = origCountry;
            if(testCountry == splitURL)
                return headerCountry[i].id + '-' + headerCountry[i].innerHTML; 
        }
        
    }
    //setting default value to 'AE-UAE'
    //if not found any match through above looping
    return '-';
}
//splitting clounty value from sting
//input parameters:
//countryValue: string having country name with ISO code
function splitCountry(countryValue)
{
    countryValue = countryValue.split('-');
    return countryValue = countryValue[1];
}
//creating cookie
//input parameters:
//name: name of cookie
//value: cookie value
//days: days of expiry
function createCookie(name,value,days) {
      //converting expiry days to time unit
      if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
      }
      else var expires = "";
      //adding cookie to browser using 'name', 'value' and 'expiry' time
      document.cookie = name+"="+value+expires+"; path=/";      
}
//reading cookie value
//input parameter:
//name: cookie name
function readCookie(name) {
      var nameEQ = name + "=";
      //getting all cookie from browser
      var ca = document.cookie.split(';');
      //looping all cookies to get desired cookie value
      for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);          
      }
      //returning null if cookie not exist
      return null;
}
//commented: if needed in future, can be used
//function eraseCookie(name) {
//      createCookie(name,"",-1);
//}
//redirecting "Navigation links" on new 'header'
function redirectUrl(action)
{
    var test = /[\s]/g; 
    var origCountry = convertName(splitCountry(readCookie("GeoIP")).replace(test, "-"));
    var url = '';
    if(action == 'home')
        url = '/home/jobs';
    else
        url = '/jobs/-/' + origCountry;
    window.location.href = url;
}
//End: Adding cookie related functions
//CR Name: Jobs CR
//Author: Vibhakar Pathak
//Date:   25-July-2011

function disableEnterKey(e,obj)
{
//debugger;
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
     {
          //return false;
          if(obj == 'index')
            Search.searchCompanylistings();
          else if(obj =='jobsHome')
            HomeSearch.submit();
          else
            Search.searchlistings();
         return false; 
     }
     else
          return true;
}

//Start: show image randomly
//CR Name: Jobs CR
//Author: Vibhakar Pathak
//Date:   23-Aug-2011
function displayRandomImage() {//debugger;
      var cookieName = "randomImageNumber";  //cookie name   
      if(readCookie(cookieName) == null)
      {
        var randomNumber = Math.floor((Math.random() * 3) + 1);// getting random number between 1 to 3
        document.cookie = cookieName+"="+randomNumber+"; path=/"; //creating & setting cookie value     
      }
      $('introimage').src = '/assets/images/newjobs/masthead_ppl' + readCookie(cookieName) + '.png'; //showing image
//      document.getElementById('introimage').style.display = 'block';
      
}
//End: show image randomly
//CR Name: Jobs CR
//Author: Vibhakar Pathak
//Date:   23-Aug-2011

function validateemail()
{
var newstring = document.getElementById('send_to').value.substring(document.getElementById('send_to').value.length-1);
var strto = document.getElementById('send_to').value;

if(newstring == ';')
{
  strto = document.getElementById('send_to').value.substring(0,document.getElementById('send_to').value.length-1);
}
	var count1=strto.split(",").length - 1;
	var count2=strto.split(";").length - 1;
	if((count1 + count2) > 2)
		    alert('Cannot enter more than 3 email address');
	else
	    document.getElementById('s2f_form').submit();
	return false;
}

function removeFromAdList(id)
{//debugger;
       var cookieName = "SHORTLIST_GLF";
       var cookieValue;
       var newCookieValue = '';
        var cookieValueSplit;
       if(readCookie(cookieName) != null)
       {
            cookieValue = readCookie(cookieName);
            cookieValueSplit = cookieValue.split(",");
            for(var i=0;i < cookieValueSplit.length;i++) {
            if(cookieValueSplit[i] != id)
                newCookieValue = cookieValueSplit[i] + ',' + newCookieValue
            }
       }
       createCookie(cookieName,newCookieValue.substring(0,newCookieValue.length-1),null);
       window.location.href = 'personal.html?_a=shortlist_del&amp;id=' + id;
//       alert(newCookieValue.substring(0,newCookieValue.length-1));
//       else
//       {
//            createCookie(cookieName,readCookie(cookieName) + "," + ad_id,null);
//       } 

}

