/* - - - - - - - - - - - - - - - - - - - - -

Title :  Common Javascript files
Author : Designkitchen, Inc.
URL : 

Description : contains common Dreamweaver scripts and a popup script

Created : 14.September.2005
Modified : 

- - - - - - - - - - - - - - - - - - - - - */

/*-----------------------------------------------------------
     ADD LOAD EVENT: allows multiple functions onload
    ---------------------------------------------------------*/
    
/* - - - - - - ADD LOAD EVENT - - - - - - - - */

function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
		} else{
			window.onload = function(){
				oldonload();
				func();
				}
			}
	
	}

/*-----------------------------------------------------------
     CHANGE FOCUS/CHANGE BLUR: resets input text 
     when users clicks in/out of input field
    ---------------------------------------------------------*/


function changeFocus(inputField){

	if (inputField.className.indexOf("searchTextbox") != -1){
	    inputValue = "Search IEG";
	}
	if (inputField.className.indexOf("subscribeEmail") != -1){
	    inputValue = "Enter Email Address";
	} 
	//if (inputField.className.indexOf("text") != -1){
	    //inputValue = "Search";
	    
	//}
	var currentValue = inputField.value;
	
	if (currentValue == ""){
		inputField.setAttribute("value",inputValue);
	} else if (currentValue == inputValue){
		inputField.setAttribute("value","");
	}
}
function changeBlur(inputField){
	if (inputField.className.indexOf("searchTextbox") != -1){
	    inputValue = "Search IEG";

	}
	if (inputField.className.indexOf("subscribeEmail") != -1){
	    inputValue = "Enter Email Address";
	}
	//if (inputField.className.indexOf("text") != -1){
	  //  inputValue = "Search";
	//}
	var currentValue = inputField.value;
		if (currentValue == ""){
		inputField.setAttribute("value",inputValue);
	} else if (currentValue == inputValue){
		inputField.setAttribute("value","");
	}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
/*
Auto center window script- Eric King (http://redrival.com/eak/index.shtml)
Permission granted to Dynamic Drive to feature script in archive
For full source, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/

// Ex. <a href="http://wsabstract.com" onclick="NewWindow(this.href,'name','400','400','yes');return false">Website Abstraction</a>
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}


function clickOpenWin() {
//define width and height of pop-up
var width = 480;
var height = 600;
//define location on screen for pop-up
var	xTop = (screen.width) ? (screen.width-width)/2 : 50;
var yTop = (screen.height) ? (screen.height-height)/2 : 200;
//launch pop-up window
window.open('printCoupon.aspx','','height='+height+',width='+width+',scrollbars=1,resizable=0,menubar=1,toolbar=0,status=0,location=0,directories=0,left=' + xTop + ',top=' + yTop + '');
}

function makePop(URL, clubID, var1, var2) {//FOR .NET
//define width and height of pop-up
var width = 600;
var height = 600;
//define location on screen for pop-up
var	xTop = (screen.width) ? (screen.width-width)/2 : 50;
var yTop = (screen.height) ? (screen.height-height)/2 : 200;
//launch pop-up window
window.open(URL,'','height='+height+',width='+width+',scrollbars=1,resizable=0,menubar=1,toolbar=0,status=0,location=0,directories=0,left=' + xTop + ',top=' + yTop + '');
}
function clickOpenWin() {//FOR TEMPLATES ONLY
//define width and height of pop-up
var width = 500;
var height = 600;
//define location on screen for pop-up
var	xTop = (screen.width) ? (screen.width-width)/2 : 50;
var yTop = (screen.height) ? (screen.height-height)/2 : 200;
//launch pop-up window
window.open('printCoupon.aspx','','height='+height+',width='+width+',scrollbars=1,resizable=0,menubar=1,toolbar=0,status=0,location=0,directories=0,left=' + xTop + ',top=' + yTop + '');
}
function clickOpenWin2() {//FOR TEMPLATES ONLY
//define width and height of pop-up
var width = 780;
var height = 500;
//define location on screen for pop-up
var	xTop = (screen.width) ? (screen.width-width)/2 : 50;
var yTop = (screen.height) ? (screen.height-height)/2 : 200;
//launch pop-up window
window.open('printPFP.aspx?pfppage=printPage','','height='+height+',width='+width+',scrollbars=1,resizable=0,menubar=1,toolbar=0,status=0,location=0,directories=0,left=' + xTop + ',top=' + yTop + '');
}

function caseRollover(id)
{
    caseDiv = document.getElementById(id);
    caseDiv.style.backgroundColor = "#faffe1";
    //cursor change added 7/11/07, KM 
    caseDiv.style.cursor = "pointer";
}

function caseRolloff(id)
{
    caseDiv = document.getElementById(id);
    caseDiv.style.backgroundColor = "White";
    //caseDiv.style.cursor = "auto";
}

function submitEnter(myField,e)
{
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;

    var strText = myField;
    if (keycode == 13)
    {
       if (strText != "Search IEG")
       {
        window.location = "/Search.aspx?SearchText=" + escape(strText).replace("&","%26");
        return false;
       }
       else
       {
        return false;
       }
    }
   else
   {
        return true;
   }


}

function GetSearch(mode)
{
    var searchInput = document.getElementsByTagName("input");
    
    for (var i = 0; i < searchInput.length; i++)
    {
        if (searchInput[i].name == "globalSearch")
        {
            var searchBox = searchInput[i];
            var searchText = searchInput[i].value;
            break;
        }
    }
    
    if (mode == "IEGSR")
        searchPage = "/IEGSR/Search.aspx";
    else
        searchPage = "/Search.aspx";
        
    if ( searchText == "Search IEG")
    {
        searchBox.value = "";
        window.location = searchPage;
    }
    else
    {
        window.location = searchPage + "?SearchText=" + escape(searchText).replace("&","%26");
    }
}

// Common cookie functions
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
var x = readCookie('IEGhome')
if (x) {
 randomnumber=x;
} else {
 var randomnumber = Math.floor(Math.random()*3) + 1; // to cover range 1 to 3
 createCookie('IEGhome',randomnumber,0);
}

function addOnChange()
{
    if (document.getElementById("sector"))
    {
        var divSector = document.getElementById("sector");
        var arrSelect = divSector.getElementsByTagName("select");
        
        var sector = arrSelect[0];
        
        sector.onchange = function(){subsectorDisplay(this.value);}
    }
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function subsectorDisplay(value)
{
    var subAgency = document.getElementById("subAgency");
    var subConsultant = document.getElementById("subConsultant");
    var subGovt = document.getElementById("subGovt");
    var subMedia = document.getElementById("subMedia");
    var subProp = document.getElementById("subProp");
    var subSponsor = document.getElementById("subSponsor");
    var subSupplier = document.getElementById("subSupplier");
    
    var arrAgency = subAgency.getElementsByTagName("select");
    var arrConsultant = subConsultant.getElementsByTagName("select");
    var arrGovt = subGovt.getElementsByTagName("select");
    var arrMedia = subMedia.getElementsByTagName("select");
    var arrProp = subProp.getElementsByTagName("select");
    var arrSponsor = subSponsor.getElementsByTagName("select");
    var arrSupplier = subSupplier.getElementsByTagName("select");
    
    var selAgency = arrAgency[0];
    var selConsultant = arrConsultant[0];
    var selGovt = arrGovt[0];
    var selMedia = arrMedia[0];
    var selProp = arrProp[0];
    var selSponsor = arrSponsor[0];
    var selSupplier = arrSupplier[0];
    
    switch(trim(value).toLowerCase())
    {
        case "agency":
            subAgency.style.display = "block";
            subConsultant.style.display = "none";
            subGovt.style.display = "none";
            subMedia.style.display = "none";
            subProp.style.display = "none";
            subSponsor.style.display = "none";
            subSupplier.style.display = "none";
            
            selAgency.options[0].selected = true;
            selConsultant.options[0].selected = true;
            selGovt.options[0].selected = true;
            selMedia.options[0].selected = true;
            selProp.options[0].selected = true;
            selSponsor.options[0].selected = true;
            selSupplier.options[0].selected = true;
            break;
        case "consultant":
            subAgency.style.display = "none";
            subConsultant.style.display = "block";
            subGovt.style.display = "none";
            subMedia.style.display = "none";
            subProp.style.display = "none";
            subSponsor.style.display = "none";
            subSupplier.style.display = "none";
            
            selAgency.options[0].selected = true;
            selConsultant.options[0].selected = true;
            selGovt.options[0].selected = true;
            selMedia.options[0].selected = true;
            selProp.options[0].selected = true;
            selSponsor.options[0].selected = true;
            selSupplier.options[0].selected = true;
            break;
        case "government":
            subAgency.style.display = "none";
            subConsultant.style.display = "none";
            subGovt.style.display = "block";
            subMedia.style.display = "none";
            subProp.style.display = "none";
            subSponsor.style.display = "none";
            subSupplier.style.display = "none";
            
            selAgency.options[0].selected = true;
            selConsultant.options[0].selected = true;
            selGovt.options[0].selected = true;
            selMedia.options[0].selected = true;
            selProp.options[0].selected = true;
            selSponsor.options[0].selected = true;
            selSupplier.options[0].selected = true;
            break;
        case "media":
            subAgency.style.display = "none";
            subConsultant.style.display = "none";
            subGovt.style.display = "none";
            subMedia.style.display = "block";
            subProp.style.display = "none";
            subSponsor.style.display = "none";
            subSupplier.style.display = "none";
            
            selAgency.options[0].selected = true;
            selConsultant.options[0].selected = true;
            selGovt.options[0].selected = true;
            selMedia.options[0].selected = true;
            selProp.options[0].selected = true;
            selSponsor.options[0].selected = true;
            selSupplier.options[0].selected = true;
            break;
        case "property":
            subAgency.style.display = "none";
            subConsultant.style.display = "none";
            subGovt.style.display = "none";
            subMedia.style.display = "none";
            subProp.style.display = "block";
            subSponsor.style.display = "none";
            subSupplier.style.display = "none";
            
            selAgency.options[0].selected = true;
            selConsultant.options[0].selected = true;
            selGovt.options[0].selected = true;
            selMedia.options[0].selected = true;
            selProp.options[0].selected = true;
            selSponsor.options[0].selected = true;
            selSupplier.options[0].selected = true;
            break;
        case "sponsor":
            subAgency.style.display = "none";
            subConsultant.style.display = "none";
            subGovt.style.display = "none";
            subMedia.style.display = "none";
            subProp.style.display = "none";
            subSponsor.style.display = "block";
            subSupplier.style.display = "none";
            
            selAgency.options[0].selected = true;
            selConsultant.options[0].selected = true;
            selGovt.options[0].selected = true;
            selMedia.options[0].selected = true;
            selProp.options[0].selected = true;
            selSponsor.options[0].selected = true;
            selSupplier.options[0].selected = true;
            break;
        case "supplier":
            subAgency.style.display = "none";
            subConsultant.style.display = "none";
            subGovt.style.display = "none";
            subMedia.style.display = "none";
            subProp.style.display = "none";
            subSponsor.style.display = "none";
            subSupplier.style.display = "block";
            
            selAgency.options[0].selected = true;
            selConsultant.options[0].selected = true;
            selGovt.options[0].selected = true;
            selMedia.options[0].selected = true;
            selProp.options[0].selected = true;
            selSponsor.options[0].selected = true;
            selSupplier.options[0].selected = true;
            break;
        default:
            subAgency.style.display = "none";
            subConsultant.style.display = "none";
            subGovt.style.display = "none";
            subMedia.style.display = "none";
            subProp.style.display = "none";
            subSponsor.style.display = "none";
            subSupplier.style.display = "none";
            
            selAgency.options[0].selected = true;
            selConsultant.options[0].selected = true;
            selGovt.options[0].selected = true;
            selMedia.options[0].selected = true;
            selProp.options[0].selected = true;
            selSponsor.options[0].selected = true;
            selSupplier.options[0].selected = true;
            break;
    }
}

addLoadEvent(addOnChange);

