function openwin(path) {
  try {
	var win = window.open(path, "batteryspecs", "width=680,height=470,left=0,top=0,scrollbars=yes,resizable=no,menubar=0,location=0");
  } catch(ex) {
    return true;
  }
  return false;
}

function historyBack() {
  history.back();
  return false;
}

function submitVerify(el) {
  var obj = el.pid;
  var isCheck = false;
  if (obj.length == undefined) {
	isCheck = obj.checked;
  } else {
    for(var i=0; i<obj.length; i++){
      if(obj[i].checked) {
	    isCheck = true;
	    break;
	  }
    } 
  }
  if (!isCheck) {
	return false;
  }
  var inquiry = el.inquiry;
  if (inquiry.length == undefined) {
    inquiry.disabled = true;
  } else {
    for(var i=0; i<inquiry.length; i++){
      inquiry[i].disabled = true;
	}
  }

  var wishlist = el.wishlist;
  if (wishlist.length == undefined) {
    wishlist.disabled = true;
  } else {
    for(var i=0; i<wishlist.length; i++){
      wishlist[i].disabled = true;
	}
  }

  if (_product_action=="inquiry") {
	el.action = "/service/inquiry";	
  } else if (_product_action=="wishlist") {
	el.action = "/shopping/wish_list";
  }

  return true;
}

var _product_action = "inquiry";

function inquirySubmit() {
   _product_action = "inquiry";
}

function wishlistSubmit() {
   _product_action = "wishlist";
}

function checkProduct(el) {
  for (var i=0; i<document.productList.elements.length; i++) {
	var e=document.productList.elements[i];
	if (e.name == "pid" && e.type == "checkbox") e.checked = el.checked;
	if (e.name == "chkTotal" && e.type == "checkbox") e.checked = el.checked;
  }
}

function addToCart(pid) {
  document._shopping_cart.pid.value = pid;
  document._shopping_cart.submit();
}

function chgSeries(el) {
  if (el.value.isBlank()) return;
  if (el.value.startsWith("http")) {
    window.location = el.value;
	return;
  }
  window.location = "/browse/" + el.value + "/";
}

function chgProductSort(el) {
  if (el.value.isBlank()) return;
  var url = document.productList.url.value;
  var perpage = document.productList.perpage.value;
  window.location = url + el.value + ",s." + perpage + ",p.1.shtml";
}

function chgProductPerpage(el) {
  if (el.value.isBlank()) return;
  var url = document.productList.url.value;
  var sort = document.productList.sort.value;
  if (sort.isBlank()) {
	window.location = url + "s." + el.value + ",p.1.shtml";
	return;
  }
  window.location = url + sort + ",s." + el.value + ",p.1.shtml";
}

function gotoPage() {
  var viewUrl = document.productList._view_url.value;
  var totalPage = parseInt(document.productList._total_page.value, 10);
  var gotoPage = document.productList._goto.value;
  if (!isInteger(gotoPage)) {
	document.productList._goto.style.background="#eff";
	return;
  }
  var page = parseInt(gotoPage, 10);
  if (page > totalPage) page = totalPage;
  if (page < 1) page = 1;
  window.location = viewUrl.replace("{PAGE}", page);
}

function returnPage(el, obj) {
  obj.style.background = "";
  if (el.keyCode==13) {
	gotoPage();
	return true;
  }	
}

function prevPage() {
  var viewUrl = document.productList._view_url.value;
  var page = parseInt(document.productList._page.value, 10);
  page--;
  window.location = viewUrl.replace("{PAGE}", page);
}

function nextPage() {
  var viewUrl = document.productList._view_url.value;
  var page = parseInt(document.productList._page.value, 10);
  page++;
  window.location = viewUrl.replace("{PAGE}", page);
}

function chgProductSearchSort(el) {
  if (el.value.isBlank()) return;
  var url = document.productList.url.value;
  var perpage = document.productList.perpage.value;
  window.location = url + "&sort=" + el.value + "&perpage" + perpage + ",p.1.shtml";
}

function chgProductSearchPerpage(el) {
  if (el.value.isBlank()) return;
  var url = document.productList.url.value;
  var sort = document.productList.sort.value;
  if (sort.isBlank()) {
	window.location = url + "&perpage=" + el.value;
	return;
  }
  window.location = url + "&sort=" + sort + "&perpage=" + el.value;
}
