/*-----------------------------------/
|	
	Name: site.js
	Author: AcroMedia Inc. (c) 2007 All Right Reserved. 
	Purpose:  JS Functions for WingSix
|  
+-----------------------------------*/

function copyrightYear(){
	if(document.getElementById('insertYear')) document.getElementById('insertYear').innerHTML = new Date().getFullYear();
}

function externalLinks(){
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external") anchors[i].target = "_blank";
		if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "chat46792138") anchors[i].target = "chat46792138";
	}
}

//Checks to see if safari is on, boolean
var detect = navigator.userAgent.toLowerCase();
var safStatus,thestring;
function checkSafari(){	
	if (checkIt('safari')) safStatus = true;
	else safStatus = false;
	function checkIt(string){
		place = detect.indexOf(string) + 1;
		return place;
	}
}

siteOnLoad = function (){
	checkSafari();
	copyrightYear();
	externalLinks();
}

function addLoadEvent(func){
	var oldOnLoad = window.onload;
	if(typeof window.onload != 'function'){ 
		window.onload = func;
	}
	else{ 
		window.onload = function(){ 
			oldOnLoad();
			func();
		}
	}
}

addLoadEvent(siteOnLoad);

//Functions to change top graphic to appear as "current" in the leftSide SubNav
function topToCur() {
	var pic = document.getElementById('topChange');
	pic.className = 'subNavTopCurrent';
}

function topToNorm() {
	var pic = document.getElementById('topChange');
	pic.className = 'subNavTop';
}

//Functions to make the little login div appear and dissapear like magic.
function showUsrLogin() {
	var loginRow = document.getElementById('loginRow');
	var divField = document.getElementById("newCustomerDiv");
	
	//IE & FF rendering differences, need error catch.
	try {
   	loginRow.style.display = "table-row";
	} 
	catch(e) {
   	loginRow.style.display = "block";
	}
	divField.style.display = "none";
}

function hideUsrLogin() {
	var divField = document.getElementById("newCustomerDiv");
	document.getElementById('loginRow').style.display = "none";
	divField.style.display = "block";	
}

//Functions to hide and show the cvv2 security code popup thingy m' jiggy
function showCVV2() {
	var theDiv = document.getElementById('secPop');
	theDiv.style.display = "block";
}

function hideCVV2() {
	var theDiv = document.getElementById('secPop');
	theDiv.style.display = "none";
}

//Auto Fill Payment Information if Checkbox == Checked
function autoFillPayInfo(field) {
	if (document.getElementById('infoSameCheck').checked == true) {
		var getId = field
		var xId = getId.substring(3);
		var newId = "ci_" + xId;
		document.getElementById(field).value = document.getElementById(newId).value;
		if (document.getElementById('pi_country')) {
			setIndex = document.getElementById('ci_country').selectedIndex;
			document.getElementById('pi_country').selectedIndex = setIndex;
		}
		if(document.getElementById(newId).className == 'error') {
			document.getElementById(newId).className = '';
		}		
	}
}

//Auto Fill Payment Info and Hide Fields
function hidePaymentFields() {
	if (document.getElementById('infoSameCheck').checked == true) {
		//Match Values
		document.getElementById('pi_fName').value = document.getElementById('ci_fName').value;
		document.getElementById('pi_lName').value = document.getElementById('ci_lName').value;
		document.getElementById('pi_address').value = document.getElementById('ci_address').value;
		document.getElementById('pi_city').value = document.getElementById('ci_city').value;
		document.getElementById('pi_stateProvince').value = document.getElementById('ci_stateProvince').value;
		document.getElementById('pi_zipPostal').value = document.getElementById('ci_zipPostal').value;
		setIndex = document.getElementById('ci_country').selectedIndex;
		document.getElementById('pi_country').selectedIndex = setIndex;

		//Hide Feilds
		document.getElementById('pi_fName').style.display = "none";
		document.getElementById('pi_lName').style.display = "none";
		document.getElementById('pi_address').style.display = "none";
		document.getElementById('pi_city').style.display = "none";
		document.getElementById('pi_stateProvince').style.display = "none";
		document.getElementById('pi_zipPostal').style.display = "none";
		document.getElementById('pi_country').style.display = "none";

		//Hide Rows
		document.getElementById('tr_pi_fName').style.display = "none";
		document.getElementById('tr_pi_lName').style.display = "none";
		document.getElementById('tr_pi_address').style.display = "none";
		document.getElementById('tr_pi_city').style.display = "none";
		document.getElementById('tr_pi_stateProvince').style.display = "none";
		document.getElementById('tr_pi_zipPostal').style.display = "none";
		document.getElementById('tr_pi_country').style.display = "none";
	}
}

//Erase Payment Info and Show Fields
function showPaymentFields() {
	if (document.getElementById('infoSameCheck').checked == false) {
		//Erase Values
		document.getElementById('pi_fName').value = "";
		document.getElementById('pi_lName').value = "";
		document.getElementById('pi_address').value = "";
		document.getElementById('pi_city').value = "";
		document.getElementById('pi_stateProvince').value = "";
		document.getElementById('pi_zipPostal').value = "";
		document.getElementById('pi_country').selectedIndex = 0;

		//Show Fields		
		document.getElementById('pi_fName').style.display = "block";
		document.getElementById('pi_lName').style.display = "block";
		document.getElementById('pi_address').style.display = "block";
		document.getElementById('pi_city').style.display = "block";
		document.getElementById('pi_stateProvince').style.display = "block";
		document.getElementById('pi_zipPostal').style.display = "block";
		document.getElementById('pi_country').style.display = "block";

		//Show Rows
		//IE & FF rendering differences, need error catch.
		try {
			document.getElementById('tr_pi_fName').style.display = "table-row";
			document.getElementById('tr_pi_lName').style.display = "table-row";
			document.getElementById('tr_pi_address').style.display = "table-row";
			document.getElementById('tr_pi_city').style.display = "table-row";
			document.getElementById('tr_pi_stateProvince').style.display = "table-row";
			document.getElementById('tr_pi_zipPostal').style.display = "table-row";
			document.getElementById('tr_pi_country').style.display = "table-row";
		}
		catch(e) {
			document.getElementById('tr_pi_fName').style.display = "block";
			document.getElementById('tr_pi_lName').style.display = "block";
			document.getElementById('tr_pi_address').style.display = "block";
			document.getElementById('tr_pi_city').style.display = "block";
			document.getElementById('tr_pi_stateProvince').style.display = "block";
			document.getElementById('tr_pi_zipPostal').style.display = "block";
			document.getElementById('tr_pi_country').style.display = "block";
		}
	}
}

//Toggle Payment Fields on and off
function toggleInfoSame() {
	if (document.getElementById('infoSameCheck').checked == false) {
		showPaymentFields();
		document.getElementById('infoSameCheck').checked == true;
	}
	if (document.getElementById('infoSameCheck').checked == true) {
		hidePaymentFields();
		document.getElementById('infoSameCheck').checked == false;
	}
}

//Toggle Over State for Host Package Boxes
function hostBoxOn(hBox) {
	var theBox = document.getElementById(hBox);
	theBox.className = "hostBoxTopOn";
}

function hostBoxOff(hBox) {
	var theBox = document.getElementById(hBox);
	theBox.className = "hostBoxTopOff";
}
