<!--Copyright Info-->
<!--The contents of this file are copyrighted by Zyz International Technology -->
<!--All Rights Reserved.  You are not permitted to copy or use this script in any circumstances -->

NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
ver4 = (NS4 || IE4) ? 1 : 0;

if (ver4) {
with (document) {
write("<STYLE TYPE='text/css'>");
if (NS4) {
write(".parent {position:absolute; visibility:visible}");
write(".child {position:absolute; visibility:visible}");
write(".regular {position:absolute; visibility:visible}")
}
else {
write(".child {display:none}")
}
write("</STYLE>");
}
}

function getIndex(el) {
ind = null;
for (i=0; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id == el) {
ind = i;
break;
}
}
return ind;
}

function arrange() {
nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;
for (i=firstInd+1; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.visibility != "hide") {
whichEl.pageY = nextY;
nextY += whichEl.document.height;
}
}
}

function initIt(){
//if (!ver4) return;
if (NS4) {
for (i=0; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
}
arrange();
}
else {
divColl = document.all.tags("DIV");
for (i=0; i<divColl.length; i++) {
whichEl = divColl[i];
if (whichEl.className == "child") whichEl.style.display = "none";
}
}
}

function expandIt(el) {
//if (!ver4) return;
if (IE4||!NS4) {
whichEl = eval(el + "Child");
if (whichEl.style.display == "none") {
whichEl.style.display = "block";
}
else {
whichEl.style.display = "none";
}
}
else {
whichEl = eval("document." + el + "Child");
if (whichEl.visibility == "hide") {
whichEl.visibility = "show";
}
else {
whichEl.visibility = "hide";
}
arrange();
}
}

function makevisible(cur,which)
{
  strength=(which==0)? 1 : 0.7
  if (cur.style.MozOpacity)
    cur.style.MozOpacity=strength;
  else if (cur.filters)
    cur.filters.alpha.opacity=strength*100;
}

function setShopCartID()
{
	var sShopCardID = getCookie("shopcartid");
//alert("CookID" + sShopCardID);
	if (!sShopCardID)
	{
	   sShopCardID = getUniqueID();
	   setCookie("shopcartid", sShopCardID);
	}

	return true;
}

function getCookie(name)
{
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((start == -1) || ((!start) && (name != document.cookie.substring(0,name.length))))
		return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1)
		end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function setCookie(name,value)
{
   document.cookie = name + "=" + escape(value) + ";expires=Thu, 01-Jan-2050 00:00:01 GMT";
}

function getUniqueID()
{
	var dt = "" + new Date().getTime();
	var sID = "";
	for (i=dt.length-1; i>dt.length-9; i--)
	{
	    sID += dt.substring(i, i+1);
	}

	sID += '_';
	var num = "" + Math.random()*1000000;
	for (i=0; i<4; i++)
	{
	   sID += num.substring(i, i+1);
	}

	return sID;
}

function checkFieldEmpty(objField)
{
	var sValue = trim(objField.value);
    return sValue.length==0;
}

function validateEmail(objEmail)
{
	if (!validateEmailValue(objEmail.value))
	{
		setFocus(objEmail);
		return false;
	}
	else
	  return true;
}

function validateEmailValue(strEmail)
{
	 var at="@"
	 var dot="."
	 var lat=strEmail.indexOf(at)
	 var lstr=strEmail.length
     var ldot=strEmail.indexOf(dot)

	 if (strEmail.indexOf(at)==-1)
	 {
	     alert("Invalid E-mail Address.")
		 return false;
	 }

	 if (strEmail.indexOf(at)==-1 || strEmail.indexOf(at)==0 || strEmail.indexOf(at)==lstr)
	 {
	     alert("Invalid E-mail Address.")
		return false;
	 }

	 if (strEmail.indexOf(dot)==-1 || strEmail.indexOf(dot)==0 || strEmail.indexOf(dot)==lstr)
	 {
	     alert("Invalid E-mail Address.")
		return false;
	 }

	 if (strEmail.indexOf(at,(lat+1))!=-1)
	 {
	     alert("Invalid E-mail Address.")
		return false;
	 }

	 if (strEmail.substring(lat-1,lat)==dot || strEmail.substring(lat+1,lat+2)==dot)
	 {
	     alert("Invalid E-mail Address.")
		return false;
	 }

	 if (strEmail.indexOf(dot,(lat+2))==-1)
	 {
	     alert("Invalid E-mail Address.")
		return false;
	 }

	 if (strEmail.indexOf(" ")!=-1)
	 {
	     alert("Invalid E-mail Address.")
	    return false;
	 }

	 return true;
}

function setFocus(objInput)
{
	objInput.focus();
	objInput.select();
}

function trim(str)
{
	var nStart = 0;
	var nEnd = str.length;//-1;
	if (nEnd<0)
	   return str;

	for (var i=0; i<=nEnd; i++)
	{
	  if (str.charCodeAt(i)!=32)
	     break;
	  nStart = i+1;
	}

	if (nStart>=nEnd)
	   return "";

	for (var i=nEnd; i>=0; i--)
	{
	  if (str.charCodeAt(i)!=32)
	     break;
	  nEnd = i-1;
	}
	nEnd++;
	str = str.substring(nStart, nEnd);
	return str;
}

function createTableOpen(){
	document.write("<TABLE cellspacing='0' cellpadding='0' border='0' align='center'><TR><TD colspan='2' height='7' rowspan='2'><IMG height='7' src='images/corner1.gif' width='7'></TD><TD style='border-top: 1px solid #BBBBBB;'><IMG height='1' src='images/clearpixel.gif' width='1' border='0'></TD><TD colspan='2' height='7' rowspan='2'><IMG height='7' src='images/corner2.gif' width='7'></TD></TR><TR valign='top'><TD><IMG height='5' src='images/clearpixel.gif' width='1' border='0'></TD></TR><TR valign='top'><TD width='1' style='border-left: 1px solid #BBBBBB;'><IMG height='1' src='images/clearpixel.gif' width='1' border='0'></TD><TD width='5'><IMG height='1' src='images/clearpixel.gif' width='5' border='0'></TD><TD bgcolor='#FFFFFF' valign='top'>");
}
function createTableClose(){document.write("</TD><TD width='5'><IMG height='1' src='images/clearpixel.gif' width='5' border='0'></TD><TD width='1' style='border-right: 1px solid #BBBBBB;'><IMG height='1' src='images/clearpixel.gif' width='1' border='0'></TD></TR><TR valign='bottom'><TD colspan='2' height='7' rowspan='2'><IMG height='7' src='images/corner3.gif' width='7'></TD><TD style='border-bottom: 1px solid #BBBBBB;'><IMG height='1' src='images/clearpixel.gif' width='1' border='0'></TD><TD colspan='2' height='7' rowspan='2'><IMG height='7' src='images/corner4.gif' width='7'></TD></TR></TABLE>");}

function createLeftButton(){
	document.write("<TABLE border='0' cellspacing='0' cellpadding='0' height='22'><TR><TD width='10' height='22'align='left' valign='middle'><IMG src='images/btt_left.gif' width='10' height='22'></TD><TD bgcolor='#0C2E82' height='22'>");
}
function createRightButton(){
	document.write("</TD><TD width='10' align='left' valign='middle'><IMG src='images/btt_right.gif' width='10' height='22'></TD></TR></TABLE>");
}

function writeDate()
{
  var d=new Date();
  var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
  var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//  document.write('<b><font size="1" face="Arial,Geneva,Sans Serif" color="#000000">');
  document.write(weekday[d.getDay()] + ", ");
  document.write(monthname[d.getMonth()] + " ");
  document.write(d.getDate() + ", ");
  document.write(d.getFullYear());
//  document.write('</font></b>');
}

function checkDateFormat(strValue,strFormat)
{
  var msg = "Invalid date format.\nCorrect date format is "+strFormat;
  if (strValue.length != strFormat.length)
  {
    alert(msg);
    return false;
  }
  else
  {
    if (strFormat == "MM/DD/YYYY")
    {
      if (strValue.substr(2,1)!="/"||strValue.substr(5,1)!="/"||strValue.substr(0,2)>'12'||strValue.substr(3,2)>'31'||strValue.substr(6,4)>'3000'){
        alert(msg);return false;}
    }
    else if (strFormat == "MM/YYYY")
    {
      if (strValue.substr(2,1)!="/"||strValue.substr(0,2)>'12'||strValue.substr(3,4)>'3000')
      {
        alert(msg);
        return false;
      }
    }
  }
  return true;
}

function autoFormat(obj,type)
{
  if (event.keyCode!=8){
    var len = obj.value.length;
    var val = obj.value.charAt(len-1);
    var preVal = obj.value.charAt(len-2);
    var maxLen = obj.getAttribute("maxlength");

    if(type=="N"||type=="n") {
      if(!('0' <= val && val <= '9')) obj.value = obj.value.substr(0,len-1);
      if(len > maxLen) obj.value = obj.value.substr(0,len+1);
    }
    else if(type == "D") {
      if('0' <= val && val <= '9'){
        if(len == '1' && val > '1') obj.value = "0" + obj.value + "/";
        else if((len == '5' && preVal == '0' && val != '0') || (len == '2' && val < '3' && preVal != '0') || (len == '2' && preVal == '0' && val != '0') || (len == '5' && preVal < '3' && preVal > '0') || (len == '5' && val < '2' && preVal == '3')) obj.value = obj.value + "/";
        else if((len == '2' && val >= '3' && preVal == '1') || (len == '2' && preVal == '0') || (len == '5' && preVal == '0') || (len == '5' && val > '1' && preVal >= '3')) obj.value = obj.value.substr(0,len-1);
        else if(len == '4' && val > '3') obj.value = obj.value.substr(0,len-1) + "0" + val + "/";
      }
      else if( val == '/') {
        if(len == '2' && preVal == '1') obj.value = "0" + preVal + "/";
        else if(len == '1' && preVal == "") obj.value = "";
        else if((len == '2' && preVal == '0') || len == '4' || (len == '5' && preVal <= '3') || (len == '5' && preVal == '0') || (len < '11' && len >= '7')) obj.value = obj.value.substr(0,len-1);
      }
      else obj.value = obj.value.substr(0,len-1);
    }
    else if(type == 'd') {
      if('0' <= val && val <= '9'){
        if(len == '1' && val > '1') obj.value = "0" + obj.value + "/";
        else if((len == '2' && val < '3' && preVal != '0') || (len == '2' && preVal == '0' && val != '0')) obj.value = obj.value + "/";
        else if((len == '2' && preVal == '0') || (len == '2' && val >= '3' && preVal == '1')) obj.value = obj.value.substr(0,len-1);
      }
      else if( val == '/') {
        if(len == '2' && preVal == '1') obj.value = "0" + preVal + "/";
        else if(len == '1' && preVal == "") obj.value = "";
        else if((len == '2' && preVal == '0') || len == '4' || (len == '5' && preVal <= '3') || (len == '5' && preVal == '0') || (len < '8' && len >= '4')) obj.value = obj.value.substr(0,len-1);
      }
      else obj.value = obj.value.substr(0,len-1);
    }
    else if(type=='F') {
      if(!(('0' <= val && val <= '9') || val == '.'))
        obj.value = obj.value.substr(0,len-1);
    }
    /*else if(type == "S") { //for String it could be anything
            if(!((val >= 'a' && val <= 'z') || (val >= 'A' && val <='Z') || ('0' <= val && val <= '9') || (val == ' ') || (val == '-')))
                    obj.value = obj.value.substr(0,len-1);
            if(len > maxLen) obj.value = obj.value.substr(0,len+1);
    }*/
  }
}

function validateGoSearch(form)
{
  //1. check the product name
  if (checkFieldEmpty(form.productname))
  {
     alert("You have to enter product name.");
     setFocus(form.productname);
     return false;
  }
  else
    return true;
}

function validateAdvancedSearch(form)
{
  //. check Category
  var bRet = false;
  if (form.category.selectedIndex>0)
  {
     bRet = true;
  }
  //. check sub-category
  if (form.subcategory.selectedIndex>0)
  {
     bRet = true;
  }
  //. check the price from
  if (!checkFieldEmpty(form.price_from))
  {
     bRet = true;
  }
  //. check price to
  if (!checkFieldEmpty(form.price_to))
  {
     bRet = true;
  }
  //. check product name
  if (!checkFieldEmpty(form.name))
  {
     bRet = true;
  }

  if (bRet)
     return true;

  alert("You have to input some value on or select at least one of fields.");
  form.category.focus();
  return false;
}

function OnLogonLoad(form)
{
  setFocus(form.email);
}

function validateLogon(form)
{
  //1. check the email
  if (checkFieldEmpty(form.email))
  {
     alert("You missed to input email.");
     setFocus(form.email);
     return false;
  }

  if (!validateEmail(form.email))
     return false;

  if (checkFieldEmpty(form.password))
  {
     alert("You missed to input password.");
     setFocus(form.password);
     return false;
  }

  return true;
}

//. For forgot account
function hasEmailAccount(form)
{
  if (checkFieldEmpty(form.email))
  {
     alert("You missed to input email.");
     setFocus(form.email);
     return false;
  }

  if (!validateEmail(form.email))
     return false;
  else
     return true;
}

function submitForgotPassword(form)
{
   form.action1.value = "forgotpassword";
//alert("submit=" +   form.action.value);
   form.submit();
}

function validatePayCreditCard(form1, form2)
{
    form2.custom.value = form1.comment.value;
    return true;
}

function validatePayPal(form1, form2)
{
    form2.amount.value = "0.01";
    form2.custom.value = form1.comment.value;
    return true;
}

function validatePayCheck(form1, form2)
{
   form2.custom.value = form1.comment.value;
   return true;
}







