function OnlyNumber() {
	if((event.keyCode==47) || ((event.keyCode<46)||(event.keyCode>57)) ){event.returnValue=false;}
}

function OnlyNumberABS() {
	if(((event.keyCode<48)||(event.keyCode>57))){event.returnValue=false;}
}

function orFloor(el) { //9 or 9.01 or 0.99
	var pattern = /^(([1-9]{1}([0-9])*)?.(([0-9]{2})?)|([0-9]{1}).(([0-9]{2})?))$/;
	if (pattern.exec(el.value) && (el.value > 0)) { 
		return true;
	} else {
		return doError(el,"sel");
	}
}

function doError(el,action) {
	if (action == "")	{
		el.focus(true);
	} else if (action == "sel") {
		el.select();
	} else if (action == "del")	{
		el.value = "";
	}
	el.focus();
	return false;
}

function isNull(input) {
    if (input.value == null || input.value == "") {
        return true;
    }
    return false;
}

function isEmpty(input) {
    if (input.value == null || input.value.replace(/ /gi,"") == "") {
        return true;
    }
    return false;
}

function removeComma(input) {
    return input.value.replace(/,/gi,"");
}

function getByteLength(input) {
    var byteLength = 0;
    for (var inx = 0; inx < input.value.length; inx++) {
        var oneChar = escape(input.value.charAt(inx));
        if ( oneChar.length == 1 ) {
            byteLength ++;
        } else if (oneChar.indexOf("%u") != -1) {
            byteLength += 2;
        } else if (oneChar.indexOf("%") != -1) {
            byteLength += oneChar.length/3;
        }
    }
    return byteLength;
}

function isValidFormat(input,format) {
    if (input.value.search(format) != -1) {
        return true; 
    }
    return false;
}

function isValidEmail(input) {
    var format = /^((\w[\-\.])+)@((\w[\-\.])+)\.([A-Za-z]+)$/;
    return isValidFormat(input,format);
}

function isNumberAlphabat(input) {
    var format = /^([0-9A-Za-z]+)$/;
    return isValidFormat(input,format);
}

function validate(field) { 
	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 
	var ok = true; 
	var temp; 
	for (var i=0; i<field.value.length; i++) { 
		temp = "" + field.value.substring(i, i+1); 
		if (valid.indexOf(temp) == "-1") ok = false; 
	} 
	if (ok == false) { 
		alert("Number or Alphabat"); 
		field.focus(); 
		field.select(); 
	} 
} 

function jsImagesPreview(img, iid) {
	Imagesid = iid;  
	if(event.srcElement.value.match(/(.jpg|.jpeg|.gif|.png|.JPG|.JPEG|.GIF|.PNG|[0-9]{10})/)){
		document.images[Imagesid].src = event.srcElement.value;
		document.images[Imagesid].style.display = '';
	} else {
		if(img) {
			document.images[Imagesid].src = img;
			document.images[Imagesid].style.display = '';
		} else {
			document.images[Imagesid].src = '/images/line.gif';
			document.images[Imagesid].style.display = '';
		}
	}
}

function show_img(id,type) {
	if(type=="") type = "big";
	var Twin=window.open("", "_blank","scrollbars=yes,top=0,left=0,width=800,height=600");
	Twin.location.href = "/product/show.html?type="+type+"&p_code="+id;
}

function show2_img(id,type) {
	if(type=="") type = "big";
	var Tw = (screen.width/2)-160;
	var Th = (screen.height/2)-160;
	var Twin=window.open("", "_blank","scrollbars=no,top="+Th+",left="+Tw+",width=320,height=300");
	Twin.location.href = "/product/show2.html?type="+type+"&p_code="+id;
}

function showself_img(id,type) {
	if(type=="") type = "big";
	var Twin=window.open("", "_blank","scrollbars=yes,top=0,left=0,width=800,height=600");
	Twin.location.href = "/product/selfshow.html?type="+type+"&code="+id;
}

function showpopupimg(page,img) {
	window.open(page+"?img="+img, "_blank","scrollbars=yes,top=0,left=0,width=800,height=600");
}

function popup(page) {
	window.open(page, "_blank","scrollbars=yes,top=0,left=0,width=800,height=600");
}
function resize_popup(w,h) {
	var clintAgent = navigator.userAgent;

	if ( clintAgent.indexOf("MSIE") != -1 ) {
		// IE
		window.resizeBy(w-document.body.clientWidth, h-document.body.clientHeight);
	} else {
		window.resizeBy(w-window.innerWidth, h-window.innerHeight);
	}
}


     window.onerror = null;
     var bName = navigator.appName;
     var bVer = parseInt(navigator.appVersion);
     var NS4 = (bName == "Netscape" && bVer >= 4);
     var IE4 = (bName == "Microsoft Internet Explorer"  && bVer >= 4);
     var NS3 = (bName == "Netscape" && bVer < 4);
     var IE3 = (bName == "Microsoft Internet Explorer"  && bVer < 4);
     var blink_speed=500;
     var i=0;
 
    if (NS4 || IE4) {
         if (navigator.appName == "Netscape") {
            layerStyleRef="layer.";
             layerRef="document.layers";
             styleSwitch="";
         }else{
            layerStyleRef="layer.style.";
            layerRef="document.all";
            styleSwitch=".style";
         }
    }

    //BLINKING
    function Blink(layerName){
        if (NS4 || IE4) { 
            if(i%2==0)         {
                eval(layerRef+'["'+layerName+'"]'+
                styleSwitch+'.visibility="visible"');
            }else{
                eval(layerRef+'["'+layerName+'"]'+
                styleSwitch+'.visibility="hidden"');
            }
        } 

        if(i<1){
            i++;
        }else{
            i--
        }
        setTimeout("Blink('"+layerName+"')",blink_speed);
    }
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];}
}
