var httpbase = "/Sshop/";

var activeDepartment = ''



function clearText(el) {

	if (el.name == 'password') {

		el.type = 'password';

	}

	el.value = "";

}



function deptInit() {

	if (activeDepartment != '') {

		menuToggle('false', activeDepartment);

	}

}



function Browser() {



  var ua, s, i;



  this.isIE    = false;  // Internet Explorer

  this.isNS    = false;  // Netscape

  this.version = null;



  ua = navigator.userAgent;



  s = "MSIE";

  if ((i = ua.indexOf(s)) >= 0) {

    this.isIE = true;

    this.version = parseFloat(ua.substr(i + s.length));

    return;

  }



  s = "Netscape";

  if ((i = ua.indexOf(s)) >= 0) {

    this.isNS = true;

    this.version = parseFloat(ua.substr(i + s.length));

    return;

  }



  // Treat any other "Gecko" browser as NS 6.1.



  s = "Gecko";

  if ((i = ua.indexOf(s)) >= 0) {

    this.isNS = true;

    this.version = 6.1;

    return;

  }

}



var browser = new Browser();

var menu = "off";

var timeout;

var activeMenu = false;



function createProductLink(form) {

	var quantity = form.qty.value;

	var prod_id =  form.product_id.value;

	var dept_id =  form.department_id.value;

	window.location = httpbase + "D" + dept_id + "/P" + prod_id + "/Q" + quantity + "/";

	return false;

}



function allAreNums() {

	var fields = 0;

	var element;

	for (var i = 0; i < document.cartForm.length; i++) {

		element = document.cartForm.elements[i];

		if (((element.value == null) || (element.value == "") || isNaN(element.value))) {

			element.value = 1;

			fields = 1;

		}

	}

	if (fields) {

		alert("Please use only numbers in the Quantity fields.\n");

	}

	else {

		document.cartForm.submit();

	}

}



function swapImg(image, filename, on) {

	image.src = filename;

	//alert(i + "\n" + idn);

}



function menuToggle(image, idn) {

	if (image != 'false') {

		image.blur();

	}

	var el = document.getElementById('subs_' + idn);

	if (el.style.display == 'block') {

		el.style.display = 'none';

	}

	else {

		el.style.display = 'block';

	}

	clearTimeout(timeout);

	menu_off();

	return false;

}



function subMenuToggle(image, idn) {

	//if the menu is toggled off toggle it on

	if (menu == "on") {

		timeout = setTimeout("menu_off()", 1000);

		menu = "off";

	}

	else {

		clearTimeout(timeout);

		menu_off();	

		menu_on(image, idn);

		menu = "on";

	}

}



function menu_on(image, idn) {

	var x, y;



	x = getPageOffsetLeft(image);

	y = getPageOffsetTop(image) + image.offsetHeight;

	  

	// For IE, adjust position.

	if (browser.isIE) {

    		x += image.offsetParent.clientLeft + 50;

		y += image.offsetParent.clientTop - 10;

  	}

	else if (browser.isNS){

    		x +=  50;

		y -= 5 ;

	}

		

	//x = image.offsetLeft + image.offsetWidth;

	//y = getPageOffsetTop(image) + image.offsetTop;

	//y = getPageOffsetTop(image);



	//var pattern = new RegExp("^dept_(" + idn + "_[0-9]+)");



	var div = document.getElementById("slave_" + idn);

	div.style.left = x + 'px';

	div.style.top = y + 'px';

	div.style.visibility = "visible";

	div.style.display = "block";

	activeMenu = idn;



	/*var pattern = new RegExp("^(" + idn + "_[0-9]+)");

	for (k = 0; k < document.anchors.length; k++) {

		var result = document.anchors[k].name.match(pattern);

		if (result != null) {

			div = document.getElementById(result[1]);

			div.style.visibility = "visible";

			div.style.display = "block";

		}

	}*/





	/*var layers = document.all.tags("DIV");

	for(var i=0;i<layers.length;i++){

		if(layers[i].className == "sub_slave"){

			if(layers[i].id.match(pattern) != null) {

				layers[i].style.visibility='visible';

				layers[i].style.display = "block";

			}

		}

	}*/

}



function menu_off() {

	//var div = document.getElementById("sub_master");

	if (activeMenu) {

		var div = document.getElementById('slave_' + activeMenu);

		div.style.visibility = "hidden";

	}



	 /*for (k = 0; k < document.anchors.length; k++) {

		 var pattern = new RegExp("^([0-9]+_[0-9]+)");

		 var result = document.anchors[k].name.match(pattern);

		 if (result != null) {

			div = document.getElementById(result[1]);

			div.style.visibility = "hidden";

			div.style.display = "none";

		}

	}*/



	/*var layers = document.all.tags("DIV");

	for(var i=0;i<layers.length;i++){

		if(layers[i].className == "sub_slave" && layers[i].style.visibility=="visible"){

			layers[i].style.visibility='hidden';

			layers[i].style.display = "none";

		}

	}*/

}





function getPageOffsetLeft(el) {



  var x;



  // Return the x coordinate of an element relative to the page.



  x = el.offsetLeft;

  if (el.offsetParent != null)

    x += getPageOffsetLeft(el.offsetParent);



  return x;

}



function getPageOffsetTop(el) {



  var y;



  // Return the x coordinate of an element relative to the page.



  y = el.offsetTop;

  if (el.offsetParent != null)

    y += getPageOffsetTop(el.offsetParent);



  return y;

}

function borderhigh(which,color){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
	which.style.borderColor=color;
	}
}

function popUp(url) {
	window.open(url, 'popup', 'width=400,height=350,status=yes,resizable=yes,scrollbars=yes');
}

function popUp_menu(url) {
	window.open(url, 'popup', 'width=400,height=550,status=yes,resizable=yes,scrollbars=yes');
}

function popUp_offer(url) {
	window.open(url, 'popup', 'width=400,height=550,status=yes,resizable=yes');
}

function scale_image(inimg, inwidth, inheight) {
	document.write('<a href="javascript:popUp(\''+inimg +'\')"><img src='+inimg+' class="sub_image" ');
	document.write(' width=140 height='+ parseInt((inheight/inwidth)*140));	
	document.write(' onMouseover="borderhigh(this,\'#FF3300\')" onMouseout="borderhigh(this,\'white\')"></a>');
}

function scale_menu(inid, inimg, inwidth, inheight) {
	document.write('<a href="javascript:popUp_menu(\'/MENU/'+inid +'/\')"><img src='+inimg+' class="sub_image" ');
	document.write(' width=140 height='+ parseInt((inheight/inwidth)*140));
	document.write(' onMouseover="borderhigh(this,\'blue\')" onMouseout="borderhigh(this,\'white\')"></a>');
}



