<!--

/* ajax call function*/
/*
function getHTTPRequest() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else

  xmlhttp = false;
  @end @*/

/*
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}


function updateElement(id, url) {
	var http = getHTTPRequest();
	http.open("GET", url, true);
	http.onreadystatechange = function() {
	  if (http.readyState == 4) {
		document.getElementById(id).innerHTML = http.responseText;
	  }
	}
  	http.send(null);
}


function updateSubTotal() {
	updateElement("rawSubTotal", "includes/subTotal.jsp?rnd=" + parseInt(Math.random()*10000000));
}

function updateCartDropDown() {
	updateElement("CartDiv1", "includes/cartDropDown.jsp?rnd=" + parseInt(Math.random()*10000000));
}

function addToCart(orderId, productId, skuId, quantityFieldId) {	
	var quantity = document.getElementById(quantityFieldId).value;
	var xmlhttp = getHTTPRequest();

	xmlhttp.open("POST", "/commerce/order/addItemToOrder/addItemToOrder");
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			var rXML = xmlhttp.responseXML;
			var rNodes = rXML.getElementsByTagName("return");
			if (rNodes == null) {
				alert("Problem adding item to cart");
			} else {
				var rText = rNodes[0].firstChild.nodeValue;
				if (rText != "null") {
				    //updateSubTotal
				    updateSubTotal();
					updateCartDropDown();
									
					//popupwindowhere
				    //alert("Adding item to cart - " + rText);
				    toggleDiv('CartDiv1',1);					
					setTimeout("toggleDiv('CartDiv1',0);",5000);					
				} else {
					alert("Problem adding item to cart");
				}
			}
		}
	}
	xmlhttp.setRequestHeader("Man", "POST /commerce/order/addItemToOrder/addItemToOrder HTTP/1.1");
	xmlhttp.setRequestHeader("MessageType", "CALL");
	xmlhttp.setRequestHeader("Content-Type", "text/xml");
	xmlhttp.send("<?xml version='1.0' encoding='UTF-8'?>"+"\n\n"+
		'<SOAP-ENV:Envelope'+
		' xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"'+
		' xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"'+
		' xmlns:xsd="http://www.w3.org/1999/XMLSchema">'+
		'<SOAP-ENV:Body xmlns:ns1="http://www.atg.com/webservices">'+
		'<ns1:addItemToOrder SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'+ 
		'<orderId xsi:type="xsd:string">'+orderId+'</orderId>'+
		'<productId xsi:type="xsd:string">'+productId+'</productId>'+
		'<skuId xsi:type="xsd:string">'+skuId+'</skuId>'+
		'<quantity xsi:type="xsd:long">'+quantity+'</quantity>'+
		'</ns1:addItemToOrder>'+
		'</SOAP-ENV:Body></SOAP-ENV:Envelope>');
	
}
/* end of ajax call function*/

String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		//date.setTime(date.getTime()+(5*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function getCookieLocale(){
	return readCookie("language");
}

function setCookieLocale(locale){
	return createCookie("language", locale, 365);
}

function changeLocale(language,path){
	setCookieLocale(language);	
	if ( language == 'fr' ){
		document.loadPageForm.profileLocale.value = "fr_CA";
		if ( path!=null){
			document.loadPageForm.action = path;
		}else {		
			document.loadPageForm.action ="../fr/index.jsp";
		}
		document.loadPageForm.submit();
	}else{
		document.loadPageForm.profileLocale.value = "en_CA";
		if ( path!=null){
			document.loadPageForm.action = path;
		}else {		
			document.loadPageForm.action ="../en/index.jsp";
		}	 
		document.loadPageForm.submit();
	}
}

function copyValue(local, target) {
	document.getElementById(target).value=local;
}

function detectBrowser() {
	var browser="";
	var userAgent=navigator.userAgent;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);	

	if(userAgent.indexOf("Firefox")>=0){
		browser="FF";
	}
	else if(userAgent.indexOf(".NET")>=0){
		browser="IE";
	}
	else if(userAgent.indexOf("Safari")>=0){
		browser="SI";
	}
	return browser;
}

function toggleElement(id,x,y) {
	document.getElementById(id).style.top=y+"px";
	document.getElementById(id).style.left=x+"px";
	document.getElementById(id).style.zIndex="999";
	document.getElementById(id).style.display="";
}

function hideElement(id) {
	document.getElementById(id).style.zIndex="0";
	document.getElementById(id).style.display="none";
}

function toggleDiv(id,flagit) {

	try {
		if (flagit == 0 || id != 'LogIn1')
			document.getElementById("loginError").innerHTML = "";
	} catch (e) {}
	
	try {
		if (flagit == 0 || id != 'ForgotPW')
			document.getElementById("forgotPasswordError").innerHTML = "";
	} catch (e) {}
	
	


	var div=document.getElementsByTagName("div");
	var divID = "";
	/**
	alert(div.length);
	**/
	for (var i=0; i<div.length; i++){
		/**
		alert(div[i].getAttribute("id"));
		**/
			divID = div[i].getAttribute("id");
			
		
		if(divID == 'LogIn1' || divID == 'ForgotPW' || divID == 'FPWThanks' || divID == 'WishList' || divID == 'MaterialList' 
			|| divID == 'CartDiv1'|| divID == 'EmailFriend1'|| divID == 'EmailFriend2'){
			if (document.getElementById){
				document.getElementById(''+divID).style.visibility = "hidden";
				if (divID == 'LogIn1' || divID == 'ForgotPW' || divID == 'FPWThanks'){
					toggleIFrame('LogInIFrame', 0);
				}else if( divID == 'EmailFriend1'){
					toggleIFrame('EmailFriendIFrame', 0);
				}else if (divID == 'CartDiv1' ){
					toggleS('selSorting', 0);
				}
			}
	    }
	}
	
	var checkBrowser = detectBrowser();
	
	if (id == 'LogIn1' || id == 'ForgotPW' || id == 'FPWThanks'){
		toggleIFrame('LogInIFrame', flagit);
	}else if( id == 'EmailFriend1'){
		toggleIFrame('EmailFriendIFrame', flagit);
	}else if (id == 'CartDiv1' ){
		toggleS('selSorting', flagit);
	}

if (flagit=="1"){
	if (document.layers){
		document.layers[''+id].visibility = "visible";
		if(checkBrowser=="SI"){
			document.layers[''+id].top = "85px";
		}else if(checkBrowser=="IE"){
			document.layers[''+id].top = "70px";
		}else{
			document.layers[''+id].top = "68px";
		}
	}
	else if (document.all){
		document.all[''+id].style.visibility = "visible";
		if(checkBrowser=="SI"){
			document.all[''+id].style.top = "85px";
		}else if(checkBrowser=="IE"){
			document.all[''+id].style.top = "70px";
		}else{
		document.all[''+id].style.top = "68px";
		}
	}
	else if (document.getElementById){
		document.getElementById(''+id).style.visibility = "visible";
		if(checkBrowser=="SI"){
			document.getElementById(''+id).style.top = "85px";
		}else if(checkBrowser=="IE"){
			document.getElementById(''+id).style.top = "70px";
		}else{
			document.getElementById(''+id).style.top = "68px";
		}
	}
}
else
if (flagit=="0"){
	if (document.layers){
		document.layers[''+id].visibility = "hidden";
		document.layers[''+id].top = "999px";
	}
	else if (document.all){
		document.all[''+id].style.visibility = "hidden";
		document.all[''+id].style.top = "999px";
	}
	else if (document.getElementById){
		document.getElementById(''+id).style.visibility = "hidden";
		document.getElementById(''+id).style.top = "999px";
	}
}

if(id == 'CartDiv1'){
	scrollbarControl(1);
}else if(id == 'MaterialList'){
	scrollbarControl(2);
}else if(id == 'WishList'){
	scrollbarControl(3);
}


}

function toggleFlexableDiv(id,flagit,x,y) {
	var checkBrowser = detectBrowser();
	x = x - document.getElementById('container1').offsetLeft;

if (flagit=="1"){
	if (document.layers){
		document.layers[''+id].visibility = "visible";
		if(checkBrowser=="SI"){
			document.layers[''+id].top = (y+17)+"px";
			document.layers[''+id].left = (x)+"px";
		}else if(checkBrowser=="IE"){
			document.layers[''+id].top = (y+2)+"px";
			document.layers[''+id].left = (x)+"px";
		}else{			
			document.layers[''+id].top = (y)+"px";
			document.layers[''+id].left = (x)+"px";
		}
	}
	else if (document.all){
		alert(id);
		document.all[''+id].style.visibility = "visible";
		if(checkBrowser=="SI"){
			document.all[''+id].style.top = (y+17)+"px";
			document.all[''+id].style.left = (x)+"px";
		}else if(checkBrowser=="IE"){
			document.all[''+id].style.top = (y+2)+"px";
			document.all[''+id].style.left = (x)+"px";
		}else{
		document.all[''+id].style.top = (y)+"px";
		document.all[''+id].style.left = (x)+"px";
		}
	}
	else if (document.getElementById){
		document.getElementById(''+id).style.visibility = "visible";
		if(checkBrowser=="SI"){
			document.getElementById(''+id).style.top = (y+17)+"px";
			document.getElementById(''+id).style.left = (x)+"px";
		}else if(checkBrowser=="IE"){
			document.getElementById(''+id).style.top = (y+2)+"px";
			document.getElementById(''+id).style.left = (x)+"px";
		}else{
			document.getElementById(''+id).style.top = (y)+"px";
			document.getElementById(''+id).style.left = (x)+"px";
		}
	}
	//document.getElementById(''+id).layers[''+id].top=y+"px";	
	//document.getElementById(''+id).style.paddingLeft=x+"px";
}
else
if (flagit=="0"){
	if (document.layers){
		document.layers[''+id].visibility = "hidden";
		document.layers[''+id].top = "999px";
	}
	else if (document.all){
		document.all[''+id].style.visibility = "hidden";
		document.all[''+id].style.top = "999px";
	}
	else if (document.getElementById){
		document.getElementById(''+id).style.visibility = "hidden";
		document.getElementById(''+id).style.top = "999px";
	}
}
}

function resetDiv(){
	
}

function OpenMenu(num, img) { 
	var level2 = document.getElementById('l'+num);
	level2.style.display="block";
	var imdNode = document.getElementById(img+'Img');
	if(imdNode){
	imdNode.src = 'imgs/button_'+img+'Sub.gif';
	}
} 

function CloseMenu(num, img) { 
	var level2 = document.getElementById('l'+num);
	level2.style.display="none";
	var imdNode = document.getElementById(img+'Img');
	if(imdNode){
	imdNode.src = 'imgs/button_'+img+'.gif';
	}
} 
/*
function wopen(url, name, w, h)
{
w += 32;
h += 96;
 var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=yes, resizable=no');
 win.resizeTo(w, h);
 win.focus();
}*/



function wopen(url, name, width, height){
	if (navigator.appName == "Netscape"){	
		width = width + 12;
	}else{width = width + 36;}
	
	var props = "width=" + width + ",height=" + height+",resizable=yes,scrollbars=yes";
	if(typeof(screen.width)!='undefined'){
		props += ",top=" + ((screen.height-height)/2);
		props += ",left=" + ((screen.width-width)/2);
	}
	var win = window.open(url,'dialogWindow',props);
	win.window.resizeTo(width,  height);
	win.window.moveTo(((screen.width-width)/2), ((screen.height-height)/2));
	
	try {
		win.window.focus();
		win.focus();
	} catch (e) {}
	
	return false;
}

indexPagePopupLocale='';

function popupOpen(name) {
	var page="popUpContainer.jsp";
	var param="content=" + name;
	if (indexPagePopupLocale.length != 0)
		page = indexPagePopupLocale + '/' + page;
	return wopen(page+"?"+param, "popup", 500, 400)
}

function popupOpenLarge(name) {
	var page="popUpContainer.jsp";
	var param="content=" + name;
	
	return wopen(page+"?"+param, "popup", 800, 600)
}

function openParent(url) {
	window.opener.location=url;
	window.opener.focus()
	return false;
}

function initResolution(){ 	
	var container1ID = document.getElementById('container1');
	container1ID.style.width = (screen.availWidth - ((screen.availWidth - 781)/2)) + "px";
}

function  resolution()
{
	
var headerID = document.getElementById('header');
var footerID = document.getElementById('footer');
var contentID = document.getElementById('content');
var container1ID = document.getElementById('container1');

var headerHeight = headerID.style.height.substring(0,3);
var headerWidth = headerID.style.width.substring(0,3);
var footerHeight;

if(footerID){
	footerHeight = footerID.style.height.substring(0,3);
}else{
	footerHeight = 0;
}

var fWidth = screen.availWidth - ((screen.availWidth - headerWidth)/2);
var fHeight = screen.availHeight * 0.9

var contentHeight = (fHeight - headerHeight) - footerHeight;

container1ID.style.width = fWidth+"px";
contentID.style.height = contentHeight+"px";
//container1ID.style.visibility = "visible";

/**
alert("Height:"+fHeight+","+footerHeight+","+headerHeight+","+contentHeight);
alert("Width:"+fWidth+","+headerWidth);
**/

}
var divTimeout;

/** Capture cursor position START **/
var cursorX=0;
var cursorY=0;

window.onload=function() {
	//resolution();
	
	if (window.Event) {
		if (document.captureEvents){
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = getXY;
		}
	}
	
}

function getXY(e) {
	cursorX = (window.Event) ? e.pageX : event.clientX;
	cursorY = (window.Event) ? e.pageY : event.clientY;
}
/** Capture cursor position END **/
//-->

function openIFrame(num){
	var IFrame = document.getElementById(num);
	if(IFrame){
		IFrame.style.display="block";
	}
}

function closeIFrame(num){
	var IFrame = document.getElementById(num);
	if(IFrame){
		IFrame.style.display="none";
	}
}

function toggleIFrame(num, flag){
	if (flag == 1){
		openIFrame(num);
	}else if (flag == 0){
		closeIFrame(num);
	}
}

function loginPopupHiddenS(num){
	var productTable = document.getElementById('cartTable');
	var SNode = document.getElementById(num);
	if (SNode){
		var productCol = productTable.childNodes;
		var check = 0;
		for(var a=0; a<productCol.length; a++){
			
			if(productCol[a].nodeName == 'TR' || productCol[a].nodeName == 'tr'){
				
				check ++;
			}
		}
		
		if(check >1){
			SNode.style.display="none";
		}
		
	}
}

function scrollbarControl(num){
	
	if(num == 1){
		var FrameNode = document.getElementById('cartFrame');
		var productTable = document.getElementById('cartTable');
	}else if(num == 2){
		var FrameNode = document.getElementById('materialsFrame');
		var productTable = document.getElementById('materialsTable');
	}else if(num == 3){
		var FrameNode = document.getElementById('wishFrame');
		var productTable = document.getElementById('wishTable');
	}
		var productCol = productTable.childNodes;
		var check = 0;
		for(var a=0; a<productCol.length; a++){
			
			if(productCol[a].nodeName == 'TR' || productCol[a].nodeName == 'tr'){
				check ++;
			}
		}
		if(check >3){
			FrameNode.style.overflow="scroll"; 
			FrameNode.style.height="175px";
		}else{
			FrameNode.style.overflow="visible"; 
			FrameNode.style.height="auto";
		}
}

function OpenS(num){
	var SNode = document.getElementById(num);
	if (SNode){
		SNode.style.display="inline";
	}
}

function toggleS(num, flag){
	if ( flag == 1 ){
		loginPopupHiddenS(num);
	}else if ( flag == 0 ){
		OpenS(num);
	}
}
