﻿if (typeof( window[ 'cacheLoc' ] )== "undefined" ) {
	//var cacheLoc = "http://akwww.digidesign.com";
	var cacheLoc = "";
}

/* button swapping JS */

var button = cacheLoc + "/images/buttons/btn_grey_m.gif";
var button_l = cacheLoc + "/images/buttons/btn_grey_l.gif";
var button_r = cacheLoc + "/images/buttons/btn_grey_r.gif";

var button_on = cacheLoc + "/images/buttons/btn_grey_m_on.gif";
var button_l_on = cacheLoc + "/images/buttons/btn_grey_l_on.gif";
var button_r_on = cacheLoc + "/images/buttons/btn_grey_r_on.gif";

var button2 = cacheLoc + "/images/buttons/btn_red_m.gif";
var button2_l = cacheLoc + "/images/buttons/btn_red_l.gif";
var button2_r = cacheLoc + "/images/buttons/btn_red_r.gif";

var button2_on = cacheLoc + "/images/buttons/btn_red_m_on.gif";
var button2_l_on = cacheLoc + "/images/buttons/btn_red_l_on.gif";
var button2_r_on = cacheLoc + "/images/buttons/btn_red_r_on.gif";

var button3 = cacheLoc + "/images/buttons/btn_blue_m.gif";
var button3_l = cacheLoc + "/images/buttons/btn_blue_l.gif";
var button3_r = cacheLoc + "/images/buttons/btn_blue_r.gif";

var button3_on = cacheLoc + "/images/buttons/btn_blue_m_on.gif";
var button3_l_on = cacheLoc + "/images/buttons/btn_blue_l_on.gif";
var button3_r_on = cacheLoc + "/images/buttons/btn_blue_r_on.gif";

var arrow_down = new Image();
arrow_down.src = cacheLoc + "/images/arrows/right.gif";
var arrow_up = new Image();
arrow_up.src = cacheLoc + "/images/arrows/down.gif";
//var arrow_hover = new Image();
//arrow_hover.src = cacheLoc + "/images/arrows/arrow_dwn_on.gif";
var digi_up= new Image();
digi_up.src = cacheLoc + "/images/digi_logo_nrml.jpg";
var digi_hover = new Image();
digi_hover.src = cacheLoc + "/images/digi_logo_over.jpg";

function swapLogo(on) {
	var logo = document.getElementById("digilogo");
	//alert(logo.src);
	if (on) {
		logo.src = digi_hover.src;
	}
	else {
		logo.src = digi_up.src;
	}
}


function swapButton(btnName,on,btnType) {
	var btnL_on, btn_on, btnR_on, btnL, btn, btnR, imgL, img, imgR, imgL_on, img_on, imgR_on, nodeL, node, nodeR;
	
	/* String names for buttons */
	btnL_on = [btnType + "_l_on"];
	btn_on = [btnType + "_on"];
	btnR_on = [btnType + "_r_on"];
	btnL = [btnType + "_l"];
	btn = btnType;
	btnR = [btnType + "_r"];
	imgL = window[btnL];
	img = window[btn];
	imgR = window[btnR];
	imgL_on = window[btnL_on];
	img_on = window[btn_on];
	imgR_on = window[btnR_on];
	nodeL = document.getElementById("btnL" + btnName);
	node = document.getElementById("btn" + btnName);
	nodeR = document.getElementById("btnR" + btnName);
	
	/* Set default button styles using string names referenced from  the global object window */ 
	nodeL.style.backgroundImage = "url(" + imgL + ")";
	node.style.backgroundImage = "url(" + img + ")";
	nodeR.style.backgroundImage = "url(" + imgR + ")";
		
	nodeL.style.backgroundPosition = "left";
	nodeL.style.backgroundRepeat = "no-repeat";
	nodeL.style.backgroundAttachment = "scroll";
	
	node.style.backgroundPosition = "top left";
	node.style.backgroundRepeat = "repeat-x";
	node.style.backgroundAttachment = "scroll";
	
	nodeR.style.backgroundPosition = "right";
	nodeR.style.backgroundRepeat = "no-repeat";
	nodeR.style.backgroundAttachment = "scroll";
	
	/* Change style on hover and revert to original otherwise */
	if (on) {
		nodeL.style.backgroundImage = "url(" + imgL_on + ")";	
		node.style.backgroundImage = "url(" + img_on + ")";
		nodeR.style.backgroundImage = "url(" + imgR_on + ")";	
	}
	else {
		nodeL.style.backgroundImage = "url(" + imgL + ")";
		node.style.backgroundImage = "url(" + img + ")";
		nodeR.style.backgroundImage = "url(" + imgR + ")";
	}
}

/* expand functions */
function showExpand(title,objToShow,expandGroup) {
	var nScrollHeight = document.getElementById(objToShow).scrollHeight;
	var nActualHeight = document.getElementById(objToShow).offsetHeight;
	var arrow = "arrow_" + title.split("_")[5];
	if (nActualHeight < nScrollHeight) {
		sizeObjV(objToShow,nScrollHeight,"null");
		document.getElementById(title).className = "expand-selected";
		document.getElementById(arrow).src = arrow_up.src;
	}
	else {
		sizeObjV(objToShow,5,"null");
		document.getElementById(title).className = "expand-normal";
		document.getElementById(arrow).src = arrow_down.src;
	}
}

function hoverExpand(title,hover) {
	if (document.getElementById(title).className != "expand-selected"){
		var arrow = "arrow_" + title.split("_")[5];
		if (hover) { 
			document.getElementById(title).className = "expand-hover";
			//document.getElementById(arrow).src = arrow_hover.src;
		}
		else { 
			document.getElementById(title).className = "expand-normal";
			//document.getElementById(arrow).src = arrow_down.src;
		}
	}
}

function sizeObjV(objToShow,showSize,completeFunction) {
	//completeFunction should take format: null OR {complete:function() {setStatus('done fading element.',1500);}} 
	new Rico.Effect.Size(document.getElementById(objToShow),null,showSize,20,10,completeFunction);	
}

function sizeObjH(objToShow,showSize,completeFunction) {
	//completeFunction should take format: null OR {complete:function() {setStatus('done fading element.',1500);}} 
	new Rico.Effect.Size(document.getElementById(objToShow),showSize,null,20,10,completeFunction);	
}

function fadeObjV(objToFade,opacity,completeFunction) {
	new Rico.Effect.FadeTo(document.getElementById(objToFade),opacity,500,10,completeFunction);
}
/* /expand functions */

/* productList functions */
function hoverProductList(row,hover) {
	if (hover) {
		document.getElementById(row).className="borderT-w-1 grey";
		//document.getElementById("ff_"+row.split("PL_")[1]).src=cacheLoc + "/images/arrows/arrow_rightff_on_grey.gif";
	}
	else {
		document.getElementById(row).className="borderT-w-1 lightgrey";
		//document.getElementById("ff_"+row.split("PL_")[1]).src=cacheLoc + "/images/arrows/arrow_rightff.gif";
	}
}

/* /productList functions */

/* tabsMain functions */
function changeTabGrad(cell) {
	if (cell.className == "tabNormal") {
		cell.className = "tabRollover";
	}
	else if (cell.className == "tabRollover")  {
		cell.className = "tabNormal";
	}
}
/* /tabsMain functions */

/* send to this url */
function gotoUrl(url) {
	document.location = url;	
}
/* send to this url */

/* imageviewer functions */
function showImage(imageUrl) {
	var imageWin = window.open("imageviewer.cfm?imageUrl="+imageUrl,'imageW','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=yes,copyhistory=no,width=640,height=480');
	// Resize popup window to fit its contents then focus on it
	imageWin.sizeToContent();
	imageWin.focus();
}
/* /imageviewer functions */

/* openMax window */
function OpenMaxWindow(url) {
	var winwidth = screen.width;
	var winheight = screen.height;
	NewWindow=window.open(url,'descr','toolbar=no,location=no,directories=no,status=no,menubar=no,,scrollbars=yes,resizable=yes,copyhistory=no,width='+winwidth+',height='+winheight);
}
/* openMax window */

/* openMax window */
function OpenWindowNoScroll(url,width,height) {
	var winwidth = width;
	var winheight = height;
	WindowNoScroll=window.open(url,'winNoScroll','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+winwidth+',height='+winheight);
}
/* openMax window */

/* openMediaPlayer */
function OpenMediaPlayer(itemid,langid) {
	var language_id = langid.substring(1,langid.length-1).split("=")[1];
	var winwidth = 540;
	var winheight = 377;
	MediaWindow = window.open("xtras/mediaPlayer.cfm?itemid="+itemid+"&langid="+language_id,'mediaplayer','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+winwidth+',height='+winheight);
}
/* /openMediaPlayer */


/* openDTVPlayer */
function openDTVPlayer(playerid,channelid,videoid) {
	var winwidth = 764;
	var winheight = 504;
	var navid = 194;
	var DTVWindow = window.open("index.cfm?navid=" + navid + "&categoryid=" + playerid + "&itemid=channelid:" + channelid + ";videoid:" + videoid + ";" + "&printview=Y","DigiTVWindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width="+winwidth+",height="+winheight);
	DTVWindow.focus();
}
/* /openDTVPlayer */

/* openDigiTVPlayer //Deprecated */
function openDigiTVPlayer(playerid,channelid,videoid) {
	var winwidth = 744;
	var winheight = 504;
	var navid = 194;
	var DigiTVWindow = window.open("index.cfm?navid=" + navid + "&categoryid=" + playerid + "&itemid=channelid:" + channelid + ";videoid:" + videoid + ";" + "&printview=Y","DigiTVWindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width="+winwidth+",height="+winheight);
	DigiTVWindow.focus();
}
/*openDigiTVPlayer */

/* open Training Centers */
function OpenTrainingCenter(centerid,langid) {
	var winwidth = 550;
	var winheight = 400;
	TrainingWindow = window.open("modules/training/center_details.cfm?id="+centerid+"&langid="+langid,'trainingcenters','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,copyhistory=no,width='+winwidth+',height='+winheight);
	TrainingWindow.focus();
}


function voidN() {
	
};

/* JS for checking required fields */
function checkRequiredVals(formid,textFields,selectFields, errortxt) {
	var tArray = textFields.split(",");
	var sArray = selectFields.split(",");
	var i;
	var bGood = 1;
	var tmpAction = "";
	
	/* check input fields for filled-in values */
	for (i = 0; i < tArray.length; i++) {
		if (document.getElementById(tArray[i]).value == "") {
			bGood = 0;
			break;
		}
	}
	/* if no error above, now check select boxes for values */
	if (bGood && selectFields != "") {  
		for (i = 0; i < sArray.length; i++) {
			if (document.getElementById(sArray[i])[document.getElementById(sArray[i]).selectedIndex].innerHTML == ""
				|| document.getElementById(sArray[i])[document.getElementById(sArray[i]).selectedIndex].value == "" ) {
				bGood = 0;
				break;
			}
		}
	}

	/* if all values filled in, submit form; else, alert error */
	if (bGood) {
		document.getElementById(formid).submit();
	} 
	else {
		alert(errortxt);
	}
}
/* JS for checking required fields */

/*
window.onload = function () {
	document.forms[0].onsubmit = function () {
		return validate()
	}
}
*/

/*Global variables to define form elements*/
var validForm;
var firstError;
var errorstring;
var W3CDOM = (document.getElementsByTagName && document.createElement);

/*Generic form validation function*/
/*function checkRequiredValsWithWait(formid,textFields,selectFields, errortxt, btnPtr, plzWait) {
	
	validForm = true;
	firstError = null;
	errorstring = '';
	var x = document.forms[0].elements;
	for (var i=0;i<x.length;i++) {
		if (!x[i].value)
			writeError(x[i],'\n This field is required');
	}
	if (x['email'].value.indexOf('@') == -1)
		writeError(x['email'],'This is not a valid email address');
	if (!W3CDOM)
		alert(errorstring);
	if (firstError)
		firstError.focus();
	if (validForm)
		alert('All data is valid!');
	return false;
}*/

/* function to dynamically create labels for errors messages of each form input */
function writeError(obj,message) {
	validForm = false;
	if (obj.hasError) return;
	if (W3CDOM) {
		obj.className += ' error';
		obj.origOnChange = obj.onchange;
		obj.onchange = removeError;
		//var sp = document.createElement('span');
		//sp.className = 'error';
		//sp.appendChild(document.createElement('br'));
		//sp.appendChild(document.createTextNode(message));
		//obj.parentNode.appendChild(sp);
		//obj.hasError = sp;
		obj.hasError = 1;
		var inputLabel = getLabelForId(obj.id);
		if (inputLabel) inputLabel.className += ' error';
	}
	else {
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
	if (!firstError)
		firstError = obj;
}

function removeError()
{
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	//this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onchange = this.origOnChange;
	try {
		this.onchange();
	}
	catch(e) {};
	var inputLabel = getLabelForId(this.id);
	if (inputLabel) inputLabel.className = inputLabel.className.substring(0,this.className.lastIndexOf(' '));
}

/* for form validation, get label for input field */
function getLabelForId(id) {
	var label, labels = document.getElementsByTagName('label');
	for (var i = 0; (label = labels[i]); i++) {
		if (label.htmlFor == id) {
  			return label;
		}
	}
	return false;
} 

/* JS for checking required fields */
function checkRequiredValsWithWait(formid,textFields,selectFields, errortxt, btnPtr, plzWait) {
	var tArray = textFields.split(",");
	var sArray = selectFields.split(",");
	var taArray = document.getElementById(formid).getElementsByTagName('textarea');
	var i;
	var bGood = 1;
	var emailcheck = /.+@.+\.\w{2,6}$/;
	var zipcheck = /\d{5}/;

	/* check input fields for filled-in values */
	if (tArray[0].length > 0){
		for (i = 0; i < tArray.length; i++) {
			if (document.getElementById(tArray[i]).value == "") {
				writeError(document.getElementById(tArray[i]),' This field is required');
				bGood = 0;
			}
			else if (document.getElementById(tArray[i]).id == "email"){
				var address = document.getElementById(tArray[i]);
				if(!emailcheck.test(address.value) ){
					writeError(address,'Please enter a valid email address');
					bGood = 0;
				}
			}
		} 
	}

/* if no error above, now check select boxes for values */
	if (sArray[0].length > 0) {  
		for (i = 0; i < sArray.length; i++) {
			if (document.getElementById(sArray[i])[document.getElementById(sArray[i]).selectedIndex].innerHTML == ""
				|| document.getElementById(sArray[i])[document.getElementById(sArray[i]).selectedIndex].value == "" ) {
				writeError(document.getElementById(sArray[i]),'Please select a value');
				bGood = 0;
			}
		}
	}
	
	/* lastly check text areas for filled-in values */
	if (taArray.length > 0){
		for (i = 0; i < taArray.length; i++){
			if (taArray[i].value == ""){
				writeError(document.getElementsByTagName('textarea')[i],'Please provide this information');
				bGood = 0;
			}
		}				
	}

	/* if all values filled in, submit form */
	if (bGood){
		if (btnPtr.value != plzWait){
			btnPtr.value = plzWait;
			btnPtr.onClick = "";
			document.getElementById(formid).submit();
		}
	} 
	/*else {
		alert(errortxt);
	}*/
}
/* JS for checking required fields */


/* JS for comparisng two fields */ 
function checkEqualValues(field1,field2,errortxt) {
	if (document.getElementById(field1).value != document.getElementById(field2).value) {
		alert(errortxt);	
		return false;
	}
	else {
		return true;	
	}
}

/* JS for resetting select form fields */
function resetSelector(selectField) {
	try {
		document.getElementById(selectField)[0].selected = true;
	}
	catch (e){
		
	}
}

/* JS for disabling a button that is submitting a form */
function pleaseWait(frmPtr,btnPtr,plzWait) {
	if (btnPtr.value != plzWait){
		btnPtr.value = plzWait;
		btnPtr.onClick = "";
		frmPtr.submit ();
	}
		
	else {
		return 1;
	}
}

// Changes URL Parameter based on form variable
function changeUrlParam(myForm,myField,urlParam,newValue){
	// Call the getParameter function from urlparams.js to find current URL parameter value
	var curParam = getParameter(urlParam);
	// Alternative method of getting select field option value for old browsers
	//var newMkt = document.forms[myForm].mkt_choice.options[document.forms[myForm].mkt_choice.selectedIndex].value;
	if (myForm != "")
		var newParam = document.forms[myForm][myField].value;
	else
		var newParam = newValue;
	// Change the current URL parameter to the form value, or just append the value if it doesn't exist
	//alert(newMkt);
	//alert(urlParam);
	//alert(curMkt);
	if (curParam)
		{setParameter(curParam,newParam);}
	else
		{
		var searchString = window.location.search.toString();
		var searchLength = searchString.length - 1;
		var newamp = "";
		var eq = "=";
		if(searchString.lastIndexOf("&") != searchLength) {newamp = "&"};
		window.location = window.location + newamp + urlParam + eq + newParam;
		//window.location = window.location + "&" + urlParam + "=" + newMkt;
		//window.location = window.location + urlParam + newMkt;
		}
	}


// Remove all nodes and events from memory when unloading a page in any browser to prevent memory leaks
/*window.onunload = function unregisterAllEvents() {
  	var treeWalker = document.createTreeWalker(document.getElementById("contentholder"), NodeFilter.SHOW_ELEMENT, { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT } }, false);

	while (treeWalker.nextNode())
		 treeWalker.currentNode.parentNode.removeChild(treeWalker.currentNode);
}*/
