/* common.js */


function addProduct(frmName, productID, productPage, params) {
	var frm = eval("document." + frmName);
	var productQuantity = parseInt(frm.productQty.value);
	var productLink = productPage + "?product_id=" + productID + "&sc=add&productQty=" + productQuantity + "&" + params;
	location.href = productLink;
	return false;
}


function on_focus() {	
	if (launched_window) { 	
		launched_window.close();
		launched_window = null;
	}
}

function close_window() {	
	window.close();
	return false;
}

function new_window(url, name, window_width, window_height, fullscreen) { 	
	if (window_width == null) window_width = screen.availWidth-10; 
	if (window_height == null) window_height = screen.availHeight-50;
	if (name == null) name = "_system";
	if (fullscreen == null) fullscreen = 0;
	window_properties = "fullscreen=" + fullscreen + ",toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,top=0,left=0,width=" + window_width + ",height=" + window_height;
	launched_window = window.open(url, name, window_properties);
}

// trim
function trim(str){
	if (str == null)
		return;

	while(''+str.value.charAt(0)==' ')
	str.value=str.value.substring(1,str.value.length);

	while(''+str.value.charAt(str.value.length-1)==' ')
	str.value=str.value.substring(0,str.value.length-1);
}

// textarea max length
function isMaxLength(obj) {
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}

// hover
function bhover(loc, cls) {
	if(loc.className)
		loc.className=cls;
}

// cell hover
function chover(obj, style) {
  obj.className = style;
}

/* generic select and deselect all */
function select_all(fld, btn) {
	if (btn.value == "+")
		action = true;
	else 
		action = false; 
	len = fld.length;
	for(i=0; i<len; i++) {
		fld[i].checked = action;
	}
}

function toggleDIV(div, display) {
	s = getElement(div).style;
	if (display == null) {
		if (s.display == "none")
			s.display = "block";
		else
			s.display = "none";
	} else {
		s.display = display;
	}
}

function setDIV(div, display) {
	s = getElement(div).style;
	if (display == null) 
		display = "none";
	s.display = display;
}

function setHTML(div, div2) {
	getElement(div).innerHTML = getElement(div2).innerHTML;
}

function getElement(div) {
	if (document.getElementById) {
		s = document.getElementById(div);
	} else if (document.all) {
		s = document.all[div];
	} else if (document.layers) {
		s = document.layers[div];
	}
	return s;
}
