
// determine if browser is capable of image swaps

//

var supported = 0;

if ( ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3)) ||
	 ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) > 3)) )
	 supported = 1;



// update the browser's bottom status bar with specified text
function dispStatus(text)
{
	if (supported) {
		window.status = text;
	}
}



// preload Nav images
var numNav = 15;
var NavImages = new Array(numNav * 3);

function addNav(index, width, height, stat, strImage)
{
	if (supported)
	{
		var on = stat * numNav;
		NavImages[index + on] = new Image(width, height);
		NavImages[index + on].src = strImage;
	}
}


addNav(1,70,15,0, pre_dir + 'images-pnav/pnav_company.gif');
addNav(2,110,15,0, pre_dir + 'images-pnav/pnav_news___events.gif');
addNav(3,72,15,0, pre_dir + 'images-pnav/pnav_products.gif');
addNav(4,74,15,0, pre_dir + 'images-pnav/pnav_customers___solutions.gif');
addNav(5,69,15,0, pre_dir + 'images-pnav/pnav_partners.gif');
addNav(6,65,15,0, pre_dir + 'images-pnav/pnav_support.gif');
addNav(7,45,15,0, pre_dir + 'images-pnav/pnav_jobs.gif');
addNav(8,20,20,0, pre_dir + 'images-pnav/transpix.gif');
addNav(9,20,20,0, pre_dir + 'images/transpix.gif');
addNav(10,20,20,0, pre_dir + 'pnav-images/transpix.gif');
addNav(11,20,20,0, pre_dir + 'pnav-images/transpix.gif');
addNav(12,20,20,0, pre_dir + 'pnav-images/transpix.gif');
addNav(13,20,20,0, pre_dir + 'pnav-images/transpix.gif');
addNav(14,20,20,0, pre_dir + 'pnav-images/transpix.gif');
addNav(15,20,20,0, pre_dir + 'pnav-images/transpix.gif');

addNav(1,70,15,1, pre_dir + 'images-pnav/pnav_company_on.gif');
addNav(2,110,15,1, pre_dir + 'images-pnav/pnav_news___events-on.gif');
addNav(3,72,15,1, pre_dir + 'images-pnav/pnav_products_on.gif');
addNav(4,74,15,1, pre_dir + 'images-pnav/pnav_customers___solutions-on.gif');
addNav(5,69,15,1, pre_dir + 'images-pnav/pnav_partners_on.gif');
addNav(6,65,15,1, pre_dir + 'images-pnav/pnav_support_on.gif');
addNav(7,45,15,1, pre_dir + 'images-pnav/pnav_jobs_on.gif');
addNav(8,20,20,1, pre_dir + 'images-pnav/transpix.gif');
addNav(9,20,20,1, pre_dir + 'images-pnav/transpix.gif');
addNav(10,20,20,1, pre_dir + 'pnav-images/transpix.gif');
addNav(11,20,20,1, pre_dir + 'pnav-images/transpix.gif');
addNav(12,20,20,1, pre_dir + 'pnav-images/transpix.gif');
addNav(13,20,20,1, pre_dir + 'pnav-images/transpix.gif');
addNav(14,20,20,1, pre_dir + 'pnav-images/transpix.gif');
addNav(15,20,20,1, pre_dir + 'pnav-images/transpix.gif');



addNav(8,20,20,2, pre_dir + 'images/transpix.gif');
addNav(9,20,20,2, pre_dir + 'images/transpix.gif');
addNav(10,20,20,2, pre_dir + 'images/transpix.gif');
addNav(11,20,20,2, pre_dir + 'images/transpix.gif');
addNav(12,20,20,2, pre_dir + 'images/transpix.gif');
addNav(13,20,20,2, pre_dir + 'images/transpix.gif');
addNav(14,20,20,2, pre_dir + 'images/transpix.gif');
addNav(15,20,20,2, pre_dir + 'images/transpix.gif');

// each rollover Nav has: name=NavX; where X indicates its index

function nav_rollover (index, action, section)
{
	// test for 14<=index<=10 
	if (index >= 15 && index<=10)
	{
		if (active_num == index && action == 0)
		{
			action = 2;
		}
	}
	if (supported) {
		if (section == current_section)
		{
			//document.images["nav" + index].src = NavImages[index].src;
		} else {
			document.images["nav" + index].src = NavImages[index + (numNav * action)].src;
		}
	}
}
	

function navUpdate(index)
{
	if (supported) {
		document.images["nav" + active_num].src = NavImages[active_num + (numNav * 0)].src;
	}
	active_num = index;
	if (supported) {
		document.images["nav" + index].src = NavImages[index + (numNav * 2)].src;
	}
	
}

state = 0;
function dateview() 
{
	switch (state) 
	{
		// off
		case 0:  nav_rollover(9,1, 'DATE VIEW'); 
		   popUp('elMenu8',event);
		   dispStatus('DATE VIEW');
		   break;
		
		// on
		case 1: nav_rollover(9,0, 'DATE VIEW'); 
		   popDownClick('elMenu8',event);
		   dispStatus('DATE VIEW');
		   break;
	}
	if (state==0)
	{
		state++;
	} else {
		state=0;
	}
}	

var windowIsOpen = "false";
// open new window
function openWindow(url, w, h) {
  popupWin = window.open(url, 'window', 'resizable=yes,scrollbars=yes,menubar=no,location=no,directories=no,status=no,menubar=no,width=' + w + ',height=' + h);
  windowIsOpen = "true";
}

/**
* In this function we want to accomplish the following 
* 1. Change the classname of the container div to the "Open" version
* 2. swap images of the triangle from "closed" to "open"
* 3. change the innerHTML of the btn is modify the onclick event attribute and swap images from "plus" to "minus"
* 4. Perform an expand transition on the form
**/
function expandForm(tgt, evt) {
    var parent, btn, header, container;
    if (tgt.parentNode) {
        btn = tgt.parentNode;
        parent = btn.parentNode;
    }       
    //1. 
    if (parent.className == "so-formPanel") {
        parent.className = "so-formPanelOpen";     
    }    
    //2. 
    header = first_child(parent);
    if (header.className == "so-formhead") {    
        //header.innerHTML = <img class="btn_tri" src="../images/btns/btn_tri_closed.gif" alt="open form" />&nbsp; PSTN termination and/or orginiation
        header.innerHTML = header.innerHTML.replace("btn_tri_closed.gif", "btn_tri_opened.gif");
    }
       
    //use modified whitespace-friendly functions (instead of container = btn.nextSibling;)
    container = node_after(btn);
    //cycle through all sibling containers in case of adjustment of the HTML structure.
    while (container && container.className != 'so-formContainer') {
        container = node_after(container);
    }
    
    if (container.className == 'so-formContainer') {
        //3.
        btn.innerHTML = "<a class=\"btnlink\" onclick=\"collapseForm(this, event)\" href=\"javascript:void(0);\"><img class=\"btnlink\" src=\"../images/btns/btn_minus.gif\" alt=\"open form\" /></a>";
        //4.
        new Effect.BlindDown(container);
    }
    
}

function collapseForm(tgt, evt) {
    var parent, btn, header, container;
    if (tgt.parentNode) {
        btn = tgt.parentNode;
        parent = btn.parentNode;
    } 
    //2.
    header = first_child(parent);
    if (header.className == "so-formhead") {    
        //header.innerHTML = <img class="btn_tri" src="../images/btns/btn_tri_closed.gif" alt="open form" />&nbsp; PSTN termination and/or orginiation
        header.innerHTML = header.innerHTML.replace("btn_tri_opened.gif", "btn_tri_closed.gif");
    } 
       
    container = node_after(btn);
    //cycle through all sibling nodes in the tree until we find the container div...
    while (container && container.className != 'so-formContainer') {
        container = node_after(container);
    }
    if (container.className == 'so-formContainer') {
        //3.
        btn.innerHTML = "<a class=\"btnlink\" onclick=\"expandForm(this, event)\" href=\"javascript:void(0);\"><img class=\"btnlink\" src=\"../images/btns/btn_plus.gif\" alt=\"open form\" /></a>";
        //4.
        //new Effect.BlindUp(container, {afterFinish: handleCollapse(parent)});
        container.style.display = "none";
        handleCollapse(parent);
    }
}

//Handle Collapse is FF / Safari compatible
function handleCollapse(parent) {
    if (parent.className == "so-formPanelOpen") {
        parent.className = "so-formPanel";
    }
}

//this function should dispose our event handler and register a new one for the form
//should be IE compliant
function handleExpand(btn) {

}

/* ------------------------ BEGIN GEOGRAPHY POPUP HELPER FUNCTIONS ------------------ */

//event handler if user clicks on the Region Name in the Service / Offerings form
var handleRegionClick = function (tgt) {
    var myElem, pattern, chkElem;
    var chkbox = "CUgeochk-";
    
    //format of id is CUsomename-n where 'n' is a dumb counter that increases with each new element. 
    //checkboxes and name <span> elements should be in lockstep with their n value, making it easy to trace back to the checkbox
    myElem = tgt.id.split("-");
    chkbox += myElem[1];
    chkElem = document.getElementById(chkbox);
    
    //if (!chkElem.checked) {
        //chkElem.checked = true;
    //}
    
    showGeoPopup(chkElem);
}

var handleRegionCheck = function (tgt) {
    if (tgt.checked) {
        //showGeoPopup(tgt);
    }
}

//in this function we want to spin through all the fucking countries
//and the fucking states that the user put into their fucking myCountries[] and myStates[]
//and "post" it back to the main form to display the names along with value of the id's for those locations
var captureGeography = function () {
    var states, countries, myChk, myRegion;
    
    countries = document.forms["geoForm"].elements["myCountries[]"];
    states = document.forms["geoForm"].elements["myStates[]"];
    myChk = document.forms["geoForm"].elements["myGeoDialogue"].value;
    myRegion = document.forms["geoForm"].elements["myGeoRegion"].value;
    
    YAHOO.geoChooser.container.dialog1.hide();
    
    var reg, comma = 0, cntry, curCntry, curState, strIDs = "", strNames = "";
    for (var i=0; i<countries.length; i++) {
        curCntry = countries[i].value;
        strIDs += curCntry;
        
        for (var j=0; j<arCountries.length; j++) {  
            if (arCountries[j]['id'] == myRegion) {
                reg = j;
                for (var k=0; k<arCountries[j]['children'].length; k++) {
                    //alert(arCountries[j]['children'][k]['name']);
                    if (arCountries[j]['children'][k]['id'] == curCntry) {
                        cntry = k;
                        strNames += arCountries[j]['children'][k]['name'];
                    }
                }
            }
        }
        
        for (var j=0; j<states.length; j++) {
            curState = states[j].value;
            
            for (var k=0; k < arCountries[reg]['children'][cntry]['children'].length; k++) {
                if (arCountries[reg]['children'][cntry]['children'][k]['id'] == curState) {
                    //alert("match found");
                    //write out country and state
                    strIDs += ',' + curState;
                    strNames += ', ' + arCountries[reg]['children'][cntry]['children'][k]['name'];
                    comma++;
                }
            }
        }
        if ((countries.length + states.length) - comma > 1) {
            strIDs += ',';
            strNames += '; ';
            comma++;
        }
    }
    
    //check of the checkbox on the main form
    var elem
    elem = document.getElementById(myChk);
    if (!elem.checked) {elem.checked = true;}
    
    writeGeo(strIDs, strNames, myChk);    
}

var clearGeography = function (mode) {
    if (mode == 'reset') {
        curLocs = document.forms["geoForm"].elements["myCountries[]"];
        while (curLocs.firstChild) {
            curLocs.removeChild(curLocs.firstChild);
        }        
        curLocs = document.forms["geoForm"].elements["myStates[]"];
        while (curLocs.firstChild) {
            curLocs.removeChild(curLocs.firstChild);
        }
    } else { 
        curLocs = document.forms["geoForm"].elements["allCountries[]"];
        while (curLocs.firstChild) {
            curLocs.removeChild(curLocs.firstChild);
        }
        
        curLocs = document.forms["geoForm"].elements["myCountries[]"];
        while (curLocs.firstChild) {
            curLocs.removeChild(curLocs.firstChild);
        }
        
        curLocs = document.forms["geoForm"].elements["allStates[]"];
        while (curLocs.firstChild) {
            curLocs.removeChild(curLocs.firstChild);
        }
        
        curLocs = document.forms["geoForm"].elements["myStates[]"];
        while (curLocs.firstChild) {
            curLocs.removeChild(curLocs.firstChild);
        }
    }  
}

var writeGeo = function (ids, names, tgt) {

    var pos, myElem, hiddenNode, iNode, txtNode, myValue;
    var myCell = 'CUgeochosen-';
    var myData = 'CUgeovalue-';
    
    pos = tgt.split("-");
    myCell += pos[1];
    myData += pos[1];
    
   
    
    myValue = document.getElementById(myData);    
    myElem = document.getElementById(myCell);
    
    //clear out old info just in case.
    while (myElem.firstChild) {
        myElem.removeChild(myElem.firstChild);
    }
    
    hiddenNode = document.createElement("input");
    iNode = document.createElement("i");
    txtNode = document.createTextNode(names);
    
    hiddenNode.type = "hidden";
    hiddenNode.value = ids;
    hiddenNode.name = "CUgeography-hidden";
    
    myElem.appendChild(hiddenNode);
    myElem.appendChild(iNode);
    myElem.appendChild(txtNode);
    
    myValue.value = ids;
   
   
   
}

var showGeoPopup = function (regionChk) {
    //alert(tgt);
    var elem, myRegion;
    
    //remove existing options from the popup
    clearGeography("all");
    
    //store the checkbox id in my "hidden field value" this is important for later to be able to insert my values back into the form.
    elem = document.getElementById("myGeoDialogue");
    elem.value = regionChk.id;
    
    //store the fucking region id in another hidden field
    elem = document.getElementById("myGeoRegion");
    elem.value = regionChk.value;
    
    //show the geo popup and load with data
    YAHOO.geoChooser.container.dialog1.show();
    showCountries(regionChk.value);
}

var removeLoc = function(e) {
    //alert(this.id + " you've removed a country");
    var type, allLocs, myLocs; 
    
    type = this.id.split("_");
    
    switch(type[0]) { 
        case 'country':
            allLocs = document.forms["geoForm"].elements["allCountries[]"];
            myLocs = document.forms["geoForm"].elements["myCountries[]"];
            break;
        case 'state':
            allLocs = document.forms["geoForm"].elements["allStates[]"];
            myLocs = document.forms["geoForm"].elements["myStates[]"];
            break;
        default:
            alert("not found");
            break;   
    }
           
    for (var i=0;i < myLocs.length; i++) {
        var tmpLoc = myLocs[i];
        
        if (tmpLoc.selected){
            myLocs.removeChild(tmpLoc);
        }
    }
};

var addLoc = function(e) {
    //alert(this.id + " you've added a country");
    var type, allLocs, myLocs, cloneNd; 
    
    type = this.id.split("_");
    
    switch(type[0]) { 
        case 'country':
            allLocs = document.forms["geoForm"].elements["allCountries[]"];
            myLocs = document.forms["geoForm"].elements["myCountries[]"];
            break;
        case 'state':
            allLocs = document.forms["geoForm"].elements["allStates[]"];
            myLocs = document.forms["geoForm"].elements["myStates[]"];
            break;
        default:
            alert("not found");
            break;   
    }
    
    var cloneNd;
    for (var i=0;i < allLocs.length; i++) {
        var tmpLoc = allLocs[i];
        
        if (tmpLoc.selected){
            cloneNd = tmpLoc.cloneNode(true);                
        }            
        //check to make sure this location hasn't been already added
        
        var locFound = false;
        if (cloneNd != null) {
            for (var j=0; j < myLocs.length; j++) {
                if (cloneNd.value == myLocs[j].value) {
                    locFound = true;
                }
            }
            
            //append the new node to myLocs if not found
            if (!locFound) {
                myLocs.appendChild(cloneNd);    
            }       
        }
         
    }
};

var clearLocs = function(e) {
    var type, allLocs, myLocs, cloneNd; 
    
    type = this.id.split("_");
    
    switch(type[0]) { 
        case 'country':
            myLocs = document.forms["geoForm"].elements["myCountries[]"];
            break;
        case 'state':
            myLocs = document.forms["geoForm"].elements["myStates[]"];
            break;
        default:
            alert("not found");
            break;   
    }
    
    while (myLocs.firstChild) {
        myLocs.removeChild(myLocs.firstChild);
    }

}

//show available countires in the select input
var showCountries = function (region) {
    var allCountries, curCntry, nodeOption;
    //alert(region);
    allCountries = document.forms["geoForm"].elements["allCountries[]"];
    
    for (var i=0; i < arCountries.length; i++) {
        if (arCountries[i]['id'] == region) {
            for (var j=0; j < arCountries[i]['children'].length; j++) {
                nodeOption = document.createElement('option');
                nodeOption.value = arCountries[i]['children'][j]['id'];
                nodeOption.innerHTML = arCountries[i]['children'][j]['name'];
                allCountries.appendChild(nodeOption);
            }
        }
    }
}

//event handler wrapper for showStates function
var showStatesHandler = function (e) {
    showStates();
}

//display the states
var showStates = function () {
    //alert("show some states");
    var allCountries, curCntry, allStates, nodeOption;
    
    allCountries = document.forms["geoForm"].elements["allCountries[]"];
    allStates = document.forms["geoForm"].elements["allStates[]"];
    
    for (var i=0; i<allCountries.length; i++) {
        
        if (allCountries[i].selected) {
            curCntry = allCountries[i];
        }
    }
    //delete existing states
    while (allStates.firstChild) {
        allStates.removeChild(allStates.firstChild);
    }
    
    //alert(curCntry.value);
    for (var i=0; i<arCountries.length; i++) {
        
        for (var j=0; j<arCountries[i]['children'].length; j++) {
            if (curCntry.value == arCountries[i]['children'][j]['id']) {
                //show my states & provinces in the form
                for (var n=0; n < arCountries[i]['children'][j]['children'].length; n++) {
                    nodeOption = document.createElement('option');
                    nodeOption.value = arCountries[i]['children'][j]['children'][n]['id'];
                    nodeOption.innerHTML = arCountries[i]['children'][j]['children'][n]['name'];
                    allStates.appendChild(nodeOption);
                }
            }
        }
    }
}	



function handleServiceUpdate(obj, fieldname, formname)
{
	//alert(fieldname + " / " + formname);
	if (obj.selectedIndex != 0)
	{
		newId = obj.options[obj.selectedIndex].value;

		document.forms[formname].elements["firstname" + fieldname].value = arUsers[newId]["firstname"];
		document.forms[formname].elements["lastname" + fieldname].value = arUsers[newId]["lastname"];
		document.forms[formname].elements["title" + fieldname].value = arUsers[newId]["title"];
		document.forms[formname].elements["phone" + fieldname].value = arUsers[newId]["phone"];
		document.forms[formname].elements["extension" + fieldname].value = arUsers[newId]["extension"];
		document.forms[formname].elements["mobilephone" + fieldname].value = arUsers[newId]["mobilephone"];
		document.forms[formname].elements["email" + fieldname].value = arUsers[newId]["email"];
	} else {
	
		document.forms[formname].elements["firstname" + fieldname].value = "";
		document.forms[formname].elements["lastname" + fieldname].value = "";
		document.forms[formname].elements["title" + fieldname].value = "";
		document.forms[formname].elements["phone" + fieldname].value = "";
		document.forms[formname].elements["extension" + fieldname].value = "";
		document.forms[formname].elements["mobilephone" + fieldname].value = "";
		document.forms[formname].elements["email" + fieldname].value = "";
	}	
	
}


/* ------------------------ END GEOGRAPHY POPUP ------------------ */



/* --- BEGIN contact div popups --- */
	var curNote, mX, mY;


	function showMsg(evt, strheader, msg, cid)
	{
		if (curNote)
			curNote.style.display = "none";

	   if (navigator.appName == "Microsoft Internet Explorer"){
		mX = event.clientX;
		mY = event.clientY;
	  }
	  else {
		mX = evt.pageX;
		mY = evt.pageY;
	  }


		//var obj = this;
		var startX = mX + Geometry.getHorizontalScroll() - 125;
		var startY = mY + Geometry.getVerticalScroll() - 75;

		//var startX = mX;
		//var startY = mY;

		myDiv = document.createElement("div");
		myDiv.id = "popupWindow";
		myDiv.className = "popup";
		myDiv.style.top = startY + "px";
		myDiv.style.left = startX + "px";

		document.body.appendChild(myDiv);

		strInner = "<div class='closeWindow'><a href='javascript:void(0);' onClick='killMsg();'>close <img src='/images/btns/btn_close_red.gif' alt='' width='11' height='12' border='0'></a></div><br clear='all'/>";
		strInner += "<div class='popupContent'><span class='popupHeader'>" + strheader + "</span><br>" + msg + "</div><iframe width='0' height='0' src='contact.asp?id=" + cid + "'></iframe>";
		//alert(strInner);
		myDiv.innerHTML = strInner;

		curNote = myDiv;
	}


	function showMsgXY(evt, strheader, msg, cid, dx, dy)
	{
		if (curNote)
			curNote.style.display = "none";

	   if (navigator.appName == "Microsoft Internet Explorer"){
		mX = event.clientX;
		mY = event.clientY;
	  }
	  else {
		mX = evt.pageX;
		mY = evt.pageY;
	  }


		//var obj = this;
		var startX = mX + Geometry.getHorizontalScroll() - 125 + dx;
		var startY = mY + Geometry.getVerticalScroll() - 75 + dy;

		//var startX = mX;
		//var startY = mY;

		myDiv = document.createElement("div");
		myDiv.id = "popupWindow";
		myDiv.className = "popup";
		myDiv.style.top = startY + "px";
		myDiv.style.left = startX + "px";

		document.body.appendChild(myDiv);

		strInner = "<div class='closeWindow'><a href='javascript:void(0);' onClick='killMsg();'>close <img src='/images/btns/btn_close_red.gif' alt='' width='11' height='12' border='0'></a></div><br clear='all'/>";
		strInner += "<div class='popupContent'><span class='popupHeader'>" + strheader + "</span><br>" + msg + "</div><iframe width='0' height='0' src='contact.asp?id=" + cid + "'></iframe>";
		//alert(strInner);
		myDiv.innerHTML = strInner;

		curNote = myDiv;
	}


	function killMsg(token)
	{
		curNote.style.display = "none";
	}




	function handle(obj)
	{
		var strUrl = obj.options[obj.selectedIndex].value;

		setTimeout("location.href = '" + strUrl + "';", 100);
	}




//</DATASRC>
// -->
// -->
