﻿
/*
 DataSecurity is used to be for the frequent validation to Email , Password, and some others' input values.
 [Begin]
*/

(function(target){

        function getPreDefinedErrorMsg(){
           var _preDefinedErrorMsg = {
                    __1 : "Please enter an email to continue.",//emailAddrEmpty
                    __2: "Please enter a valid email format to continue.",//emailAddrFormat
                    __3:"Passwords do not match, please try again.", //emailAddrBad
                    __4:"Please enter a password to continue..",
                    __5:"Please enter a valid password format to continue.",
                    __6:"Please enter a value to continue.",
                    _1:"success"
                 };
            return _preDefinedErrorMsg;
        
        }
  /*      
        function $(id){
            return document.getElementById(id);
        }*/
        
        function trim(str){
            return str.replace(/(^\s*)|(\s*$)/g, "");  
        }
        
        function clearTextBoxValue(){
           for(var i=0;i<arguments.length;i++)
                arguments[i].value = "";
        }
        
        
       var $$ = function(args){
            return args ? Array.apply(null,args):new Array();
        }
        
  /*      Function.prototype.bind = function(){
          var args = $$(arguments);
          var tempThis = this;
          var obj = args.shift();
            return function(){
                tempThis.apply(obj,args);
            };
        }*/
        
        function dataSecurity(){}// constructor
        
        dataSecurity.prototype = {
            /*
            parameters:
                fnCallBack-- optional,it's a function pointer and will deal with what should be done afterwards when the email address is not valid.
            */
            IsValidEmailFormat : function(obj1,fnCallBack){
                var reg= /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
                if(reg.test(trim(obj1.value)))
                    return true;
                else{
                    if(fnCallBack != null)
                        fnCallBack();
                    else
                        clearTextBoxValue(obj1);
                        
                    return false; 
                }
                    
            },
            IsValidPasswordFormat : function(){
                return true;
            },
            
            IsTheSamePassword : function(obj1,obj2,fnCallBack){
                if(obj1.value!=obj2.value){
                    if(fnCallBack!=null)
                        fnCallBack();
                    else
                        clearTextBoxValue(obj2,obj1);
                    return false;
                  }else
                        return true;
                    
            },
            PasswordConfirmChecked : function(textBox1Id,textBox2Id,isUsingDefaultErrMsg){
                var obj1 = document.getElementById(textBox1Id);
                var obj2 = document.getElementById(textBox2Id);
                
             //   if(!this.IsTheSamePassword(obj1.value ,obj2.value,clearTextBoxValue.bind(null,obj1,obj2)))
             if(!this.IsTheSamePassword(obj1 ,obj2,null))
                      return isUsingDefaultErrMsg == true ? {statusCode:-3,value:getPreDefinedErrorMsg().__3} : -3;
                else
                    return 1;
                    
                
            
            },
               /*
                check whether an email address is validated according to some rules.
               */   
            EmailValidated : function(textBoxId,isUsingDefaultErrMsg){    
                     
                        var objEmailTxtBox = document.getElementById(textBoxId);
                        var emailLen = trim(objEmailTxtBox.value).length;
                        if(emailLen == 0){
                            objEmailTxtBox.focus();
                            return isUsingDefaultErrMsg == true ? {statusCode:-1,value:getPreDefinedErrorMsg().__1} : -1;

                        }
                        if(emailLen>0){
                            if(!this.IsValidEmailFormat(objEmailTxtBox,null/*clearTextBoxValue.bind(null,objEmailTxtBox)*/)){
                                
                                objEmailTxtBox.focus();
                              return isUsingDefaultErrMsg == true ? {statusCode:-2,value:getPreDefinedErrorMsg().__2} : -2;  
                            }
                            else{
                                return 1;
                            }
                        }

                },
            PasswordValidated : function(textBoxId,isUsingDefaultErrMsg){
                var objPwTxtBox = document.getElementById(textBoxId);
                var pwLen = objPwTxtBox.value.length;
                if(pwLen==0){
                    objPwTxtBox.focus();
                    
                    return isUsingDefaultErrMsg == true ? {statusCode:-4,value:getPreDefinedErrorMsg().__4} : -4;
                }
                if(pwLen>0){
                    if(!this.IsValidPasswordFormat()){
                       objPwTxtBox.focus();
                        return isUsingDefaultErrMsg == true ? {statusCode:-5,value:getPreDefinedErrorMsg().__5} : -5;
                    }else
                        return 1;
                }
                    
            },
            
            // just only check whether the textbox value is empty.
            NormalTextBoxValidated : function(textBoxId,isUsingDefaultErrMsg){
               var objPwTxtBox = document.getElementById(textBoxId);
                var pwLen = trim(objPwTxtBox.value).length;
                if(pwLen==0){
                    objPwTxtBox.focus();
                    return isUsingDefaultErrMsg == true ? {statusCode:-6,value:getPreDefinedErrorMsg().__6} : -6;
                }else
                    return true;   
            },

            
                // public method  
            isValidated : function(objIds){ // objIds = {email:{id:"",errorMsg:""},password:{id:"",errorMsg:""}}
                if(objIds == null){
                        alert("please pass the textbox value you want to validate as a Object to this function!");
                        return false;
                    }
                else{
                       for(var pName in objIds){
                            
                       }
                    }
                }  ///////////////////
 
    }
    
    var DataSecurity = new dataSecurity();
    if(typeof target.DataSecurity == "undefined")
        target.DataSecurity = DataSecurity;
    else
        alert("Object 'DataSecurtity'attached unsuccessfully!");
    
})(window);

/*
 DataSecurity is used to be for the frequent validation to Email , Password, and some other input values.
 [End]
*/


//--------------------make the IE be more closely to the DOM event--------
/*function EventCompatibility(){
}
EventCompatibility.prototype = {
    formatEvent:function(oEvent){
           if(document.all){// for IE
             oEvent.charCode=(oEvent.type=="keypress")?oEvent.keyCode:0;
             oEvent.eventPhase=2;
             oEvent.isChar=(oEvent.charCode>0);
             oEvent.pageX=oEvent.clientY+document.documentElement.scrollTop;
             oEvent.pageY=oEvent.clientX+document.documentElement.scrollLeft;
             oEvent.preventDefault=function(){
                                this.returnValue=false;
                    };
        
          if(oEvent.type=="mouseout")
             oEvent.relatedTarget=oEvent.toElement;
          else if(oEvent.type=="mouseover")
             oEvent.relatedTarget=oEvent.fromElement;
        
          oEvent.stopPropagation=function(){
                this.cancelBubble=true;
            };
        
        oEvent.target=oEvent.srcElement;
        oEvent.time=(new Date).getTime();
        
         return oEvent;
        }
       else
         return this.formatEvent.caller.arguments[0];
           
     },
     
     
   getEvent : function(){
     if(window.event)
        return this.formatEvent(window.event);
     else
        return this.getEvent.caller.arguments[0];
    }
    
    
    
  }*/
  
  
  var CrrEventUtility = (function(){

   
    // it returns an object contain attributes which are appName,appFullVersion,appMajorVersion. For example,
                                  // appName="Microsoft Internet Explorer"
                                  // appFullVersion = 7.0 
                                  // appMajorVersion = 7
    
    var browser = (function(){
    
        function _browserDetection(){ 
        var nVer = navigator.appVersion;
        var nAgt = navigator.userAgent;
        var browserName  = navigator.appName;
        var fullVersion  = ''+parseFloat(navigator.appVersion); 
        var majorVersion = parseInt(navigator.appVersion,10);
        var nameOffset,verOffset,ix;
        // In MSIE, the true version is after "MSIE" in userAgent
        if((verOffset=nAgt.indexOf("MSIE"))!=-1) {
            browserName = "Microsoft Internet Explorer";
            fullVersion = nAgt.substring(verOffset+5);
          }
        // In Opera, the true version is after "Opera" 
        else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
            browserName = "Opera";
            fullVersion = nAgt.substring(verOffset+6);
          }
        // In Chrome, the true version is after "Chrome" 
        else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
            browserName = "Chrome";
            fullVersion = nAgt.substring(verOffset+7);
          }
        // In Safari, the true version is after "Safari" 
        else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
            browserName = "Safari";
            fullVersion = nAgt.substring(verOffset+7);
          }
        // In Firefox, the true version is after "Firefox" 
        else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
            browserName = "Firefox";
            fullVersion = nAgt.substring(verOffset+8);
         }
        // In most other browsers, "name/version" is at the end of userAgent 
        else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) {
            browserName = nAgt.substring(nameOffset,verOffset);
            fullVersion = nAgt.substring(verOffset+1);
            if (browserName.toLowerCase()==browserName.toUpperCase()) {
                browserName = navigator.appName;
                }
         }
        // trim the fullVersion string at semicolon/space if present
        if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
        if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);
            majorVersion = parseInt(''+fullVersion,10);
            if (isNaN(majorVersion)) {
            fullVersion  = ''+parseFloat(navigator.appVersion); 
            majorVersion = parseInt(navigator.appVersion,10);
            }
            return {
               appName : browserName,
               appFullVersion : fullVersion,
               appMajorVersion : majorVersion
            }; 
          }
          return  _browserDetection();
         })(); // dectect browser End 
         
         


    var EventUtility = function(){//constructor function
        if(typeof(Function.prototype._addParamsToEventHandler) == "undefined"){
                 Function.prototype._addParamsToEventHandler = function(objParams){ // bind params to the EvnentHandler
                       var objFn = this;
                       var _objParams = objParams;
                        return function(ev){
                            var e = ev||window.event;
                            _objParams["event"] = e;
                            objFn.call(null,_objParams);
                        };
              
                 }  
        }
    }
        
    EventUtility.prototype ={ //--------------------make the IE be more closely to the DOM event--------
             
        addEventHandler : function(oTarget,sEventType,fnHandler,isCapture,objParams,sfnHandlerName){
                var eventHandler = fnHandler._addParamsToEventHandler(objParams);
                 if(browser.appName=="Firefox") // for DOM-compliant browsers
                     oTarget.addEventListener(sEventType,eventHandler,isCapture|false);
                 else if(browser.appName="Microsoft Internet Explorer"){ //for IE
                        oTarget.attachEvent("on"+sEventType,eventHandler);
                     }
                 else
                     oTarget["on"+sEventType]=eventHandler;
                     
                    // store the eventType and eventHandler 
                   if(typeof(oTarget.EventTypes)=="undefined")
                                oTarget.EventTypes=new Array();
                   if(typeof(oTarget.EventTypes[sEventType])=="undefined")
                                oTarget.EventTypes[sEventType] = new Array();
                    oTarget.EventTypes[sEventType][sfnHandlerName] = eventHandler;
                    //-------------------------
                    
                },
         removeEventHandler : function(oTarget,sEventType,fnHandler,isCapture,sfnHandlerName){
                 if(browser.appName=="Firefox")
                       oTarget.removeEventListener(sEventType,oTarget.EventTypes[sEventType][sfnHandlerName],isCapture|false);
                 else if(browser.appName="Microsoft Internet Explorer")
                       oTarget.detachEvent("on"+sEventType,oTarget.EventTypes[sEventType][sfnHandlerName]);// must move the fnHandler, do it later.
                 else
                       oTarget["on"+sEventType]=null;
                },
         adjustEvent : function(e){
             var oEvent = e;
             if(browser.appName=="Firefox"){
               return oEvent;
             }
            else if(browser.appName="Microsoft Internet Explorer"){
             oEvent.charCode=(oEvent.type=="keypress")?oEvent.keyCode:0;
             oEvent.eventPhase=2;
             oEvent.isChar=(oEvent.charCode>0);
             oEvent.pageX=oEvent.clientY+document.documentElement.scrollTop;
             oEvent.pageY=oEvent.clientX+document.documentElement.scrollLeft;
             oEvent.preventDefault=function(){
                this.returnValue=false;
             };
            if(oEvent.type=="mouseout")
                oEvent.relatedTarget=oEvent.toElement; 
            else if(oEvent.type=="mouseover")
                oEvent.relatedTarget=oEvent.fromElement;
        
            oEvent.stopPropagation=function(){
               this.cancelBubble=true;
           };
        
           oEvent.target=oEvent.srcElement;
           oEvent.time=(new Date).getTime();
        
           return oEvent;
            
            }else{}
            
         
         }               
                
                
                
                
    }// prototype End
    
    return new EventUtility();
})();

//--------------------make the IE be more closely to the DOM event (END)----




//------------------------------Element's Dimension [Begin]-------------------------------
// JScript File

var CrrElementDimension = (function(){

    var d = document, w = window;
	var getOffset = function(el){
	  if (document.documentElement["getBoundingClientRect"]){
		var box = el.getBoundingClientRect(),
		doc = el.ownerDocument,
		body = doc.body,
		docElem = doc.documentElement,
		// for ie 
		clientTop = docElem.clientTop || body.clientTop || 0,
		clientLeft = docElem.clientLeft || body.clientLeft || 0,
		
		// In Internet Explorer 7 getBoundingClientRect property is treated as physical,
		// while others are logical. Make all logical, like in IE8.		
		
		zoom = 1;
		
		if (body.getBoundingClientRect) {
			var bound = body.getBoundingClientRect();
			zoom = (bound.right - bound.left)/body.clientWidth;
		}
		
		if (zoom > 1){
			clientTop = 0;
			clientLeft = 0;
		}
		
		var top = box.top/zoom + (window.pageYOffset || docElem && docElem.scrollTop/zoom || body.scrollTop/zoom) - clientTop,
		left = box.left/zoom + (window.pageXOffset|| docElem && docElem.scrollLeft/zoom || body.scrollLeft/zoom) - clientLeft;
	
				
		return {
		    left: left,
			top: top
		};
	}else {
		var top = 0, left = 0;
		do {
			top += el.offsetTop || 0;
			left += el.offsetLeft || 0;
		}while (el = el.offsetParent);
		
		return {
			    left: left,
			    top: top
		 };
	
    }
}


 /*   function getElementCoordinate(el){
	  
    }
    */
    
   var ElementDimension = {
        getElementCoordinate : function(el){
              var left, right, top, bottom;	
	    var offset = getOffset(el);
	    left = offset.left;
	    top = offset.top;
						
	    right = left + el.offsetWidth;
	    bottom = top + el.offsetHeight;		
		
	    return {
		        left: left,
		        right: right,
		        top: top,
		        bottom: bottom
	        };
        },
        
        getElementSize : function(el){
        
           var width = el.offsetWidth,
               height = el.offsetHeight;
               
           return{
                width:width,
                height:height
           }; 
        
        }

    }// object End
    
    return ElementDimension;
    
})();

//----------------------------------------------------------------------------------------



 /* auto complete jobtitle or location search
 *  20090805
 */


function AutoCompleteSalJobTitle(et,searchbyfield){
    var e = CrrEventUtility.adjustEvent(et);

    var initValue = document.getElementById(e.target.id).value;

    var source = e.target;
    if(source.value.length < 2)
    {
        cleanAutoComplete();
        return(false);
    }
    
    if(e.keyCode==9){// for TAB key
    
    
            var source = source;
                clearTimeout(source.hideTimer);
                source.hideTimer = setTimeout("cleanAutoComplete()",100);
            
       document.getElementById(e.target.id).style.color="#000000";
       mousedownEventHandler(e,e.target);
       if(document.getElementById(e.target.id).onfocus==null)
          document.getElementById(e.target.id).select();
        return;
    }
    
   if (e.keyCode == 38){
        cancelAutoCompleteTimer();
        var tbl = document.getElementById("tblAutoCompleteOptions");
        if(!tbl)
            return(false);
            
        if(typeof(tbl.currentSelection)=="undefined"){
            tbl.currentSelection = tbl.rows.length;
        }
         if(typeof(tbl.initailValue)=="undefined"){
            tbl.initailValue = initValue;
        }
        if(tbl.currentSelection<0)
            tbl.currentSelection = tbl.rows.length;
            
        var index = tbl.currentSelection - 1;
        if(index < 0){
            index = 0;
            tbl.currentSelection = index;

            changeAutoCompleteOption(e,tbl,tbl.rows[index].cells[0]);
            initializeTextBox(e,tbl.initailValue);
            tbl.currentSelection = tbl.rows.length;

            return(false);
        }
        changeAutoCompleteOption(e,tbl,tbl.rows[index].cells[0]);
        return(false);
    }
    
    if (e.keyCode == 40){
        cancelAutoCompleteTimer();
        var tbl = document.getElementById("tblAutoCompleteOptions");
        if(!tbl)
            return(false);
            
        if(typeof(tbl.currentSelection)=="undefined"){
            tbl.currentSelection = -1;
            }
        if(typeof(tbl.initailValue)=="undefined"){
            tbl.initailValue = initValue;
        }
       
        if(tbl.currentSelection==tbl.rows.length)
            tbl.currentSelection =  -1;
       
        var index = tbl.currentSelection + 1;
        if(index >= tbl.rows.length){
            tbl.currentSelection = index - 1;
            changeAutoCompleteOption(e,tbl,tbl.rows[index-1].cells[0]);
            initializeTextBox(e,tbl.initailValue);
            
            index = 0;
            tbl.currentSelection = -1;
            return(false);
        }
      changeAutoCompleteOption(e,tbl,tbl.rows[index].cells[0]);
        return(false);
    }

    if (e.keyCode == 27){

        cleanAutoComplete();
    }
    
    if (e.keyCode == 13){
        var tbl = document.getElementById("tblAutoCompleteOptions");
        if(!tbl)
            return(false);
        selectAutoCompleteOption(tbl);
        window.initialLocationValue="";
        return(false);
    }
   
    window.clearTimeout(source.autoCompleteTimer);

   
    source.onkeydown = function(){
        if (e.keyCode == 13){return(false);}
    } 
    
    window.autoCompleteObject = source;
    
    source.autoCompleteTimer = window.setTimeout("_AutoComplete('"+searchbyfield+"')",300);
    
    
    document.body.onclick=function(){

            var source = window.autoCompleteObject; 
            clearTimeout(source.hideTimer);
            source.hideTimer = setTimeout("cleanAutoComplete()",100);
    }
    
}

function initializeTextBox(e,initValue){
        document.getElementById(e.target.id).value=initValue;
}

function changeAutoCompleteOption(ev,table, td){


        var e = null;
        if(window.event)
            e = window.event;
        else
            e = changeAutoCompleteOption.caller.arguments[0];
        
        if(e.type!="mouseover"){

                document.getElementById(ev.target.id).value = table.rows[td.index].cells[0].firstChild.nodeValue;
    }
    
            table.rows[td.index].cells[0].style.backgroundColor='#B2B4BF';
            table.rows[td.index].cells[0].style.color="#FFFFFF";
            table.rows[td.index].cells[1].style.backgroundColor='#B2B4BF';
            table.rows[td.index].cells[1].style.color="#FFFFFF";
    if(table.currentSelection >= 0 && table.currentSelection <table.rows.length ){
            table.rows[table.currentSelection].cells[0].style.backgroundColor='#FFFFFF';
            table.rows[table.currentSelection].cells[0].style.color='#000000';
            table.rows[table.currentSelection].cells[1].style.backgroundColor='#FFFFFF';
            table.rows[table.currentSelection].cells[1].style.color='#000000';
        }
        table.currentSelection = td.index;
}

function _AutoComplete(searchfieldid){
    var source = window.autoCompleteObject;
    var arrHshParam = new Object();
    
    arrHshParam.searchField = source.value;
    arrHshParam.searchbywhichfield=searchfieldid;
    try{
        SalaryCom.CrrElements.CrrElementScripts.Crre_Base.SalAjxGetAutoCompleteOptions(arrHshParam, AutoComplete_CallBack);
    }
    catch(e)
    {
        cleanAutoComplete();
    }
    
 }
 
 
function AutoComplete_CallBack(r){


    var div = document.getElementById("dvAutoComplete");
    var source = window.autoCompleteObject;
    
    if (div==null){
        var topPosition = CrrElementDimension.getElementCoordinate(source).top;//source.offsetTop;
        var leftPosition = CrrElementDimension.getElementCoordinate(source).left; //source.offsetLeft;
        
        var srcWidth =  CrrElementDimension.getElementSize(source).width;
        var srcHeight =  CrrElementDimension.getElementSize(source).height;
        
        div = document.createElement("DIV");
        div.id = "dvAutoComplete";
        div.style.position = "absolute";
        div.style.top = topPosition + srcHeight + "px";
        div.style.left = leftPosition + "px";
        div.style.backgroundColor = "#FFFFFF";
        div.style.borderStyle = "solid";
        div.style.borderWidth = "1px";
        div.style.width = srcWidth-2 + "px";
        div.style.borderColor = "#000000";
        div.targetObj = source;
        if(document.all)
         div.onmouseenter = cancelAutoCompleteTimer;
        else 
         div.onmouseover = cancelAutoCompleteTimer;
         
         div.onmouseout = function(){window.isInAutoCompleteClick=false;}
         
          document.body.appendChild(div);
        
    }

    div.innerHTML = r.value;
    
    if(div.innerHTML=="" || div.innerText=="")
        document.body.removeChild(div);
   
    
    var tbl = document.getElementById("tblAutoCompleteOptions");
    if(!tbl){
        //remove iframe
       var ifrm = document.getElementById("ifAutoComplete");
       if(ifrm!=null){
       document.body.removeChild(ifrm);
       }
        return(false);
    }
    
    if(tbl.rows.length < 1)
    {
      
       cleanAutoComplete();
       return(false); 
    }
    var tblRowLen = tbl.rows.length;
    var truncatedIndex1 = 30;
    var truncatedIndex2 = 25;
    var truncatedItem;
    var lstIndex;
    for (var i = 0 ; i < tblRowLen ; i++){
        var row = tbl.rows[i];

        
        if(source.id !="jobtitle"&&source.id != "location"){
            if(trim(row.cells[0].firstChild.nodeValue).length>=truncatedIndex1){
               truncatedItem = row.cells[0].firstChild.nodeValue.substring(0, truncatedIndex1);
               lstIndex = truncatedItem.lastIndexOf(",");
               if(lstIndex<0){
                     lstIndex = truncatedItem.lastIndexOf(" ");
                     if(lstIndex<0)
                        lstIndex = truncatedIndex1;
                     }     
               row.cells[0].firstChild.nodeValue = row.cells[0].firstChild.nodeValue.substring(0,lstIndex);
              }
           }else{
               if(trim(row.cells[0].firstChild.nodeValue).length>=truncatedIndex2){
                    truncatedItem = row.cells[0].firstChild.nodeValue.substring(0, truncatedIndex2);
                     lstIndex = truncatedItem.lastIndexOf(",");
                    if(lstIndex<0){
                        lstIndex = truncatedItem.lastIndexOf(" ");
                        if(lstIndex<0)
                            lstIndex = truncatedIndex2;
                     }              
                    row.cells[0].firstChild.nodeValue = row.cells[0].firstChild.nodeValue.substring(0,lstIndex);
                }
           }
                
        
        row.cells[0].targetObj = div.targetObj;
        row.cells[0].autoCompleteMenu = div;
        
        
        
        row.cells[0].className = "content";
        row.cells[0].style.cursor = "pointer";
        row.cells[0].index = i;
        row.cells[0].tableObject = tbl;
       
        row.cells[0].onmouseover = new Function("changeAutoCompleteOption('"+div.targetObj.id+"',this.tableObject, this);");
            
         row.cells[0].onclick = function(e){
             var e = CrrEventUtility.adjustEvent(e||window.event);
             e.stopPropagation();
             this.targetObj.value = this.firstChild.nodeValue; 
             cleanAutoComplete();
             window.initialLocationValue="";
         }
    }
  

       //remove iframe
       var ifrm = document.getElementById("ifAutoComplete");
       if(ifrm!=null){
       document.body.removeChild(ifrm);
       }
       
    ifrm = document.createElement("IFRAME");
    ifrm.src = "/iframeblank.html";
    ifrm.id="ifAutoComplete";

   
    div.parentNode.appendChild(ifrm);
    div.ifrmObject = ifrm;
    
    var divTop = CrrElementDimension.getElementCoordinate(div).top;
    var divLeft = CrrElementDimension.getElementCoordinate(div).left;
    var divWidth = CrrElementDimension.getElementSize(div).width;
    var divHeight = CrrElementDimension.getElementSize(div).height;

    ifrm.style.position = "absolute";
    ifrm.style.top = divTop + "px";
    ifrm.style.left = divLeft + "px";
    ifrm.style.width = divWidth + "px";
    ifrm.style.height = divHeight + "px";
    ifrm.style.border="0px";

    div.style.zIndex = 20;
    ifrm.style.zIndex = 10;
    
//    startAutoCompleteTimerByKeyboard();

}


/*
function startAutoCompleteTimerByMouse(){
   if(document.activeElement)//document.activeElement ="BODY" for FireFox
    {
        if(document.activeElement.tagName=='TD')
        {
            if(document.activeElement.parentNode.parentNode.parentNode.id=='tblAutoCompleteOptions')
                return;
        }
    }

 //       var ec = new EventCompatibility();
 //       var e = ec.getEvent();

    if(!window.isInAutoCompleteClick){   
    var source = window.autoCompleteObject; 
    clearTimeout(source.hideTimer);
    source.hideTimer = setTimeout("cleanAutoComplete()",100);
    }
 
   
}*/

    
function startAutoCompleteTimerByKeyboard(){
    var source = window.autoCompleteObject; 
    clearTimeout(source.hideTimer);
    source.hideTimer = setTimeout("cleanAutoComplete()",3000);
}


function cancelAutoCompleteTimer(){
    var source = window.autoCompleteObject;    
    clearTimeout(source.hideTimer);
}

function cleanAutoComplete(){

    var div = document.getElementById("dvAutoComplete");
    var ifrm = document.getElementById("ifAutoComplete");
    
    if(ifrm!=null){
        //ifrm.outerHTML = "";
        document.body.removeChild(ifrm);
    }
    
    if(div!=null){
        document.body.removeChild(div);
    }
}





function selectAutoCompleteOption(table){
    var source = window.autoCompleteObject;
    if(typeof(table.currentSelection) !="undefined" && table.currentSelection>0 )
        source.value= table.rows[table.currentSelection].cells[0].firstChild.nodeValue;
    cleanAutoComplete();    
}


function trim(str){
            return str.replace(/(^\s*)|(\s*$)/g, "");  
}
        


function fillTextUp()
{

    if(document.getElementById("JobKeyword")!=null && document.getElementById("Location")!=null)
    {
        if(document.getElementById("JobKeyword").value=="" && document.getElementById("Location").value=="")
        {
            document.getElementById("JobKeyword").value = " Job Title or Keyword";
            document.getElementById("JobKeyword").style.color="#b7b9b7";
            document.getElementById("JobKeyword").style.width="241px";
            document.getElementById("Location").value = " ex: New York, NY or 10016";
            document.getElementById("Location").style.color="#b7b9b7";
            document.getElementById("Location").style.width="241px";
            addEventToElement(["JobKeyword","Location"],{"mousedown":mousedownEventHandler});
        }
        addEventToElement(["JobKeyword","Location"],{"focus":focusEventHandler});
    }
    

}

function clickBodyEventHandler(e,objEle)
{
    if(typeof (window.activeSearchObject)!="undefined"){
     var trimedValue = trim(window.activeSearchObject.value);
     if(trimedValue==''||trimedValue.length==0){
           if(window.activeSearchObject.id=="JobKeyword"){
                    document.getElementById("JobKeyword").style.color="#b7b9b7";
                    document.getElementById("JobKeyword").value=" Job Title or Keyword";
                    document.getElementById("JobKeyword").style.width="241px";
                }else if(window.activeSearchObject.id=="Location"){
                    document.getElementById("Location").value = " ex: New York, NY or 10016";
                    document.getElementById("Location").style.color="#b7b9b7";
                    document.getElementById("Location").style.width="241px";
                }else if(window.activeSearchObject.id=="jobtitle"){
                  
                }else{
                  
                }
            }
        }
}

function blurEventHandler(e,objEle)
{
    if(typeof (window.previousActiveSearchObject)=="undefined")
        window.previousActiveSearchObject = objEle;
    else{
        if( window.previousActiveSearchObject.value=="")
               if(window.previousActiveSearchObject.id=="JobKeyword"){
                    document.getElementById("JobKeyword").style.color="#b7b9b7";
                    document.getElementById("JobKeyword").value=" Job Title or Keyword";
                }else if(window.previousActiveSearchObject.id=="Location"){
                    document.getElementById("Location").value = " ex: New York, NY or 10016";
                    document.getElementById("Location").style.color="#b7b9b7";
                }else if(window.previousActiveSearchObject.id=="jobtitle"){
                   
                }else{
                   
                }
                window.previousActiveSearchObject = objEle;
    }

}

// can modify the event handler as you need
function mousedownEventHandler(e,objEle)
{
    if(typeof (window.previousActiveSearchObject)=="undefined")
    {
        window.previousActiveSearchObject = objEle;
    }
    else
    {
        if( window.previousActiveSearchObject.value=="")
        {
               if(window.previousActiveSearchObject.id=="JobKeyword" )                {
                    document.getElementById("JobKeyword").style.color="#b7b9b7";
                    document.getElementById("JobKeyword").value=" Job Title or Keyword";
                    document.getElementById("JobKeyword").style.width="241px";
                }
                else if(window.previousActiveSearchObject.id=="Location"){
                    document.getElementById("Location").value = " ex: New York, NY or 10016";
                    document.getElementById("Location").style.color="#b7b9b7";
                    document.getElementById("Location").style.width="241px";
                }
                window.previousActiveSearchObject = objEle;
        }
    }
        
   
    if(objEle.id=="JobKeyword"){
        if(objEle.value.indexOf("Keyword")>0)
            objEle.value = "";
    }else if(objEle.id=="Location"){
            if(objEle.value.indexOf("ex:")>0)
                objEle.value = "";
    }else if(objEle.id=="jobtitle"){
        if(objEle.value.indexOf("Keyword")>0)
                objEle.value = "";
    }else{
          if(objEle.value.indexOf("ex:")>0)
                objEle.value = "";
    }

    document.getElementById(objEle.id).style.color="#000000";
    document.getElementById(objEle.id).focus();
    window.activeSearchObject = objEle;
    

    
    if(window.event)
        e.cancelBubble = true;
    else
        e.stopPropagation();
    
}




// used to add an Event to a specific Element,which commonly support FF&IE.
function addEventToElement(arrTargetIds,objEventSettings)
{
    Function.prototype.getHandler = function(objEle)
    {
        var tempThis = this; var arg = objEle;
        return function(){
                if(window.event)
                    tempThis.call(null,window.event,arg);
                else
                    tempThis.call(null,arguments[0],arg);
         }
    }

    for(var i=0;i<arrTargetIds.length;i++)
    {
        for(var evTp in objEventSettings)
        {
                if(document.addEventListener)
                {
                    if(typeof arrTargetIds[i]=="string")
                    {
                        document.getElementById(arrTargetIds[i]).addEventListener(evTp,objEventSettings[evTp].getHandler(document.getElementById(arrTargetIds[i])),false);  
                    }
                    else if(typeof arrTargetIds[i]=="object")
                    {
                        arrTargetIds[i].addEventListener(evTp,objEventSettings[evTp].getHandler(arrTargetIds[i]),false);
                    }  
                }
                else if(document.attachEvent)
                {
                    if(typeof arrTargetIds[i]=="string")
                    {
                        document.getElementById(arrTargetIds[i]).attachEvent("on"+evTp,objEventSettings[evTp].getHandler(document.getElementById(arrTargetIds[i])));
                    }
                    else if(typeof arrTargetIds[i]=="object")
                    {
                        arrTargetIds[i].attachEvent("on"+evTp,objEventSettings[evTp].getHandler(arrTargetIds[i]));
                    }
                }
                else{}
        
        } 
    }
}



function focusEventHandler(e,objEle)
{

    document.getElementById(objEle.id).style.color="#000000";
    document.getElementById(objEle.id).focus();
    window.activeSearchObject = objEle;
    
    if(window.event)
        e.cancelBubble = true;
    else
        e.stopPropagation();
}


window.onload = fillTextUp;
