﻿// JScript File
var cX = 0; 
var cY = 0; 
var rX = 0; 
var rY = 0;

function UpdateCursorPosition(e)
{ 
    cX = e.pageX; 
    cY = e.pageY;
}
function UpdateCursorPositionDocAll(e)
{ 
    cX = event.clientX; 
    cY = event.clientY;
}
    if(document.all) 
    { 
        document.onmousemove = UpdateCursorPositionDocAll; 
    }
    else 
    { 
        document.onmousemove = UpdateCursorPosition; 
    }

function AssignPosition(d) 
{
    if(self.pageYOffset) 
    {
	    rX = self.pageXOffset;
	    rY = self.pageYOffset;
    }
else if(document.documentElement && document.documentElement.scrollTop) 
{
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
}
else if(document.body) 
{
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
}

if(document.all) 
{
	cX += rX; 
	cY += rY;
}
    d.style.left = (cX+10) + "px";
    d.style.top = (cY+5) + "px";
}

function HideContent(d) 
{
    if(d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}

function ShowContent(d) 
{
    if(d.length < 1) { return; }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    dd.style.display = "block";
}

function ReverseContentDisplay(d) 
{
    if(d.length < 1) { return; }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    if(dd.style.display == "none") { dd.style.display = "block"; }
    else { dd.style.display = "none"; }
}
function toggle(div_id) {

    if(div_id.length < 1) { return; }
    
	var el = document.getElementById(div_id);
	AssignPosition(el);
	el.style.display = 'block';	
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}


function getParamStringForPost(obj){
    
  var params = "";
  
  for(var a in obj){
      if(params != "")
          params += "&";
      
      params += a; 
      params += "=" + escape(obj[a]); 
  }
  
  return(params);
}

function toggles() 
{
    document.getElementById("popup_name").style.display = 'none';
    document.getElementById("popup_name").innerHTML = "";
    document.getElementById("popup_Alert").style.display = 'none';
    document.getElementById("popup_Alert").innerHTML = "";
    document.getElementById("popup_AlertPercent").style.display = 'none';    
    document.getElementById("popup_AlertPercent").innerHTML = "";
}

function callServerMethod(url, params, callbackfunction){
    
    var http = createRequestObject();
    
    if(!http){
      alert("Error: No support ");
    }
    
    http.open("POST", url, true);
    
    //window.open(url + "&" + params);
    
    //Send the proper header information along with the request
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");

    http.onreadystatechange = function() {//Call a function when the state changes.
            
            if(http.readyState == 4 && http.status == 200) {
                    var resultado = new Object();
                    
                    var xml = http.responseXML;
                    var dados = xml.getElementsByTagName("data");
                    for(var i = 0 ; i <  dados.length ; i++)
                          {
                          var paramName = dados[i].getAttribute("id");
                          var paramValue = dados[i].text;
                          if(!paramValue){
                              paramValue = dados[i].textContent;
                          }
                          
                          eval("resultado." + paramName + " = paramValue");
                    }
                    if(callbackfunction){
                        //callbackfunction(http.responseText);
                        callbackfunction(resultado);
                    }
            }
    }
    http.send(params);
}


function createRequestObject(){
    var xmlHttp;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          return false;
          }
        }
      }
      return xmlHttp;
}


function testAjax_callback(r)
{
 
    var dv = document.getElementById("dvGlossary");
    dv.innerHTML = r.result;
}

function Inint_AJAX()
{
    var xmlHttp;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          return false;
          }
        }
      }
      return xmlHttp;
}

function glossaryDetail(g_ID)
{
    var dvGlossary = document.getElementById("dvGlossaryDetail");
    
    dQuery = "emp_ID=" + empID + "&delete=" + del_photo;
   
    setTimeout("callServerMethod(\'ajaxResponse.asp\'," + sQuote(dQuery)+ ", testAjax_callback)", 1000);
}

function hideDetail()
{
    var dvGlossary = document.getElementById("dvGlossaryDetail");
    dvGlossary.style.display = "none";
}

function toggleDIV(g_ID)
{
    var dvShow = 'show'+g_ID;
    var tgShowDiv = document.getElementById(dvShow);
    var sQuery = "g_ID=" + g_ID + "&show=true";
    callServerMethod("aj_getGlossary.asp",sQuery, testAjax_callback);
}

function nToggleDIV(g_ID)
{
    var dvShow = 'show'+g_ID;
    var tgShowDiv = document.getElementById(dvShow);
    var sQuery = "g_ID=" + g_ID + "&show=false";
    callServerMethod("aj_getGlossary.asp",sQuery, testAjax_callback);
}

function expandAll()
{
    var dvGlossary = document.getElementById("dvGlossary");
    var sQuery = "g_ID=&show=all";
    callServerMethod("aj_getGlossary.asp",sQuery, testAjax_callback);
}

function contractAll()
{
    var dvGlossary = document.getElementById("dvGlossary");
    var sQuery = "g_ID=&show=none";
    callServerMethod("aj_getGlossary.asp",sQuery, testAjax_callback);
}


function showLoadingEffect()
{
    var dvLoading = document.getElementById('divloading');
    dvLoading.style.display = 'block';
    dvLoading.innerHTML = '<p><img src="images/loader.gif"></p>';
}

function hideLoadingEffect()
{
    var dvLoading = document.getElementById('divloading');
    dvLoading.style.display = 'none';
}

function toggleSelect(obj)
{
    var appVer = navigator.appVersion.toLowerCase();
    var iePos = appVer.indexOf('msie');
    if (iePos !=-1) 
    {
        var is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
        var is_major = parseInt(is_minor);
    }

    if (navigator.appName.substring(0,9) == "Microsoft")
    { // Check if IE version is 6 or older
        if (is_major <= 6) 
        {
            var selx,sely,selw,selh,i, objx, objy, objh, objw, visibility
            var sel=document.getElementsByTagName("SELECT")
            var hidden = false;
            for(i=0;i<sel.length;i++)
            {
                selx=docjslib_getRealLeft(sel[i]);
                sely=docjslib_getRealTop(sel[i]);
                selw=sel[i].offsetWidth;
                selh=sel[i].offsetHeight;
                selxoff=(selx + selw);
                selyoff=(sely + selh);
                objx=docjslib_getRealLeft(obj);
                objy=docjslib_getRealTop(obj);
                objw=obj.offsetWidth;
                objh=obj.offsetHeight;
                if((objx < selx) && (selx < (objx + objw)) && (objy < sely) && (sely < (objy + objh)))
                {
                    if(sel[i].style.visibility!="hidden")
                    {
                        sel[i].style.visibility="hidden";
                    }
                    else
                    {
                        sel[i].style.visibility="visible";
                    }
                }
                else if((objx < selxoff) && (selxoff < (objx + objw)) && (objy < selyoff) && (selyoff < (objy + objh))) 
                {
                    if(sel[i].style.visibility!="hidden")
                    {
                        sel[i].style.visibility="hidden";
                    }
                    else
                    {
                        sel[i].style.visibility="visible";
                    }
                }
                else
                {
                    if(sel[i].style.visibility=="hidden")
                    {
                        sel[i].style.visibility="visible";
                    }
                }
                visibility = sel[i].style.visibility;
            }
        }
    }
}
function loadFeedControl() 
	{
    		var feed  = "http://rss.people.com/web/people/rss/topheadlines/index.xml";
   		    var fg = new GFdynamicFeedControl(feed, "feedControl");
	}
//gets the X position of the element in question

function docjslib_getRealLeft(imgElem) 
{
    xPos = eval(imgElem).offsetLeft;
    tempEl = eval(imgElem).offsetParent;

 	while (tempEl != null) 
 	{
	    xPos += tempEl.offsetLeft;
     	 tempEl = tempEl.offsetParent;
 	}
    return xPos;
}

//gets the Y position of the element in question

function docjslib_getRealTop(imgElem) 
{
    yPos = eval(imgElem).offsetTop;
    tempEl = eval(imgElem).offsetParent;

    while (tempEl != null) 
    {
	    yPos += tempEl.offsetTop;
     	 tempEl = tempEl.offsetParent;
 	}
    return yPos;
}
function ajx_ShowJobDetails(jobID)
{
    var html = '<img src=images/processing.gif>';
    document.getElementById('popup_name').innerHTML = html;
    var fQuery = "?jobID=" + jobID;
    makePostRequest('jobDescription.aspx', fQuery);
    blanket_size('popup_name');
	window_pos('popup_name');
	//toggle('blanket');
	toggle('popup_name');
}

