/* http://dean.edwards.name/weblog/2005/09/busted/
This script is used to create an event for DomContentLoaded, which executes PRIOR to the page onLoad event.  It is ideal to run this initialization javascript on the DomContentLoaded (refered to in this script as the Init() function) because it minimizes the possibility of browser flicker.  

There is an issue with IE though, which is why we check the page protocol.  For HTTPS pages, an external script is included to get around the issue that
javascript:void(); executes an HTTP request, giving a "Page contains unsecure items" warning.  By including the external script, we get around this issue.  We only do this when needed though, which is on the HTTPS pages, since this method has the potential to introduce page flicker due to the time needed to load an external script.
*/

/* DO NOT DELETE THIS BLOCK!!! */
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32) {
	var loc = document.location.toString();
	var index = loc.indexOf(":");
	var protocol = loc.substring(0,index);

	if (protocol == "https") {
		document.write("<script defer src=/scripts/ie_sslInit.js><\/script>");
	}
	else {
		document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
			if (this.readyState == "complete") {
				init(); // call the onload handler
			}
		}
	}
};
/*@end @*/

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = init;

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);

	// do stuff
	prep();
};

function prep() {
	externalLinks();
	replaceFlash('flash_content');
	if (window.expandCollapse) {
		expandCollapse();
	}
}

// Open External Links as Blank Targets via Unobtrusive JavaScript
// http://perishablepress.com/press/2007/11/20/open-external-links-as-blank-targets-via-unobtrusive-javascript/
// http://www.sitepoint.com/print/1041

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");

	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		var relative = anchor.getAttribute("rel");
		var pattern = /external/i;
		
		if (anchor.getAttribute("href") && pattern.test(relative)) {
		   anchor.target = "_blank";
		}
	}
}

function replaceFlash(id) {
	if (document.all) {
		var div = document.getElementById(id); // this is the container of the <object> tag
		if (div) {
			var	ret = div.innerHTML; // this can vary wildly in IE
			var movie = ret.substring(ret.toLowerCase().indexOf("data=") + 5); // strip out the movie path
			var end = Math.min(movie.indexOf(" "), movie.indexOf(">")); // there's no telling if data is the last attribute in the <object> tag opener
			movie = movie.substring(0, end);
			ret = ret.replace("</OBJECT>", "<PARAM NAME='Movie' VALUE='" + movie + "'></OBJECT>");
			div.innerHTML = ret;
		}
	}
}

function expandInt(){

    var div = document.getElementById('international');
    div.style.display='block';
    var us = document.getElementById('US');
    if(us.style.display=="block"){
        us.style.display="none";    
    }
    document.getElementById('findRepInt').blur();
}

function expandUS(){
    var div = document.getElementById('US');
    div.style.display='block';
    var international = document.getElementById('international');
    if(international.style.display=="block"){
        international.style.display="none";    
    }
    document.getElementById('findRepUS').blur();
}

function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
        oldonload();
        func();
        }
    }
}

// this function toggles the status of Image Category
function toggleImages(image,id){ 
	if (!document.getElementById) return false;
    document.getElementById(id).blur();
    var showHide=document.getElementById(id).style; 
    if (showHide.display=="none"){ 
        showHide.display="block"; 
        document.getElementById(image).src="/images/Common/minus.gif"; 
        document.getElementById(image).alt="Open";
    } else { 
        showHide.display="none"; 
        document.getElementById(image).src="/images/Common/plus.gif"; 
        document.getElementById(image).alt="Close"; 
 } 
}

function hideImageLibrary(){
	if (!document.getElementById('accurus')) return false;
	if (!document.getElementById('mivs')) return false;
	if (!document.getElementById('Grieshaber')) return false;
	if (!document.getElementById('triesence')) return false;
	document.getElementById('accurus').style.display="none";
	document.getElementById('mivs').style.display="none";
	document.getElementById('Grieshaber').style.display="none";
	document.getElementById('triesence').style.display="none";
}
 
addLoadEvent(hideImageLibrary);

//Open new window for images on eyelite accessories
var newwindow;
function popUpImage(url, title, w, h)
{

	if (title == null){
		title = "";
	}
	if (newwindow && !newwindow.closed){
		newwindow.focus();
		newwindow.document.clear()
	} else  {
	newwindow=window.open('','','width=' + w + ',height=' + h + ',resizable=1,resizable=no')
	}

	 newwindow.document.writeln('<head> <title>' + title + '<\/title><style>body{margin:0;}</style> <\/head> <body bgcolor=\"white\"> <center>');
	 newwindow.document.writeln('<img src=' + url + ' title=\"' + title + '\" alt=\"' + title + '\" >');
	 newwindow.document.writeln('<\/center> <\/body> <\/html>');
	 newwindow.document.close();
}

function popupPurePointOperationVideo()
{
	window.open("purepointHowToOperate.asp", "", "width=640,height=500,resizable=1,resizable=no");
	
	return false;
}
function popupSlitLamp()
{
	window.open("slitLamp_features.asp", "", "width=640,height=500,resizable=1,resizable=no");
	
	return false;
}