function setClass(obj, cl){
  if (!cl) cl = '';  
  obj.className = cl;
}

function DeleteCategory(deleteurl, cat_name) {
	if (confirm('Are you sure to delete category \"'+cat_name+'\" ?\n All products in this category will also be deleted.')) {
		this.location = deleteurl;
	}
}
function DeleteBrand(deleteurl, brand_name) {
	if (confirm('Are you sure to delete brand \"'+brand_name+'\" ?\n All products of this brand will also be deleted.')) {
		this.location = deleteurl;
	}
}

function DeleteProduct(deleteurl, prod_name) {
	if (confirm('Are you sure to delete product \"'+unescape(prod_name)+'\" ?')) {
		this.location = deleteurl;
	}
}

function ConfirmLogout() {
	return confirm('Are you sure to logout?');
}

function LimitTextArea(limit, name) {
	if (name.value.length > limit) {
		alert('Please enter only '+limit+' chars.'); 
		name.value=name.value.substring(0, limit) ;
	}
}

 function wopen(wurl,wname,w,h) {
	ww=window.open(wurl,wname,'width='+w+',height='+h+',resizable=1,scrollbars=no,menubar=no,status=no');	
	ww.resizeTo(w,h);
	ww.focus();
	}

function OpenWin(win_url, win_name, w, h) {
	ww = window.open(win_url, win_name, 'width = '+w+', height = '+h+', resizable = 1, scrollbars = no, menubar = no,status = no');	
	ww.resizeTo(w, h);
	ww.focus();
}


function setClassById(objid, cl){
  if (!cl) cl = '';  
  document.getElementById(objid).className = cl;
}

function changeDisplayById(objId){
  for (c = 0; c < changeDisplayById.arguments.length; c++){
	obj = document.getElementById(changeDisplayById.arguments[c]);
	if (obj.style.display == 'none') obj.style.display = 'block';
	else obj.style.display = 'none';
  }  
}

function gotoURL(url){
  if (!url) url = "/";
  if (window.event){
	var src = window.event.srcElement; 
	if((src.tagName != 'A') && ((src.tagName != 'IMG') || (src.parentElement.tagName != 'A'))){
	  if (window.event.shiftKey) window.open(url);
	  else document.location = url;
	}
  } else document.location = url;
}

function popupURL(url){
 window.open(url);
}

function getLeftPos(obj){
  var res = 0;
  while (obj){
	res += obj.offsetLeft;
	obj = obj.offsetParent;
  }
  return res;
}

function trim(str){
  var re = /^ */;
  var res = str.replace(re, '');
  re = / *$/;
  return(res.replace(re, ''));
}

function isNumber(str) {
	var re = /^\d*\.?\d*$/;
	str = str.toString( );
	if (!str.match(re)) {
		return false;
	}
	return true;
}

function isEmail(mailstr){
	var re = /^ *([a-z0-9_-]+\.)*[a-z0-9_-]+@(([a-z0-9-]+\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2})|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) *$/;
	if (!mailstr.match(re)) {		
		return false;
	}
	return true;
}

function getTopPos(obj){
  var res = 0;
  while (obj){
	res += obj.offsetTop;	
	obj = obj.offsetParent;
  }
  return res;
}

function chbCheckAll(formId, checkName, checkVal){
  var checkCount = 0;
  var el = document.forms[formId].elements;
  for (count = 0; count < el.length; count++){
   if (el[count].name == checkName + checkCount){
	if (!el[count].disabled){
	  el[count].checked = checkVal;
	}
	checkCount++;
   }
  }
}

function chbSetRestore(formObj, checkName, checkVal){
	var el = formObj.elements;
	if( checkVal ){
		document[checkName] = new Array();
		for (count = 0; count < el.length; count++)
			if (el[count].name == checkName + '[]'){
				document[checkName][count] = el[count].checked;
				el[count].checked = checkVal;
			}
	}
	else{
		for (count = 0; count < el.length; count++)
			if (el[count].name == checkName + '[]'){
				el[count].checked = document[checkName][count];
			}
	}
}

function chbExamAll(formId, checkName, resName){
  var checkCount = 0;
  var boxCount = 0;
  var el = document.forms[formId].elements;  
  for (count = 0; count < el.length; count++){
   if (el[count].name == checkName + boxCount){
	boxCount++;
	if (el[count].checked || el[count].disabled) checkCount++;
   }
  }
  document.forms[formId].elements[resName].checked = (checkCount == boxCount);
}

function chbIsAllEmpty(formId, checkName){
  var checkCount = 0;
  var boxCount = 0;
  var el = document.forms[formId].elements;
  for (count = 0; count < el.length; count++){
   if (el[count].name == checkName + boxCount){
	boxCount++;
	if (el[count].checked) checkCount++;
   }
  }
  return(checkCount == 0);
}

function chbIsOnlyOne(formId, checkName){
  var checkCount = 0;
  var boxCount = 0;
  var el = document.forms[formId].elements;
  for (count = 0; count < el.length; count++){
   if (el[count].name == checkName + boxCount){
	boxCount++;
	if (el[count].checked) checkCount++;
   }
  }
  return(checkCount == 1);
}

function disableAll(){
  for (c1 = 0; c1 < document.forms.length;  c1++){
	var formElements = document.forms[c1].elements; 
	for (c2 = 0; c2 < formElements.length;  c2++) formElements[c2].disabled = true;
  }
}

function FormSubmit_s(formObject) {
	try {
		formObject.submit();
	}
	catch(error){
		if( error.name == "TypeError")
		{
			alert("Please enter a valid path in the Add Image field!");
			return false;
		}
	}
	return true;
}