var ie = false;
if (navigator.appName == "Microsoft Internet Explorer") ie = true;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function set_opacity(obj,opacity) {
	if (typeof(obj)=="string") obj = document.getElementById(obj);
	obj.style['filter'] = 'alpha(opacity='+opacity*100+')';
	obj.style['-moz-opacity'] = opacity;
	obj.style['opacity'] = opacity;
}

// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function charonly(myfield) {
  var strPass = myfield.value;
  var strLength = strPass.length;
  var lchar = myfield.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);
//alert(cCode);
  if ((cCode > 96 && cCode < 123) || (cCode > 64 && cCode < 91)) {
    return false;
  } else {
    var fieldvalue = myfield.value.substring(0, (strLength) - 1);
    myfield.value = fieldvalue;
	//alert('Please enter alphabet only');
  }
}

/////
///onKeyPress="return numbersonly(this, event)";
/////

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;
	if (window.event){
		key = window.event.keyCode;
	}else if (e){
		key = e.which;
	}else{
		return true;
	}
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ){
		return true;
	}else if ((("+1234567890").indexOf(keychar) > -1)){
		return true;
	}else if (dec && (keychar == ".")){
		myfield.form.elements[dec].focus();
		return false;
	}else{
		return false;
	}
}

////// onKeyUp="tabNext(this,3, this.form.fieldname);"
function tabNext(obj, len, next) {
	if(obj.value.length == len) next.focus();
}

function auto_tab(e,event,prefix) {
	var k = event.keyCode, t = event.type;
	id=e.id.split("_");
	if ((k>=48 && k<=57 || k>=96 && k<=105) && id[1]<4) {
			if (t=="keyup" && e.value.length==e.maxLength) {
				o = document.getElementById(prefix+"_"+(1*id[1]+1));
				if(o) { o.select(); o.focus(); }
			}
		} else if (k==8) {
			if (t=="keydown" && e.value=="" && id[1]>1) {
				o = document.getElementById(prefix+"_"+(id[1]-1));
				if(o) { o.select(); o.focus(); }
				return false;
			}
		} else if (!(k==9 || k==16 || k==37 || k==39 || k==46 || k>=48 && k<=57 || k>=96 && k<=105) && id[1]<=4) {
			return false;
		}
		return true;
}

function formatCurrency(amount, cur,nocomma){
	var i = parseFloat(amount);
	if (!cur) cur='';
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i <= -0.01) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(!nocomma){
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(s)) s = s.replace(rgx, '$1' + ',' + '$2');
	}
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + cur + s;
	return s;
}

function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
		return (true);
	else
		return (false);
}

function Len(string) {
	if (string == null)
	return (false);
	return String(string).length;
}

function getWindowSize() {
	var w = {};

	if (self.innerHeight) // all except Explorer
	{
		w.w = self.innerWidth;
		w.h = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		w.w = document.documentElement.clientWidth;
		w.h = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		w.w = document.body.clientWidth;
		w.h = document.body.clientHeight;
	}


	if (self.pageYOffset) // all except Explorer
	{
		w.l = self.pageXOffset;
		w.t = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		w.l = document.documentElement.scrollLeft;
		w.t = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		w.l = document.body.scrollLeft;
		w.t = document.body.scrollTop;
	}

	var test1 = document.body.scrollHeight, test2 = document.body.offsetHeight;
	if (test1 > test2) // all but Explorer Mac
	{
		w.pw = document.body.scrollWidth;
		w.ph = document.body.scrollHeight;
	}
	else // Explorer Mac; would also work in Explorer 6 Strict, Mozilla and Safari
	{
		w.pw = document.body.offsetWidth;
		w.ph = document.body.offsetHeight;
	}

	if (self.screenX)
	{
		w.wl = self.screenX;
		w.wt = self.screenY;
	}else if(document.all) {
		w.wl = window.screenLeft;
		w.wt = window.screenTop;
	}

	return w;
}

function popupCenter(url, width, height, features) {
	var w = getWindowSize();
	//alert('w.l'+w.wl+' w.w'+w.w+' w.wt'+w.wt);
	var leftPos = (w.w-width+30)/2;
	var topPos = (w.h-height)/2;
	if(w.wl) leftPos = 1*w.wl+leftPos;
	if(w.wt) topPos = 1*w.wt+topPos;
	newwindow = window.open(url,'popupWindow','width=' + width + ',height='+height+',top='+topPos+',left='+leftPos+features);
	if (window.focus) {newwindow.focus();}
	return false;
}

function popupWindow2(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=0,resizable=no,copyhistory=no,width=360,height=600,screenX=150,screenY=150,top=150,left=150');
}

function popupWindow3(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=640,height=800,screenX=150,screenY=150,top=150,left=150');
}

function gbb_over(o,over) {
	var type = o.src.match(/(good|better|best)/)[0];
	if (over) {
		o.defSrc = o.src; 
		o.src = o.src.replace(/bv/,'reg').replace(/(on|off)/,'over');
	} else {
		o.src = o.defSrc;
	}
	document.getElementById("gbb_preview_"+type).style.display = over?'':'none';
}
// Warranty
	var wprods = [];

	function VerifyWarranty(obj) {
		var question = 'You have chosen not to purchase warranty for the following products:\n\n';
		var str = '';
		var footer = '\nAre you sure you would like to proceed? (Click cancel to purchase a warranty)';

		question_config_verify?question = question_config_verify:'';
		footer_config?footer = footer_config:'';

		if (wprods.length>0)
		{
			for (var i=0;i<wprods.length;i++)
			{
				str += (i+1)+'. '+wprods[i]+'\n';
			}
			var agree = confirm(question+str+footer);
			if (agree)
			{
				return true;
			} else {
				return false;
			}
		}
		return true;
	}
// Validate Search form
function check_search(f,v,msg) {
	if(f.keywords.value!='' && f.keywords.value!='0' && f.keywords.value!=v) return true;
	if(typeof msg !="undefined") alert(msg);
	else alert('Please enter keyword.');
	return false;
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function hideItem(objID) {
	document.getElementById(objID).style.display = "none";
}
function showItem(objID) {
	document.getElementById(objID).style.display = "";
}

function showOther(id1, id2) {
  if (id1 && id2){	
	var elem1 = document.getElementById(id1);
	var elem2 = document.getElementById(id2);
	if(elem1.style.display =="none" ||
	   elem2.style.display == "" ||
	   elem1.style.display == elem2.style.display) 
	   return;
	//alert('1--'+document.getElementById(id1).style.display);
	document.getElementById(id1).style.display = "none";
	document.getElementById(id2).style.display = "";
  }	
}

//************* as low as pop up ***************
function ShowPopup(objID,offsetX,offsetY,pObj) {

	obj = document.getElementById(objID);
	if(!obj) return;
	
	if(obj.style.display == "block") return;
	if(offsetX && offsetY && pObj) {
		obj.style.left=findPosX(pObj)+offsetX+'px';
		obj.style.top=findPosY(pObj)+offsetY+'px';
	}
	obj.style.display = "block"
	//alert(offsetX);
}
function HidePopup(objID) {
	document.getElementById(objID).style.display = "none";
}

function ShowPopupUC(objID,pObjID) {
	obj = document.getElementById(objID);
	if(!obj) return;
	pobj = document.getElementById(pObjID);
	if(!pobj) return;
	if(obj.style.display == 'block') return;

	offX = findPosX(pobj);
	offY = findPosY(pobj);
	if (navigator.appName.match(/Internet Explorer/)) {
		offX = offX - 13;
		offY = offY - 33;
	}
	obj.style.display = 'block';
	ow = obj.offsetWidth;
	pw = pobj.width;
	obj.style.left= (offX - ow/2 + pw/2)+'px';
	obj.style.top = (offY+pobj.offsetHeight)+'px';
}
//************* eof as low as pop up ***************

//*****************  Category Menu *****************************

function CatMenu(id) {
	var s = document.getElementById('smenu_'+id);
	var m = document.getElementById('arrow_img_'+id);
	var hide_current = false;
	for (var i = 1; i<=20; i++) {
		if(id == i && s.style.display=='block') { hide_current = true; }
		if(document.getElementById('smenu_'+i) && document.getElementById('smenu_'+i).style.display!='none') {document.getElementById('smenu_'+i).style.display='none';}
		if(document.getElementById('arrow_img_'+i) && document.getElementById('arrow_img_'+i).className!='arrow') {document.getElementById('arrow_img_'+i).src='images/arrow_list_cate.gif'; document.getElementById('arrow_img_'+i).className='arrow';}
	}
	if (s && !hide_current) {
		m.className='arrow-open';
		s.style.display='block';
		m.src = 'images/arrow_down_list_cate.gif';
	}
	return false;
}

//******************* eof Category Menu ************************

// ******************** LEFT MENU POPUP ************
activeMid = null;
function showPopCover() {
	if (navigator.appName.match(/Internet Explorer/) && document.getElementById('iePOP').style.visibility != 'visible')
		document.getElementById('iePOP').style.visibility = 'visible';
}
function hidePopCover(force) {
	if (!force && activeMid && document.getElementById(activeMid).style.visibility == 'visible') { return; }
	if (navigator.appName.match(/Internet Explorer/) && document.getElementById('iePOP').style.visibility != 'hidden')
		document.getElementById('iePOP').style.visibility = 'hidden';
}
var catMenus = {
  timer: null,
  activeMenuID: null,
  offX: 100,   // horizontal offset 
  offY: -25,   // vertical offset 
  isIE: null,
  show: function(id, e, pobj, offx, offy) {
	if (navigator.appName.match(/Internet Explorer/)) this.isIE = true;
    var mnu = document.getElementById? document.getElementById(id): null;
    if (!mnu) return;
    this.activeMenuID = id;
    if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
    if ( mnu.onmouseover == null ) mnu.onmouseover = this.clearTimer;
	if (this.isIE) this.offY = -33;
	if (typeof offx == "undefined") { offx = this.offX; }
	if (typeof offy == "undefined") { offy = this.offY; }
    this.position(mnu,e,pobj,offx,offy);
  },
  
  hide: function() {
	if (this.isIE && document.getElementById('iePOP').style.visibility != 'hidden')
		document.getElementById('iePOP').style.visibility = 'hidden';
    this.clearTimer();
    if (this.activeMenuID && document.getElementById) {
      this.timer = setTimeout("document.getElementById('"+this.activeMenuID+"').style.visibility = 'hidden'", 100);
	  activeMid = null;
	}
  },
  
  position: function(mnu, e, pObj,offx,offy) {
	var x = findPosX(pObj) + offx;
	var y = findPosY(pObj) + offy;
    mnu.style.left = x + "px"; mnu.style.top = y + "px";
	this.timer = setTimeout("document.getElementById('" + this.activeMenuID + "').style.visibility = 'visible'", 100);
	activeMid = this.activeMenuID;
	if(this.isIE && this.activeMenuID.match(/pop-catelist_/) && document.getElementById('iePOP').style.visibility != 'visible') {
		popc = document.getElementById('iePOP').style;
		popc.left = (x+55)+"px"; popc.top = (y-2)+"px";
		popc.width = mnu.offsetWidth-53; popc.height = mnu.offsetHeight+2;
		popc.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		document.getElementById('iePOP').style.visibility = 'visible';
	}
  },
  
  mouseoutCheck: function(e) {
    e = e? e: window.event;
    var mnu = document.getElementById(catMenus.activeMenuID);
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( mnu != toEl && !catMenus.contained(toEl, mnu) ) catMenus.hide();
  },
  
  contained: function(oNode, oCont) {
    if (!oNode) return;
    while ( oNode = oNode.parentNode ) 
      if ( oNode == oCont ) return true;
    return false;
  },

  clearTimer: function() {
    if (catMenus.timer) clearTimeout(catMenus.timer);
  }
  
}