function openURL3(url, width, height)
{
    var stdOptions = "resizable=no,directories=no,left=400,top=300,toolbar=no";
    var options = stdOptions + ",width=" + width + ",height=" + height + ",scrollbars=yes" ;
    window.open(url,"url",options);
}

function openURL2(url, width) {
    openURL3(url, width, 380);
}

function openURL(url)
{
    openURL3(url, 270, 380);
}

function openWindow(url) {
    var stdOptions = "resizable=yes,directories=yes,left=400,top=300,toolbar=yes,menubar=yes,scrollbars=yes";
    window.open(url,"url",stdOptions);
}

function hideCategories() {
    document.getElementById('topCategories').style.display = 'none';
    document.getElementById('topCategoryExplain').style.display = 'block';
    document.getElementById('categoryToggle').innerHTML = "<a href=\"javascript: showCategories()\"><img src=\"/siteimages/layout/ajax/expand_blue.jpg\" alt=\"Expand\" /></a>";
}

function showCategories() {
    document.getElementById('topCategories').style.display = 'block';
    document.getElementById('topCategoryExplain').style.display = 'none';
    document.getElementById('categoryToggle').innerHTML = "<a href=\"javascript: hideCategories()\"><img src=\"/siteimages/layout/ajax/collapse_blue.jpg\" alt=\"Collapse\" /></a>";
}

//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      alert('\'' + strEmail + '\' is not a valid email address.  Please try again.');
      return false;
    } 
    return true; 
}

function ajaxRequest(url,elementId) {
    var xmlHttp;
    try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("We're sorry, but your browser does not support this feature.");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
            document.getElementById(elementId).innerHTML = xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function showModalBackground() {
    document.getElementById('modalBackground').style.visibility = 'visible';
}

function hideModalBackground() {
    document.getElementById('modalBackground').style.visibility = 'hidden';
}

function showModalPopup(elementId) {

    var width = window.innerWidth || document.body.offsetWidth;
    var height = window.innerHeight || document.body.offsetHeight;
    if (width == 0) {
        width = document.body.clientWidth;
    }
    if  (height == 0) {
        height = document.body.clientHeight;   
    }
    document.getElementById(elementId).style.left = ((width / 2) - (document.getElementById(elementId).style.width.replace('px', '') / 2) + "px");
    //document.getElementById(elementId).style.top = ((height / 2) - (document.getElementById(elementId).style.height.replace('px', '') / 2) + "px");
    showModalBackground();
    showDiv(elementId);
}

function hideModalPopup(elementId) {
    hideModalBackground();
    hideDiv(elementId)
}

function showSightMax() {
    var width = window.innerWidth || document.body.offsetWidth;
    var height = window.innerHeight || document.body.offsetHeight;
    if (width == 0) {
        width = document.body.clientWidth;
    }
    if  (height == 0) {
        height = document.documentElement.clientHeight;   
    }
    document.getElementById('sightMaxPanel').style.left = ((width / 2) - 200) + "px";
    document.getElementById('sightMaxPanel').style.top = "180px";
    showModalPopup('sightMaxPanel');
    ajaxRequest('/popups/liveSupport.html', 'sightMaxContent');
    
}

function ajaxPopup(id, header, width, url)
{
	 if (!document.getElementById(id)) {
         var newdiv = document.createElement('div');
         newdiv.setAttribute('id',id);
         newdiv.className = 'modalPopup';
         
         var divcontents = '<div style="float:right; margin-top: 2px; margin-right: 2px"><a href="javascript: hideDiv(\'' + id + '\')"><img src="/siteimages/layout/ajax/closeWindowBlue.gif" alt="Close" /></a></div>';
         divcontents += '<div class="modalPopupHeader"><strong>' + header + '</strong></div>';;
         divcontents += '<div id="' + id + 'Content"><div style=\"vertical-align: middle; font-size: large; margin: 20px\"><img src=\"/siteimages/ajax-loader.gif\" alt=\"\" />Loading...</div></div>';
         
         newdiv.innerHTML = divcontents;
         
         
         newdiv.style.visibility = 'visible';
         newdiv.style.display = 'block';
         newdiv.style.width = width + 'px';
         
         document.body.appendChild(newdiv);
         
        newdiv.style.top = mouseY + 'px';
        newdiv.style.left = (mouseX - width) + 'px';
        
        ajaxRequest(url, id+'Content');
     } else {
         showDiv(id);
         document.getElementById(id).style.top = mouseY + 'px';
         document.getElementById(id).style.left = (mouseX - width) + 'px';
     }
     
}

function hideDiv(id) {
    document.getElementById(id).style.visibility = 'hidden';
    document.getElementById(id).style.display = 'none';
}

function showDiv(id) {
    document.getElementById(id).style.visibility = 'visible';
    document.getElementById(id).style.display = 'block';
}

/*
    var myWidth = 0, myHeight = 0;
    
    if ( typeof( window.innerWidth ) == 'number' ) 
    {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } 
    else if ( document.documentElement && 
            ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } 
    else if ( document.body && 
            ( document.body.clientWidth || document.body.clientHeight ) ) 
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    var divWidth = document.getElementById(elementId).style.width;
    var divHeight = document.getElementById(elementId).style.height;

    var left  = ((myWidth / 2) - (divWidth / 2));
    var top = ((myHeight / 2) - (divHeight / 2));

    top = 100;
    
    alert("element:" + elementId + ", top:" + top + ", left:" + left + ", myWidth:" + myWidth + ", myHeight:" + myHeight + ", divWidth:" + divWidth + ", divHeight:" + divHeight);
        
    document.getElementById(elementId).style.top = (top + "px");
    document.getElementById(elementId).style.left = (left + "px");
*/

var IE = document.all?true:false;
document.onmousemove = getMouseXY;

var mouseX = 0;
var mouseY = 0;

function getMouseXY(e) {
    if (!IE) {
        mouseX = e.clientX;
        mouseY = e.clientY;
    } else {
        mouseX = event.clientX;
        mouseY = window.event.y;
    }
}

function submitWebsiteFeedback(sessionId,feedbackUrl) {
    var name = document.getElementById('feedbackName').value;
    var email = document.getElementById('feedbackEmail').value;
    var feedback = document.getElementById('feedback').value;
    var width = screen.width;
    var height = screen.height;
    var browser = BrowserDetect.browser;
    var browserVersion = BrowserDetect.version;
    var os = BrowserDetect.OS;
    var feedbackType = document.getElementById('feedbackType').value;
    
    if (isValidEmail(email)) {
        ajaxRequest("/ajax/websiteFeedbackForm.aspx?sessionId="+sessionId+"&email="+email+"&name="+name+"&feedback="+feedback+"&screenWidth="+width+"&screenHeight="+height+"&browser="+browser+"&browserVersion="+browserVersion+"&os="+os+"&feedbackType="+feedbackType+"&feedbackUrl="+feedbackUrl,'feedbackArea');
    }
    hideDiv('websiteFeedbackPopup');
}

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();

function fireFoxCursorFix() {
    var browser = BrowserDetect.browser;
    var browserVersion = BrowserDetect.version;
    
    if ((browser == "Firefox") && (browserVersion == "2")) {
        
        var formElements = document.getElementsByTagName("input");
        
        for(i=0; i<formElements.length; i++) {
            if ((formElements[i].type == 'text') || (formElements[i].type == 'password')) {
                if (formElements[i].id) {
                    formElements[i].addEventListener('click', function() { toggleFakeCursor(this.id, 'on')}, false);
                    formElements[i].addEventListener('keydown', function() { toggleFakeCursor(this.id, 'on')}, false);
                    formElements[i].addEventListener('keyup', function() { toggleFakeCursor(this.id, 'on')}, false);
                    formElements[i].addEventListener('blur', function() { toggleFakeCursor(this.id, 'off')}, false);
                }
            }
        }
    }
}

function toggleFakeCursor(elementId, state) {
    var browser = BrowserDetect.browser;
    var browserVersion = BrowserDetect.version;
    
    if ((browser == "Firefox") && (browserVersion == "2")) {
        if (state == "on") {
            document.getElementById(elementId).style.backgroundImage = "url('/siteimages/blinking_cursor.gif')";
            document.getElementById(elementId).style.backgroundRepeat = "no-repeat";
            //See how far to position this guy...
            document.getElementById('ruler').innerHTML = document.getElementById(elementId).value;
            document.getElementById(elementId).style.backgroundPosition = document.getElementById('ruler').offsetWidth + 2 + "px";
        } else {
            document.getElementById(elementId).style.backgroundImage = 'none';
        }
    }
}

function trim(strToTrim)
{
    return strToTrim.replace(/^\s+|\s+$/g,"");
}

function setChatOnline()
{
    if (document.getElementById("liveSupportStatus") != null)
    {
        document.getElementById("liveSupportStatus").innerHTML = "online";
        document.getElementById("liveSupportStatus").style.color= "#e59f44";
        document.getElementById("liveSupportStatus").style.textDecoration = "underline";
    }
   
    if (document.getElementById("productPageLiveSupportButton") != null)
    {
        document.getElementById("productPageLiveSupportButton").src = "/siteimages/layout2/liveSupportOnline.gif";
    }
    
    if (document.getElementById("searchLiveSupportPanel") != null)
    {
        document.getElementById("searchLiveSupportPanel").style.visibility = "visible";
        document.getElementById("searchLiveSupportPanel").style.display = "block";
    }
}

function setChatOffline()
{
    if (document.getElementById("liveSupportStatus") != null)
    {
        document.getElementById("liveSupportStatus").innerHTML = "offline";
    }
   
    if (document.getElementById("productPageLiveSupportButton") != null)
    {
        document.getElementById("productPageLiveSupportButton").src = "/siteimages/layout2/liveSupportOffline.gif";
    }
}

function ajaxSightmaxRequest(url, action) {
    if (document.getElementById("liveSupportStatus") != null ||
        document.getElementById("productPageLiveSupportButton") != null) {
    var xmlHttp;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                //alert("We're sorry, but your browser does not support this feature.");
                return false;
            }
        }
    }

    if (action == 0)
    {
        xmlHttp.onreadystatechange=function()
        {
            if(xmlHttp.readyState == 4)
	        {
		        if (xmlHttp.status == 200)
            	{
                	try
                 	{
                		if (trim(xmlHttp.responseText) == "1")
                		{
                    		setChatOnline();
                		}
                		else
                		{
                    		setChatOffline();
                		}
                	} 
                	catch(e) 
                	{
                        setChatOffline();
                	}
            	}
            	else
            	{
                	setChatOffline();
            	}
    	    }
        }
    }
    else if (action == 1)
    {
        xmlHttp.onreadystatechange=function()
        {
            if(xmlHttp.readyState==4)
            {
                if (xmlHttp.status==200)
                {
                    //document.write(xmlHttp.responseText);
                    //var e = document.createElement("script");
                    //e.innerHTML = xmlHttp.responseText;
                    //e.type="text/javascript";
                    //document.getElementsByTagName("head")[0].appendChild(e);
                }
            }
        }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    }
}

function enableMenuJavascriptDelay() {
    var x=1;
    for (x=1; x < 8; x++) {
        document.getElementById('menu' + x.toString()).className = 'menu';
    }
    
    document.getElementById('menu1').onmouseover = function() { setTimeout(function() { var x=1; for (x=1; x < 8; x++) { if (x!=1)document.getElementById('menu' + x.toString()).className = 'menu'; } document.getElementById('menu1').className = 'menu menudrop';} , 300) };
    document.getElementById('menu2').onmouseover = function() { setTimeout(function() { var x=1; for (x=1; x < 8; x++) { if (x!=2)document.getElementById('menu' + x.toString()).className = 'menu'; } document.getElementById('menu2').className = 'menu menudrop';} , 300) };
    document.getElementById('menu3').onmouseover = function() { setTimeout(function() { var x=1; for (x=1; x < 8; x++) { if (x!=3)document.getElementById('menu' + x.toString()).className = 'menu'; } document.getElementById('menu3').className = 'menu menudrop';} , 300) };
    document.getElementById('menu4').onmouseover = function() { setTimeout(function() { var x=1; for (x=1; x < 8; x++) { if (x!=4)document.getElementById('menu' + x.toString()).className = 'menu'; } document.getElementById('menu4').className = 'menu menudrop';} , 300) };
    document.getElementById('menu5').onmouseover = function() { setTimeout(function() { var x=1; for (x=1; x < 8; x++) { if (x!=5)document.getElementById('menu' + x.toString()).className = 'menu'; } document.getElementById('menu5').className = 'menu menudrop';} , 300) };
    document.getElementById('menu6').onmouseover = function() { setTimeout(function() { var x=1; for (x=1; x < 8; x++) { if (x!=6)document.getElementById('menu' + x.toString()).className = 'menu'; } document.getElementById('menu6').className = 'menu menudrop';} , 300) };
    document.getElementById('menu7').onmouseover = function() { setTimeout(function() { var x=1; for (x=1; x < 8; x++) { if (x!=7)document.getElementById('menu' + x.toString()).className = 'menu'; } document.getElementById('menu7').className = 'menu menudrop';} , 300) };
}