//	Utility Scripts
//		A collection of various javascript functions which control the site behavior
//		Compiled/Written in part by Shawn Marincas - 09-07-2008

//Initialization Processes:
//document.onclick = function(event) { Feedback(event); }

$.wait = function(time,func) {
	time = time || 1000;
	func = func || function() { var z=0; }
	window.setTimeout(func,time);
}

load_body = function() { 
			if($("#newbody").is(":hidden")) {
				$("#bqeloading").fadeOut(function() {
					$("#newbody").fadeIn('2000'); 
					$("#bqeloading").remove(); 
				});
			}
		}
		
$(function() {
	if($("#bqeloading").length > 0) {
		$("#bqeloading").fadeIn(function() { $.wait(5000,load_body); });
		$(window).load(load_body);
	}
	else {
		$("#newbody").show();
	}
	highlightMainMenuTab();
	$("a.mail_link").click(function () {
		var mailto = "mailto:";
		var x = this;
		$.post("/_asp/getServerData.asp",{ reqType: "emailLink", mailLink: $(x).text() },function(data) {
			mailto += data;
			if(x.rel) mailto += "?subject="+x.rel;
			location.href = mailto;
		});
		return false;
	});
});

//window.onload = function() { $("#bqeloading").fadeOut(function() {$("#newbody").fadeIn('2000'); $("#bqeloading").remove();});  }

/*function Feedback2() {
	window.open("/BetaFeedback.asp","_blank","height=550,width=500,status=no,location=no,menubar=no,scrollbars=no,toolbar=no,titlebar=no");
}
/*----------------------------------------------------------------------\
|	Monitors for combination of keypress and click						|
|	when combination matches, popups a new window with feedback form	|
|	By Shawn Marincas - 08.29.2008										|
\----------------------------------------------------------------------*/
/*
function Feedback(evt) {
	var e = evt || window.event;
	
	var ctrlDn = e.ctrlKey;
	var altDn = e.altKey;
	
	if(ctrlDn && altDn) {
		window.open("/BetaFeedback.asp","_blank","height=550,width=500,status=no,location=no,menubar=no,scrollbars=no,toolbar=no,titlebar=no,resizable=no,directories=no");
	}
}*/

/*----------------------------------------------------------------------\
|	Changes Main Menu tab class to highlight current section			|
|	By Shawn Marincas - 09.07.2008										|
\----------------------------------------------------------------------*/
function highlightMainMenuTab() {
	var ref = String(document.location.pathname);
	
	ref = ref.substring(ref.lastIndexOf("/"));
		
	if(ref.match(/default/i))
		document.getElementById('navHome').className = "currentSection";
	else if(ref.match(/solutions/i))
		document.getElementById('navSolutions').className = "currentSection";
	else if(ref.match(/products/i))
		document.getElementById('navProducts').className = "currentSection";
	else if(ref.match(/try/i))
		document.getElementById('navTrial').className = "currentSection";
	else if(ref.match(/store/i))
		document.getElementById('navBuy').className = "currentSection";
	else if(ref.match(/service/i))
		document.getElementById('navServices').className = "currentSection";
	else if(ref.match(/support/i))
		document.getElementById('navSupport').className = "currentSection";
	else if(ref.match(/company|media/i))
		document.getElementById('navCompany').className = "currentSection";
}
function popVideoWithForm(src, showInfForm)
{
	if(!showInfForm ) {
		window.open("/Playvideo.asp?vidId=" + src,"_blank","height=700,width=1038,status=no,location=no,menubar=no,scrollbars=no,toolbar=no,titlebar=no");
	}
	else
	{
		window.open("/Playvideo.asp?vidId=" + src + "&showInfForm=true","_blank","height=700,width=1038,status=no,location=no,menubar=no,scrollbars=no,toolbar=no,titlebar=no");
	}
	
	return false;
}
function popVideo(src,mode) {
	if(!mode) {
		window.open("/Playvideo.asp?vidId=" + src,"_blank","height=700,width=1038,status=no,location=no,menubar=no,scrollbars=no,toolbar=no,titlebar=no");
	} else {
		window.open("/"+mode.url+"?vidId=" + src,"_blank","height="+mode.h+",width="+mode.w+",status=no,location=no,menubar=no,scrollbars=no,toolbar=no,titlebar=no");
	}
	return false;
}

function mkPost(url, parameters, fill, after) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
	} else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = function() { ajxStateChange(fill,after); }
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function ajxStateChange(fill,after) {
	if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		result = http_request.responseText;
		if(fill) {
			document.getElementById(fill).innerHTML = result;
		}
		if(after == "refresh") { location.reload(true); }
	 } else {
		alert('There was a problem with the request.'+http_request.status);
	 }
	}
}

/*----------------------------------------------------------------------*/

// Finds correct Mouse position on the page cross-browser like
// by Quirksmode.org
// Source: http://www.quirksmode.org/js/events_properties.html
function getMousePos(evt, z) {
	var posx = 0;
	var posy = 0;
	if (evt.pageX || evt.pageY) 	{
		posx = evt.pageX;
		posy = evt.pageY;
	}
	else if (evt.clientX || evt.clientY) 	{
		posx = evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = evt.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	
	if(z == "y")
		return posy;
	else
		return posx;
}

//	Element visibility toggling functions (qa.js)
//	By unknown
function showElement(){ //usage showElement('id1','id2','id3','id4','etc')
 var element;
 for (var i=0; i<=showElement.arguments.length; i++) {
    element = document.getElementById(showElement.arguments[i]);
      if(element){
         element.style.display='';
         // edl: 'block' value causes a "space leak" problem in Firefox
         //element.style.display='block';
      }
 }
}// end fn

function hideElement(){  //usage hideElement('id1','id2','id3','id4','etc')
 var element;
 for (var i=0; i<=hideElement.arguments.length; i++) {
    element = document.getElementById(hideElement.arguments[i]);
      if(element == null) { continue };
    element.style.display='none';
 }
}// end fn

function popmelarge(where) {
var listWindow = window.open(where,'_blank','toolbar=no,location=no,menubar=yes,resizable=yes,directories=no,scrollbars=yes,status=no,width=750,height=600,top=100,left=100');
}

function toggleView(){ //usage toggleView('id1','id2','id3','id4','etc')
  var element;
  for (var i=0; i<=toggleView.arguments.length; i++) {
    element = document.getElementById(toggleView.arguments[i]);
       if(element == null) { continue };
    element.style.display=='' ?  element.style.display='none' : element.style.display='';
  }// end for
 }

 function selIndustry(div,target, seldiv, url, sol) {
  //alert ("div " + div + " t "+ target + " u " + url  + "seldiv " + seldiv + " " + sol);
	var elementTarget, elementDiv, elementSelDiv, showSolution;
	elementTarget = document.getElementById(target);
	elementDiv = document.getElementById(div);
	elementSelDiv = document.getElementById(seldiv);
	
	 if (elementDiv.style.display == '' )
	 {
		elementDiv.style.display='none';
	    elementTarget.style.display='';
		elementSelDiv.innerHTML = sol;
		//alert ("Seldiv IHTML" + elementSelDiv.innerHTML );
		jah(url,target);
	 }
	 else
	 {	
	   if (elementSelDiv.innerHTML == sol )
	   { 
			//alert ("Seldiv IHTML == sol " + elementSelDiv.innerHTML );
			elementDiv.style.display='';
			elementTarget.style.display='none';
			
	   }
	   else
	   {
			//alert ("Seldiv IHTML != sol " + elementSelDiv.innerHTML );
			elementSelDiv.innerHTML = sol;
			jah(url,target);
	  }
	   }
 }
//	Toggle Functions (tabs.js)
//	By sean@thecity.org (not me - SM)
function togglePerspective() {
	var d = document; {
		document.getElementById('perspective').style.display = "block";
		document.getElementById('perspectiveTab').style.backgroundPosition = "0 0";
		document.getElementById('welcome').style.display = "none";
		document.getElementById('welcomeTab').style.backgroundPosition = "0 -24px";
	} 
}
function toggleWelcome() {
	var d = document; {
		document.getElementById('welcome').style.display = "block";
		document.getElementById('welcomeTab').style.backgroundPosition = "0 0";
		document.getElementById('perspective').style.display = "none";
		document.getElementById('perspectiveTab').style.backgroundPosition = "0 -24px";
	} 
}

//  Go Function (go.js)
//  No Credit - Used to operate the Jump To... select box in default.asp
function go() {
	var box = document.forms[0].url;
	var destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

//	NewWindow (popup.js)
//	Auto center window script- Eric King (http://redrival.com/eak/index.shtml)
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)
}

//  Jah (jah.js)
//  XMLHTTP Request functions for basic AJAX
//  No credit
function jah(url,target) {
	// native XMLHttpRequest object
	document.getElementById(target).innerHTML = "<p><strong>Loading</strong></p>";
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = function() {jahDone(target);};
		req.open("GET", url, true);
		req.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = function() {jahDone(target);};
			req.open("GET", url, true);
			req.send();
		}
	}
}

function jahDone(target) {
	// only if req is "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			results = req.responseText;
			document.getElementById(target).innerHTML = results;
		} else {
			document.getElementById(target).innerHTML="ajax error:\n" +
				req.statusText;
		}
	}
}