var ns;
var ie;
var ns6;
var mac;
var win;
var siteWidth = 600;
ns4 = (document.layers)? true:false;
ie = (document.all)? true:false;
ns6=(document.getElementById&&!document.all)? true:false;
mac=(navigator.platform.indexOf("Mac") > -1)? true:false;
win=(navigator.platform.indexOf("Win") > -1)? true:false;

function getE(id) {
	return document.getElementById(id);
}

function $(id) {
	return document.getElementById(id);
}

function trimDivs(e)
{
	var divsP, divs, div, divP;
	var x, y, s, z;
	var ie6;
	
	if (ie==false) return 0;
	
	
	ie6 = (navigator.userAgent.indexOf('MSIE 6.0')) >-1;
				
	divs = document.all.tags('nobr');

	
	z = 0;
	
	for (y=0;y<divs.length;y++) {
		div = divs(y);
		
		
		if (div.scrollWidth>div.offsetWidth && div.offsetWidth>0 && div.title=='') {
			
			div.title=div.innerText;
			
			s = div.title;
			div.style.cursor='default';
			
			if (ie6==false) {
				
				z=0;

				while (div.scrollWidth-div.clientWidth>100) {
					s = s.substr(0,s.length-20);
					div.innerText = s + '...';
					
					
					if (z++>=200) break;
				}
				while (div.scrollWidth-div.clientWidth>50) {
					s = s.substr(0,s.length-5);
					
					div.innerText = s + '...';
					
					if (z++>=200) break;
				}								
				while (div.scrollWidth>div.offsetWidth) {
					s = s.substr(0,s.length-1);
					
					if (s.substr(s.length-1,1) == ' ')
						s = s.substr(0,s.length-1);
					
					div.innerText = s + '...';
					
					if (z++>=200) break;
				}		
			}
		}
	}
}
		
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
	if (begin != 0) return null;
	} else
		begin += 2;
	
	var end = document.cookie.indexOf(";", begin);
	
	if (end == -1)
	end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function showHide(id) {

getE(id).style.display = (getE(id).style.display=='block')? 'none':'block';

}

function itemVisibility(id,v) {
    if (v){
        getE(id).style.display = 'block'
    }else{
        getE(id).style.display = 'none'
    }
//(getE(id).style.display=='block')? 'none':'block';
}

function showE(id) {

getE(id).style.display = '';

}

function hideE(id) {

getE(id).style.display = 'none';

}


function resizeWindow() {

var c = getE('content');
var height;

if (c) {
	
	var b = getE('bottom');

	height = document.body.offsetHeight-70;
	
	if (document.body.offsetWidth<1024)
		height += -16;
		
	
	if (b)
		height+=-b.offsetHeight;
	
	var t = getE('top');
	
	if (t)
		height += -t.offsetHeight+28;
		
	
	if (height>100) 
		c.style.height=height;


}


}

function navigate(url) {
	document.forms('_formNav').action=url;
	document.forms('_formNav').submit();
}

/*
function openDialog(url, height, width, arguments, sizeable)
{
	var features = "center:yes;help:no;status:yes;";

	if (sizeable)
		features += "resizable:yes;"
		
	if (!height)
		height = 550;

	if (!width)
		width  = 900;
		
	features += "dialogHeight:" + (height + 26) + "px; dialogWidth:" + width + "px;"

	try {
		window.returnValue = window.showModalDialog(url, arguments, features)
	}
	catch (e) {
		window.open(url);
	}
	
	if (window.returnValue)
		return true;
}
*/

function openDialog(url, height, width, arguments, sizeable)
{
	var features = "center=yes, ";

	if (sizeable)
		features += "resizable=yes,scrollbars=yes "
		
	if (!height)
		height = 550;

	if (!width)
		width  = 900;
	
	features += "left=20, "
	
	features += "height=" + (height-36) + ", width=" + width + "";
    
    if (arguments)
        features += "," + arguments;
        
	window.open(url,null,features);
	
}

function toggleSelect(v, top) {

	var s = document.getElementsByTagName('select');

	if (s) {

		for (var x=0;x<s.length;x++) {
		    
			if (! s[x].donthide)
				s[x].style.visibility=v;
		}
	}
}


//function popupYesNo(title, text, button1, button2) {
//var s;

//s = 'YesNoDialog.aspx?Title=' + title + '&Text=' + text;

//if (button1)
//	s += '&Button1=' + button1;

//if (button2)
//	s += '&Button2=' + button2;
//	
//	var features = "center:yes; help: no; status:no; ";

//	var height = 120;
//	var width  = 300;
//	
//	features += "dialogHeight:" + height +"px; dialogWidth:" + width + "px;"

//	
//		return window.showModalDialog(s, true, features);
//	
//	
//}

function shortDate() {
var today = new Date()
  var year = today.getYear()
  if(year<1000) year+=1900
     
  return (today.getMonth()+1) + "/" + today.getDate() + "/" + (year+"").substring(2,4)

}

//function keypressHandler() {

//	try {
//	if (window.event.keyCode==189 && window.event.ctrlKey)
//		if ((window.event.srcElement.tagName.toLowerCase()=='input' && window.event.srcElement.type.toLowerCase()=='text') || window.event.srcElement.tagName.toLowerCase()=='textarea')
//			{ 
//			var txt = window.event.srcElement;
//			if (txt.createTextRange) {
//				txt.caretPos = document.selection.createRange().duplicate();
//				txt.caretPos.text = shortDate(); 
//			}
//			}
//	}
//	catch (e) {}
//}

//document.onkeydown=keypressHandler;

var blink_speed = 500;

function Blink(id){
var d;

	d = getE(id)
	
	if (d.className=='blinkOn')
		d.className='blinkOff';
	else
		d.className='blinkOn';
	 
 setTimeout("Blink('"+id+"')",blink_speed);
}




	function autoSize() {
		//document.getElementById('content').style.height = document.body.offsetHeight-5;
	}
	
	
function checkMax(form, controlName, max)
{
	var checkedItems = 0;
	var returnVal = true;
	
	if(max > 0)
	{
		for(x = 0;x < form[controlName].length;x++)
		{
			if(form[controlName][x].checked == true)
			{
				checkedItems++;
				
				if(checkedItems > max)
				{
					returnVal = false;
				}
			}
		}
	}
	
	if(returnVal == false)
	{
		alert("Please limit to " + max + " selections.");
	}
	
	return returnVal;
}

function checkBoxDropDownItemSelected(control)
{
	var itemSelected = false;
	
	for(x = 0;x < control.length;x++)
	{
		if(control[x].checked == true)
		{
			itemSelected = true;
		}
	}
	
	return itemSelected;
}

function applyJobT(j, js) {

var i = new Image;

i.src='/xt/ApplyJobT.aspx?j=' + j + '&js=' + js;

}

function applyJobTJ(j, js) {

var i = new Image;

i.src='/xt/ApplyJobT.aspx?j=' + j + '&js=' + js + '&t=j';

}


		function emailValid(str1) {
        var str=String(str1)
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }

 		 return true;				
	}

var enterKeyUsed = false
function AutocompleteDown(id, e) {
window.status = window.status + 'ac down'

    enterKeyUsed=false
    var key = (window.event) ? event.keyCode : e.keyCode;
    var t = document.getElementById(id + 'Text');
    var s = document.getElementById(id + 'Value');
    var test;
    var testIndex;
    var value = t.value.toLowerCase();
    var selIndex;
    var startAt;
    var selStart = doGetCaretPosition(t);
    var specialKey;


    switch (key) {
        case 38:
            selIndex = s.selectedIndex -1;
            selStart = 0;
            specialKey = true;
            break;
           
        case 40:
            selIndex = s.selectedIndex +1;
            selStart = 0;
            specialKey = true;
            break;
       case 13:
                 
       //     debugger;  
            window.blur()
            window.focus()
            selIndex=s.selectedIndex;
           
            s.style.display='';
            enterKeyUsed=true;
            return false;
            break;
    }
    
    //if they are typing out a new name, this short-circuits the logic
    //greatly speeding the time it takes to type
    if (selStart>3 && s.selectedIndex==-1){
                return true;
    }
    
    
    if (selIndex >-1 && selIndex < s.options.length) {
        
        s.selectedIndex = selIndex;
        var selEnd = s.options[selIndex].text.length;
        
        //t.value = s.options[selIndex].text;
        
        doSetCaretPosition(t,0, selEnd);
        
        s.style.display='';
        
        return false;
    }
    
    
    return true;
    

}


function AutocompleteUp(id, e) {
     window.status = window.status + 'ac up'
    var key = (window.event) ? event.keyCode : e.keyCode;
    
    var t = document.getElementById(id + 'Text');
    var s = document.getElementById(id + 'Value');
    var test;
    var testIndex;
    var value = t.value.toLowerCase();
    var selIndex;
    var startAt;
    var selStart = doGetCaretPosition(t);
    var specialKey;
    

    switch (key) {
        
        case 8:
            specialKey = true;
            break;
            
        case 35:
            specialKey = true;
            break;
            
        case 36:
            specialKey = true;
            break;
            
        case 37:
            specialKey = true;
            break;
            
        case 38:
            specialKey = true;
            break;
        case 39:
            specialKey = true;
            break;
            
        case 40:
            specialKey = true;
            break;
       case 46:
            specialKey = true;
            break;
        default:
        
            //if they are typing out a new name, this short-circuits the logic
    //greatly speeding the time it takes to type
    if (selStart>3 && s.selectedIndex==-1){
        return true;
    }
    
        
        if (value.length>0) {
            startAt = s.selectedIndex;
            if (startAt > 10)
                startAt = startAt-10;
            
            if (startAt < 0)
                startAt = 0;
                    
            for (var x =startAt;x<s.options.length;x++) {
                test = s.options[x].text.toLowerCase();    
                
                testIndex = test.indexOf(value)
                if (testIndex==0) {
//                    if (key==13){
//                        var mybreak=1;
//                    }
                    if (test.length!=value.length && key==13){
                        //alert('hello!');
                        s.style.display='none';
                        s.selectedIndex=-1;
                        break;
                        
                    }else{
                        selIndex = x;
                        break;
                    }
                }
            }
            
            if (!selIndex && value.length > 3) {
                for (var x =0;x<s.options.length;x++) {
                    test = s.options[x].text.toLowerCase();    
                    
                    testIndex = test.indexOf(value)
                    if (testIndex>0) {
                        selIndex = x;
                        break;
                    }
                }
            }
        }
    }
    
    if (selIndex >-1 && selIndex < s.options.length) {
        
        if (!specialKey)
            s.selectedIndex = selIndex+10;
            
        s.selectedIndex = selIndex;
        var selEnd = s.options[selIndex].text.length;
        
        //t.value = s.options[selIndex].text;
        
        doSetCaretPosition(t,selStart, selEnd);
        
        s.style.display='';
        
    }
    else if (!specialKey)
        s.selectedIndex=-1;
        
   //hack to make the blur event fire when hitting enter
   if (key==13){
   //document.getElementById('focusCatch').focus();
   t.blur();
   }
        
    return true;
    
}

function AutocompleteClick(id,ev) {

window.status = window.status + 'click'
    var t = document.getElementById(id + 'Text');
    var s = document.getElementById(id + 'Value');

    t.value = s.options[s.selectedIndex].text;
    doSetCaretPosition(t,0,t.value.length);
    enterKeyUsed=true;
    AutocompleteBlur(id,ev)

}

var tF=false;
var sF=false;

function registerBlur(id){
    ddHasFocus=false;
    enterKeyUsed=true;
    AutocompleteBlur(id,null) 
}

//Says that the drop down has focus
var ddHasFocus =false
function registerFocus(){
    ddHasFocus=true;
}
function closeDD(id) {
    window.status ='IN closedd'
    if (!ddHasFocus){
        window.status ='IN IF'
        //allows the atuocomplete blur to be called and actually close the dd instead
        //of being short cirtucted
       enterKeyUsed=true
       AutocompleteBlur(id,null) 
    }
}


function AutocompleteBlur(id,eventInfo) {
window.status+='hello'

if (!enterKeyUsed){
setTimeout('closeDD(\'' + id + '\')',1000)
return;
}

     window.stats = window.status + 'blur'
    var t = document.getElementById(id + 'Text');
    var s = document.getElementById(id + 'Value');
    //alert('hello')
    if (s.selectedIndex != -1){ 
    t.value = s.options[s.selectedIndex].text;
    }
    //s.style.display='none';
    //debugger;
    document.getElementById(id+'Value').style.display="none"

    //alert(eventInfo);
    //Raise a pseudo event, calls a function but doesn't break
    //if it doesnt exist.  This allows us to do work on the page, on blur
    
    try{
        AutocompleteBlurEvent(id,eventInfo)
    }catch(e){
    }
    //alert('done')
   window.blur()
   window.focus()

}


function doGetCaretPosition (oField) {

     // Initialize
     var iCaretPos = 0;

     // IE Support
     if (document.selection) { 

       // Set focus on the element
       oField.focus ();
  
       // To get cursor position, get empty selection range
       var oSel = document.selection.createRange ();
  
       // Move selection start to 0 position
       oSel.moveStart ('character', -oField.value.length);
  
       // The caret position is selection length
       iCaretPos = oSel.text.length;
     }

     // Firefox support
     else if (oField.selectionStart || oField.selectionStart == '0')
       iCaretPos = oField.selectionStart;

     // Return results
     return (iCaretPos);
   }


function doSetCaretPosition (oField, iCaretPos, end) {

     // IE Support
     if (document.selection) { 

       // Set focus on the element
       oField.focus ();
  
       // Create empty selection range
       var oSel = document.selection.createRange ();
  
       // Move selection start and end to 0 position
       oSel.moveStart ('character', -oField.value.length);
  
       // Move selection start and end to desired position
       oSel.moveStart ('character', iCaretPos);
       oSel.moveEnd ('character', end);
       oSel.select ();
     }

     // Firefox support
     else if (oField.selectionStart || oField.selectionStart == '0') {
       oField.selectionStart = iCaretPos;
       oField.selectionEnd = end;
       oField.focus ();
     }
   }



	function AcroPluginCheck()
	{
		var agt=navigator.userAgent.toLowerCase();
		
		if(agt.indexOf("msie") != -1)
		{
			IEShowVersionInfo();
		}
		else if(agt.indexOf("mozilla") != -1)
		{
			
			NNShowVersionInfo();
		}

	}

	function NNShowVersionInfo()
	{

		
		if (navigator.plugins && navigator.plugins["Adobe Acrobat"].description != "") 
		{
			
			//alert("found");

		}
		else
		{
		showWarning()		
		}
		
	}


	function IEShowVersionInfo()
	{
		// Call the ActiveX Object and get the Version Information
	var pdf = document.getElementById('Pdf1')
		var versionData = pdf.GetVersions();

		// Create an Array of all of the Plugin Names
		var versionDataArray = versionData.split(",");

		if (versionData!=null){
			//alert("found")
				showWarning()
		}else{
			showWarning()
		}
		
	}
	function showWarning(){
	    try{
	    document.getElementById('needAdobe').style.display='block';
	    }catch(err)
	    {
	    }
	}
	function ClearOrResetText(obj, txt) {
    if (obj.value == txt) {
      obj.value = '';
    }
    else if (obj.value == '') {
    obj.value = txt;
    }
  }
  
  function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}