/* legacy js to be refined v2
 *
 * Function to add onload events while preserving existing onload events
 * @param func - sting
 * 	function name
 */

    var browser=navigator.appName
    var b_version=navigator.appVersion
    var version=parseFloat(b_version)




var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();








//// testing flash detection function ////

function MM_checkPlugin(plgIn, theURL, altURL, autoGo) { //v4.0
  var ok=false; document.MM_returnValue = false;
  with (navigator) if (appName.indexOf('Microsoft')==-1 || (plugins && plugins.length)) {
    ok=(plugins && plugins[plgIn]);
  } else if (appVersion.indexOf('3.1')==-1) { //not Netscape or Win3.1
    if (plgIn.indexOf("Flash")!=-1 && window.MM_flash!=null) ok=window.MM_flash;
    else if (plgIn.indexOf("Director")!=-1 && window.MM_dir!=null) ok=window.MM_dir;
    else ok=autoGo; }
  if (!ok) theURL=altURL; if (theURL) window.location=theURL;
}



//// testing for alert content on homepage////

function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
subobj.style.left=xpos+"px"
subobj.style.top=ypos+"px"
return false
}
else
return true
}

function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}


/////




function openAlertWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

 
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

window.onresize = function() {
	setFooter();
}
addLoadEvent(setFooter);
function setFooter() {
	if (document.getElementById) {
		var windowHeight = document.getElementById('container').offsetHeight;
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('body').offsetHeight + document.getElementById('header').offsetHeight + document.getElementById('footer').offsetHeight;
			leftover = windowHeight - contentHeight;
			if (windowHeight > contentHeight) {
				document.getElementById('body').style.height = document.getElementById('body').offsetHeight + (leftover-20) + 'px';
			}
			else {
				
			}
		}
	}
}

addLoadEvent(externalLinks);
function externalLinks() {
 if (!document.getElementsByTagName) return;  var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

addLoadEvent(startList);

function startList() {
	if (document.all&&document.getElementById)
	{
		navRoot = document.getElementById("mainnav");
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") 
			{
				node.onmouseover=function()
				{
				this.className+=" over";
		  		}
				node.onmouseout=function() 
				{
  				this.className=this.className.replace(" over", "");
   				}
   			}
  		}
 	}
}


addLoadEvent(checkbrowser);

function checkbrowser(){
	
	var detect = navigator.appName.toLowerCase();
	
	if(detect == 'microsoft internet explorer'){
		lookupmenu();
	}
}


function lookupmenu(){
	var mainnav = document.getElementById('mainnav');
	for(i=0; i<mainnav.childNodes.length; i++){
		
		node = mainnav.childNodes[i];
		if (node.nodeName=="LI"){
			listitem = node;
			for(j=0; j<listitem.childNodes.length; j++){
				if(listitem.childNodes[j].nodeName == "A"){
					if(listitem.childNodes[j].href != ''){
						listitem.childNodes[j].onmouseover = function(){showiframe(this),j};
						listitem.childNodes[j].onmouseout = function(){removeiframe(this),j};
					}
					
				} else if (listitem.childNodes[j].nodeName == "UL"){
					listitem.childNodes[j].onmouseover = function(){showiframe(this),j};
					listitem.childNodes[j].onmouseout = function(){removeiframe(this),j};
				}
			}
		}
	}
}

function showiframe(e){
	
	var eHeight;
	var eWidth;
	var eTop;
	var eLeft;
	var iframe = document.createElement('iframe');
	
	iframe.id = 'iframe_fix';
	iframe.style.display = 'none';
	iframe.style.zIndex = '12';
	iframe.frameborder = '0';
	
	for(k=0; k<e.parentNode.childNodes.length; k++){
		if(e.parentNode.childNodes[k].nodeName == "UL"){
			
			e.parentNode.childNodes[k].style.zIndex = '13';
			
			e.parentNode.insertBefore(iframe, e.parentNode.childNodes[k]);
			
			eheight = e.parentNode.childNodes[k].clientHeight;
			eWidth = e.parentNode.childNodes[k].clientWidth;
			eTop = e.parentNode.childNodes[k].offsetTop;
			eLeft = e.parentNode.childNodes[k].offsetLeft;
		}
	}
	
	iframe.style.position = 'absolute';
	iframe.style.display = '';
	iframe.style.top = eTop+'px';
	iframe.style.left = eLeft+'px';
	iframe.style.width = eWidth+'px';
	iframe.style.height = eheight+'px';
}

function removeiframe(e){
	var iframe_fix = document.getElementById('iframe_fix');
	iframe_fix.parentNode.removeChild(iframe_fix);
}

function jumpRefresh(varname, varvalue) {
	// Jumps to the current URL updating it with the passed data.
	
	s = location.href;
	qpos = s.indexOf("?");
	
	//get hidden values
	
	if (qpos != -1) {
		qpos += 1;
		data = s.substring(qpos).split("&");
		var queries = new Array();
		for (querypart in data) {
			thisquery = data[querypart]; 
			qppos = thisquery.indexOf("=");
			if (qppos != -1) {
				queries[thisquery.substr(0,qppos)] = thisquery.substr(qppos + 1);				
			}
		}
		queries[varname] = varvalue;
		finaltext = s.substr(0,qpos);
		for (queryname in queries) {
			finaltext += queryname + "=" + queries[queryname] + "&";
		}
		location.href = finaltext;   
	} else {
		location.href = s + "?" + varname + "=" + varvalue;
	}
	
}

function clearPartnerLogin(defaultvalue) {

	if (document.partnerlogin.partner_username.value == defaultvalue) {
		document.partnerlogin.partner_username.value = '';
	}

}

function clearPartnerPassword() {

	if (document.partnerlogin.partner_password.value == 'Password') {
		document.partnerlogin.partner_password.value = '';
	}

}

function setPartnerLogin(defaultvalue) {

	if (document.partnerlogin.partner_username.value == '') {
		document.partnerlogin.partner_username.value = defaultvalue;
	}
	
}

function setPartnerPassword() {

	if (document.partnerlogin.partner_password.value == '') {
		document.partnerlogin.partner_password.value = 'Password';
	}

}

function displaySearchFields(country) {

	if ((country == 38) || (country == 8)) {

		document.getElementById('searchfields').style.display = '';

		if (country == 38) {
			document.getElementById('province').style.display = '';			
			document.getElementById('state').style.display = 'none';			
		}
		
		if (country == 8) {
			document.getElementById('state').style.display = '';						
			document.getElementById('province').style.display = 'none';			
		}

	} else {

		document.getElementById('searchfields').style.display = 'none';
		document.getElementById('province').style.display = 'none';			
		document.getElementById('state').style.display = 'none';			
		
	}

}

function checkCity() {

	f = document.solutionprovider;

	if (f.city.value != '') {
		
		if (f.country.value == 8) {

			if (f.state.value == '') {
			
				alert('Please enter a State when searching by City and State.');
				return false;
			
			}

		} else {

			if (f.province.value == '') {
			
				alert('Please enter a Province when searching by City and Province.');
				return false;
			
			}

		}		
		
	} else {

		if (f.country.value == 8) {

			if (f.state.value != '') {
			
				alert('Please enter a City when searching by City and State.');
				return false;
			
			}

		} else {

			if (f.province.value != '') {
			
				alert('Please enter a City when searching by City and Province.');
				return false;
			
			}

		}		

	}
	
	if (f.country.value == '') {

		alert('Please select a Country.');
		return false;

	}
	
	return true;

}