var isIE6 = navigator.userAgent.indexOf("MSIE 6") >= 0;
var isIE7 = navigator.userAgent.indexOf("MSIE 7") >= 0;
var isIE8 = navigator.userAgent.indexOf("MSIE 8") >= 0;
var isNetscape = navigator.userAgent.indexOf("Netscape/") >= 0;
var isOpera = navigator.userAgent.indexOf("Opera/") >= 0;
var isSafari = navigator.userAgent.indexOf("Safari/") >= 0;

var yourSearch = null;
var followYourSearch = true;

var onResizeCall = null;


function popup_resize()
{
  try
  {
    var content = document.getElementById("content");
    var footer = document.getElementById("footer");
    isIframe = (content.nodeName.toLowerCase() == "iframe");
    var height = footer.offsetTop - content.offsetTop - (isIE6 ? 0 : isIE7 && isIframe ? 90 : 30);
    content.style.height = height + "px";
  }
  catch (E)
  {
  }
}

function show_login(recruiterLogin)
{
  document.getElementById("login_bottom").style.display = "";
  var el = document.getElementById("login_bottom_content");
  growLoginHeightTo(el, recruiterLogin ? 190 : 230);
}

function hide_login()
{
  document.getElementById("login_bottom").style.display = "none";
  var el = document.getElementById("login_bottom_content");
  el.style.height = "0px";
}

function growLoginHeightTo(el, h)
{
  var h0 = parseInt(el.style.height);
  var rem = h - h0;
  if (rem > 20)
  {
    el.style.height = (h0 + (rem > 80 ? 60 : 30)) + "px";
    setTimeout("growLoginHeightTo(document.getElementById('"+el.id+"'), "+h+")", 800.0 / Math.max(rem, 40));
  }
  else
  {
    if (rem > 0)
      el.style.height = h + "px";
    document.getElementById("login").focus();
    document.getElementById("login").select();
  }
}

var bottomPos = 0;



var alignWithContent;

function search_results_scrolled(evt)
{
    var scrollTop = parseInt((document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop);

    var scrollHeight = parseInt((document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : document.body.scrollHeight);

    if (scrollTop > 120 && (scrollHeight > scrollTop + yourSearch.clientHeight + 160 || (yourSearch.clientHeight + parseInt(yourSearch.style.top) + 130 < (document.getElementById("footer").offsetTop + document.getElementById("footer").clientHeight))))
        {
            yourSearch.style.top = scrollTop + "px";
        }
    else if (scrollTop < 120)
        {
            yourSearch.style.top = "124px";
        }
}

function alignWithContent_scrolled(evt)
{
    try
    {
        var scrollTop = parseInt((document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop);
        if (scrollTop > 140)
            {
                alignWithContent.style.top = ( scrollTop - 140 ) + "px";
            }

        else
            {
                alignWithContent.style.top = 0;
            }
    }
    catch (E)
    {

    }
}


function alignWithContent_scrolled_popup(evt)
{
    try
    {
        var scrollTop = parseInt((document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop);

        //if (jjj++ == 5)
            

        if (scrollTop > 90)
            {
                alignWithContent.style.top = ( scrollTop ) + "px";
            }

        else
            {
                alignWithContent.style.top = "90px";
            }
    }
    catch (E)
    {
        alert("a");
    }
}

function getArray(s)
{
    if (s=="") return new Array();
    return s.split(",");
}


function createXmlHttp()
{
    /* Create a new XMLHttpRequest object to talk to the Web server */
    var xmlHttp = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    try {
      xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
      } catch (e2) {
        xmlHttp = false;
      }
    }
    @end @*/

    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}

function postSync(xmlHttp, updateFunction, param, url, postData) 
{
  xmlHttp.open('post', url, false);
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttp.send(postData);
  if (updateFunction)
    updateFunction(xmlHttp, param);
}

function addQS(baseQS, qs)
{
    var ret = new Array();

    if (!baseQS) return qs;

    var baseQS_array = baseQS.split('&');
    var baseQS_array_split = new Array(baseQS_array.length);

    for (var i = 0; i < baseQS_array.length; i++)
    {
	    baseQS_array_split[i] = baseQS_array[i].split('=');	
    }

    var qs_array = qs.split('&');
    var qs_array_split =  new Array(qs_array.length);

    for (var i = 0; i < qs_array.length; i++)
    {
	    qs_array_split[i] = qs_array[i].split('=');
    }

    var pushed = false;

    for (var i = 0; i < baseQS_array_split.length; i++)
    {
	    base_split = baseQS_array_split[i];
	    var process = true;
	    for (var j = 0; j < qs_array_split.length; j++)
	    {
		    if (base_split[0] == qs_array_split[j][0])
	{
			    process = false;
	    break;
	}
	    }
	    if (process)
	    {
		    if (pushed) ret.push('&');
		    ret.push(base_split[0]+'='+base_split[1]);
		    pushed = true;
	    }
    }

    if (qs)
    {
	    for (var i = 0; i < qs_array_split.length; i++)
	    {
		    if (pushed) ret.push('&');
		    ret.push(qs_array_split[i][0]+'='+qs_array_split[i][1]);
		    pushed = true;
	    }
    }
    return ret.join('');
}  



//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Popup functions
//

function closePopups()
{
  for (var id in popups)
  {
    hidePopup(id);
  }
}

/*
function movePopup(id, leaveVisibility)
{
  var p = document.getElementById("innerPopup1"+id);
  var popupInfo = popups[id];
  var moveCenter = popupInfo.moveCenter;
  var deltaLeft = popupInfo.deltaLeft;
  var deltaTop = popupInfo.deltaTop;

  var winW, winH;
  if (window.innerHeight)
  {
    winW = window.innerWidth;
    winH = window.innerHeight;
  }
  else if (document.body && document.body.offsetWidth)
  {
    winW = document.body.offsetWidth;
    winH = document.body.offsetHeight;
  }

  var p = document.getElementById("innerPopup1"+id);
  if (!leaveVisibility)
  {
    p.style.visibility="hidden";
    p.style.display = 'block';
  }
  var pageWidth = winW;
  var pageHeight = winH;

  var h = parseInt(p.clientHeight);
  var w = parseInt(p.clientWidth);

  var scrollTop = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;

  var scrollLeft = (document.documentElement &&  document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;

  if (moveCenter)
  {
      if (!deltaTop)
	deltaTop = 0;

      p.style.top = ((deltaTop ? deltaTop : 0) + (scrollTop+((pageHeight-h)	/2)))+"px";
      p.style.left = (scrollLeft+((pageWidth-w) /2)) + "px";
  }
  else
  {
    if (deltaLeft)
    {
      p.style.left = parseInt(deltaLeft)+"px";
    }
    if (deltaTop)
    {
      p.style.marginTop = parseInt(deltaTop)+"px";
    }
  }
}
*/
var popups = new Object();


function showPopup(id, moveCenter, deltaLeft, deltaTop, centerX)
{
    popups[id] = new Object();
    /*
    popups[id].moveCenter = moveCenter;
    popups[id].deltaLeft = deltaLeft;
    
    var innerDiv = document.getElementById('inner');
    if (!innerDiv)
    innerDiv = document.getElementById("content");
    var delta = 0;

    if ( (isIE6 || isOpera) && innerDiv)
      delta += innerDiv.scrollTop;
  
    if (deltaTop2)
      delta += deltaTop2;

    popups[id].deltaTop = delta + (self.isPopup ? 0
		: (isOpera ? 160 : isIE7 ? 140 :  -110));

    movePopup(id);
    */
   var p = document.getElementById("innerPopup1"+id);
   var winH;
      if (isIE7 || isIE8)
      {
          winH = document.documentElement.clientHeight;
      }
      else if (window.innerHeight)
      {
        winH = window.innerHeight;
      }
      else if (document.body && document.body.offsetWidth)
      {
        winH = document.body.offsetHeight;
      }
    p.style.visibility="";
    p.style.display = 'block';

   var currentWidth = p.clientWidth;
   
   if (moveCenter)
   {
       
       var currentHeight = p.clientHeight;
       var scrollTop = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
       p.style.top = (scrollTop + (winH / 2) - (currentHeight / 2) - (self.isPopup ? 10 : 140)) + "px";
       if (self.isPopup)
       {
           p.style.textAlign = "center";
           p.style.marginLeft = (290 - currentWidth / 2) + "px";
       }
       else
            p.style.left = (390 - currentWidth / 2) + "px";
   }
   else if (centerX)
   {   
       p.style.left = (390 - currentWidth / 2) + "px";
   }
   else if (deltaLeft > 0)
       {
           p.style.left = deltaLeft + "px";
       }
    
}
function hidePopup(id)
{
    document.getElementById("innerPopup1"+id).style.display = 'none';
}


function resizeText(divId, maxWidth, initFontSize)
{
    try
    {
        if (isSafari)
            return;
        text = document.getElementById(divId);
        var widthFinal = maxWidth;
        var widthTemp = parseInt(text.offsetWidth);
        var textOriginal = text.innerHTML;
        var lengthText = textOriginal.length;

        var maxIter = 200;
        while(widthTemp > widthFinal && lengthText > 0 && --maxIter > 0)
        {
            if (initFontSize > 12)
            {
                initFontSize--;
                text.style.fontSize = initFontSize + "px";
                text.innerHTML = textOriginal;

            }
            else
            {
                lengthText--;
                var textTrimmed = textOriginal.substring(0, lengthText) + "...";
                text.innerHTML = textTrimmed;
            }

            widthTemp = parseInt(text.offsetWidth);
        }
    }
    catch (E)
    {

    }
}

var jjj = 0;

var zoom = new Object();
var _maxScrollHeight = 0;
var _ie7_popup_resize_defined = false;
function popup_scrolled()
{
    try
    {
        if (isIE7)
        {
            if (_maxScrollHeight == 0)
                _maxScrollHeight = parseInt(document.documentElement.scrollHeight) + 200;

            if (!_ie7_popup_resize_defined)
            {
                _ie7_popup_resize_defined = true;
                window.addEventListener("resize", "_maxScrollHeight=0", true);
            }

            if (parseInt(document.documentElement.scrollHeight) > _maxScrollHeight)
                return;
        }
        
        var scrollTop = parseInt((document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop);
    
        if (parseInt(document.getElementById("popup_footer").style.marginTop) != scrollTop)
            document.getElementById("popup_footer").style.marginTop = scrollTop + "px";
    }
    catch (E)
    {        
    }
}


function popupFrameResize()
{
    try
    {
        var f = document.getElementById("frame_content");
           var winH;
          if (isIE7 || isIE8)
          {
              winH = document.documentElement.clientHeight;
          }
          else if (window.innerHeight)
          {
            winH = window.innerHeight;
          }
          else if (document.body && document.body.offsetWidth)
          {
            winH = document.body.offsetHeight;
          }
        f.style.height = (winH - 160) + "px";
    }
    catch (E)
    {
        
    }
}


function scrollToBottom()
{
    var scrollHeight = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : document.body.scrollHeight;

    if (document.documentElement && document.documentElement.scrollHeight)
        document.documentElement.scrollTop = scrollHeight;
    else
        document.body.scrollTop = scrollHeight;
}


function openWidePopup(href)
{
	var w = window.open(href, "_blank",
	'toolbar=no,menubar=no,titlebar=no,status=no,scrollbars=yes,resizable=yes,width=800,height=740');
    try { w.focus(); }
      catch (E) {}
}

function ensureWidePopup()
{
  try
  {
    var curwidth = document.body.clientWidth;
    if (!curwidth)
        curwidth = document.documentElement.clientWidth;

    if (curwidth < 800)
        window.resizeTo(800,740)
  }
  catch (E)
  {}
}

function openPopup(href)
{
	var w = window.open(href, "",
	'toolbar=no,menubar=no,titlebar=no,status=no,scrollbars=yes,resizable=yes,width=660,height=740');
    try { w.focus(); }
      catch (E) {}
}


function scrollToTopAnchor(){
  var theElement = document.getElementById("top_anchor")
  elemPosX = theElement.offsetLeft
  elemPosY = theElement.offsetTop;
  theElement = theElement.offsetParent;
  while(theElement != null){
    elemPosX += theElement.offsetLeft
    elemPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
 }
 window.scrollTo(elemPosX ,elemPosY);
}
