var _n=null;
function s_e(ts){ts.style.display="";}
function h_e(ts){ts.style.display="none";}

function showElement(ele){
  var ts=document.getElementById(ele);
  if(ts!=_n)s_e(ts);
}
function hideElement(ele){
  var ts=document.getElementById(ele);
  if(ts!=_n)h_e(ts);
}

/* 
 * This utility is used in conjunction with cleaField to set and clear
 * text in a text field on focus and on blur respectively. This one
 * sets the default value.
 * @param field The field whose value need to be set to default value
 */
function populateField(field) {
	var message = document.getElementById(field);
	if (!message) return;
	
	var sample = message.getAttribute("prompt");
	if (!sample) return;
	
	// If the current field value is empty set it to default
	if (message.value == "") {
		message.value = sample;
		message.style.color="#3c3c3c";
	}
}

/* 
 * This utility is used in conjunction with cleaField to set and clear
 * text in a text field on focus and on blur respectively. This one clears
 * default value.
 * @param field The field whose value need to be set to default value
 */
function clearField(field) {
	var message = document.getElementById(field);
	if (!message) return;
	
	var sample = message.getAttribute("prompt");
	if (!sample) return;
	
	// Clear the field if the current value is set to default
	if (message.value == sample) {
		message.value = "";
		message.style.color="#000000";
	}
}

    /* 
 * This utility is used in conjunction with cleaField to set and clear
 * text in a text field on focus and on blur respectively. This one
 * sets the default value.
 * @param field The field whose value need to be set to default value
 */
function populateField2(field, dft) {
	var message = document.getElementById(field);
	if (!message) return;
	
	var sample = dft;
	if (!sample) return;
	
	// If the current field value is empty set it to default
	if (message.value == "") {
		message.value = sample;
		message.style.color="#3c3c3c";
	}
}

/* 
 * This utility is used in conjunction with cleaField to set and clear
 * text in a text field on focus and on blur respectively. This one clears
 * default value.
 * @param field The field whose value need to be set to default value
 */
function clearField2(field, dft) {
	var message = document.getElementById(field);
	if (!message) return;
	
	var sample = dft;
	if (!sample) return;
	
	// Clear the field if the current value is set to default
	if (message.value == sample) {
		message.value = "";
		message.style.color="#000000";
	}
}

function submitForm( id )
{
  document.getElementById(id).submit();
}

function doEventDispatch(elmId,check) {
   var evt = null,
       elm = null;

   if(document.getElementById) {
     elm = document.getElementById(elmId);
   }
   if(document.createEvent) {
     evt = document.createEvent('MouseEvents');
   }
   if(document.createEventObject)
   {
    evt = document.createEventObject('MouseEvents');
   }
   if(elm && elm.fireEvent)
   {
   elm.fireEvent("onclick");
   }
   if(elm && elm.dispatchEvent && evt && evt.initMouseEvent) {
     evt.initMouseEvent(
       'click',
       true,     // Click events bubble
       true,     // and they can be cancelled
       document.defaultView,  // Use the default view
       1,        // Just a single click
       0,        // Don't bother with co-ordinates
       0,
       0,
       0,
       false,    // Don't apply any key modifiers
       false,
       false,
       false,
       0,        // 0 - left, 1 - middle, 2 - right
       null);    // Click events don't have any targets other than
                 // the recipient of the click

     elm.dispatchEvent(evt);
}
  if(!check && elm)
  {
      elm.onclick=null;
  }
}
    
function isEmpty(elem, msg)
{
    if( elem.value == null || elem.value == '' ){
        alert( msg );
        return false;
    }
    return true;
}
function confirmCheck(msg){
   return confirm(msg);
}

 function showList(obj,locationArray,keyword,location2)
{
    var divobj = document.getElementById("moreLocation"); 
    var element = divobj.getElementsByTagName("li");
    var length = element.length;                                
    for ( var index = length - 1; index >= 0; index--)
    {
        divobj.removeChild(element[index]);
    }                               
    var value = obj.value;        
    value= value.toUpperCase();
    if ( value != null && value.length != 0 )
    {
        var startIndex = locationArray.indexOf( "{" + value, 0);                                    
        var endIndex = locationArray.indexOf( ",", startIndex );

        while ( startIndex != -1 && endIndex != -1 && startIndex < endIndex)
        {
            var locationName = locationArray.substring(startIndex + 1,endIndex);          
            startIndex = endIndex + 1;
            endIndex = locationArray.indexOf( ",", startIndex );
            var locationId = locationArray.substring(startIndex,endIndex);
            startIndex = endIndex + 1;
            endIndex = locationArray.indexOf( "}", startIndex ); 
            var locationCount = locationArray.substring(startIndex,endIndex);                      

            var liElement = document.createElement("li");                                        
            liElement.innerHTML = '<a href="/jobs-in/' + locationName + '/' + locationCount + '/' + keyword + '/in/' + location2 + '/0">'+ locationName + '(' + locationCount + ') </a>';
            divobj.appendChild( liElement );

            startIndex = locationArray.indexOf( "{" + value, endIndex);                                                                                
            endIndex = locationArray.indexOf( ",", startIndex );                                           
        }
    }                             
    return true;
}

 function isChecked( formname )
{
  var formElm = document.forms[formname];
  if ( formElm ){
    var count = formElm.elements.length;
    for (var i=0; i < count; i++) {
        if ( formElm.elements[i].checked == 1 )
          return true;
    }
  }
  return false;
}

function getCheckedElements( formname )
{
  var checkedElms='';
  var formElm = document.forms[formname];
  if ( formElm ){
    var count = formElm.elements.length;
    for (var i=0; i < count; i++) {
        if ( formElm.elements[i].checked == 1 )
        {
          checkedElms += formElm.elements[i].value + ",";
        }
    }
  }
  return checkedElms;
}

function selectIt( sel, val)
{
	for( var i=0, limit=sel.options.length; i < limit; ++i )
	{
		if( sel.options[i].value==val )
			sel.options[i].selected=true;
	}
}

 function CheckAll( formname )
{
  var formElm = document.forms[formname];
  if ( formElm ){
    var count = formElm.elements.length;
    for (var i=0; i < count; i++) {
      formElm.elements[i].checked = 1;
    }
  }
  return false;
}

function UncheckAll( formname )
{
  var formElm = document.forms[formname];
  if ( formElm ){
    var count = formElm.elements.length;
      for (var i=0; i < count; i++) 
      {
         formElm.elements[i].checked = 0;
      }
  }
return false;
}

function adjustContent(content, maxsize, adjustType, replaceID, addHellip, lineBreak ) {
    var ele=document.getElementById(replaceID);
    a_d='';
    if(adjustType=='trim'){
        a_d=content.toString().substring(0,maxsize);
        if(a_d.length!=content.length && addHellip )
            a_d+='...';
    }
    if(adjustType=="wrap"){
        var n_s_c=0;
        var a_n=false;
        for (var i = 0; i < content.length; i++) {
            if(lineBreak){
                if( i!=0 && i%maxsize==0){
                    if(content.charAt(i)==' '){
                        a_d+='<br>';
                        continue;
                    }
                    else{
                        a_n=true;
                    }
                }
                if(!a_n){
                    a_d+=content.charAt(i);
                }
                else{
                    if(content.charAt(i)==' '){
                        a_d+='<br>';
                        a_n=false;
                    }
                    else{
                        a_d+=content.charAt(i);
                    }
                }
                continue;
            }
            if(content.charAt(i)==' ')
                n_s_c=0;
            else
                n_s_c++;
            if(n_s_c!=0 && n_s_c%maxsize==0)
                a_d+=' ';
            a_d+=content.charAt(i);
        }
        if(addHellip)
            a_d+='...';
    }
    if(ele)
      ele.innerHTML=a_d;
}
function validateImage(url,replaceId,dftImg){
    var targetImage=new Image;
    targetImage.src=url;
    if(targetImage.height==0){document.getElementById(replaceId).src=dftImg;}
}


