﻿var loaded = new Array();

function F_loadRollover(image,imageName) {	
   if (image && image.src &&
    (null == image.out || typeof(image.out) == typeof(void(0)))) {
      s = image.src;
      image.out = new Image();
      image.out.src = s;
      image.over = new Image();
      if (imageName.lastIndexOf('/') >= 0 || imageName.lastIndexOf('\\') >=0) {
         s = imageName;
      } else {
         i = s.lastIndexOf('/');
         if (i<0) i = s.lastIndexOf('\\');
         if (i<0) { s = imageName; }
         else     { s = s.substring(0,i+1) + imageName; }
      }
      image.over.src = s;
      loaded[image.name] = image;
   }
}

function F_roll(imageName,over) {
   if (document.images) {
      if (over) { imageObject = "over"; }
      else      { imageObject = "out"; }
   image = loaded[imageName];
   if (image) {
       ref = eval("image."+imageObject);
       if (ref) image.src = eval("image."+imageObject+".src");
   }
   if (window.event)
      window.event.cancelBubble = 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.0
  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 && document.getElementById) x=document.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 IsNumeric(ch){

	if (ch=="0"||ch=="1"||ch=="2"||ch=="3"||ch=="4"||ch=="5"||ch=="6"||ch=="7"||ch=="8"||ch=="9")
		return 1;
	else
		return 0;
}



function IsNumeric1(ch){

	if (ch=="0"||ch=="1"||ch=="2"||ch=="3"||ch=="4"||ch=="5"||ch=="6"||ch=="7"||ch=="8"||ch=="9"||ch=="."||ch==",")
		return 1;
	else
		return 0;
}

function IsNumber(str){
	var i, ch;
	
	for (i=0; i<str.length; i++){
	
		ch = str.substring(i,i+1);
		if (!IsNumeric(ch)){
			return 0;
		}	
	}
	return 1;
}

function IsFloat(str){
	var i, ch;
	
	for (i=0; i<str.length; i++){
	
		ch = str.substring(i,i+1);
		if (!IsNumeric1(ch)){
			return 0;
		}	
	}
	return 1;
}

function checkEmail(str)
{
	
	
	if (str.indexOf("@")==-1 || str.charAt(0)=="@" || str.indexOf(".")==-1 || str.charAt(0)=="." || str.charAt(str.indexOf("@")+1)=="." )
		return 0;
	else
		return 1;		
}

function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];

	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}

	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.");
	    return false;
	}

	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {

		alert("The address must end in a three-letter domain, or two letter country.");
		return false;
	}

	if (len<2) {
		var errStr="This address is missing a hostname!";
		alert(errStr);
		return false;
	}

	return true;
}

function popup(url, ext_url, w, h, scrollable){
	var popup, left, top, setting;
	left=screen.width?(screen.width-w)/2:0;
	top=screen.width?(screen.height-h)/2:0;
	
	setting="width=" + w + ",height=" + h + ", scrollbars=" + scrollable + ", dependent=yes, " + "top=" + top + ",left=" + left + "'";
	popup = window.open("","test",setting);
	popup.location.href=url + ext_url;
	if (popup.opener == null) { 
   		popup.opener = self; 
	}	
}
function popup_resize( url, w, h)
{
    var left, top;
	left=screen.width?(screen.width-w)/2:0;
	top=screen.width?(screen.height-h)/2:0;
    window.open( url, "popup", "fullscreen=no, toolbar=no, menubar=no, width=" + w + ", height=" + h + ", resizable=yes, top=" + top +  ", left=" + left + ", scrollbars=yes");
}
function itemIsExisted(srcList, value){
	var len, i, tmpValue;
	len=srcList.length;
	
	for(i=0; i<len; i++){
		tmpValue=srcList.options[i].value;
		
		if(tmpValue==value){
			srcList.selectedIndex=i;
			srcList.focus();
			return true;
			break;
		}
	}
	return false;
	srcList.selectedIndex=-1;
}

function Spec_itemIsExisted(srcList, value){
	var len, i, tmpValue;
	var pos,valueID;
	
	len=srcList.length;
	
	for(i=0; i<len; i++){
		tmpValue=srcList.options[i].value;
		pos = tmpValue.indexOf("|");
		valueID = tmpValue.substring(0,pos);
		
		if(valueID == value){
			srcList.selectedIndex=i;
			srcList.focus();
			return i;
			break;
		}
	}
	return -1;
	srcList.selectedIndex=-1;
}

function clearLst(srcLst, remainItem){
//	var i, l;
//	l=srcLst.length;
	//	for(i=l-1; i>=remainItem; i--){
//		srcLst.remove(i);
//	}
	srcLst.options.length=0;
}

function showPanel(textLink,id) {
    // Show the Panel (and hide the rest)
    var spans = document.body.all.tags("SPAN"); 
	var idSpan;
	//alert("spans.length=" + spans.length);
	//alert("textLink=" + textLink);
	//alert("id=" + id);
    for (i=0; i < spans.length; i++) { 
		idSpan = spans(i).className;
	    if (idSpan.indexOf("linktab")>=0) {
			if (spans(i).id==textLink){
				spans(i).className =  "linktabactive";
			}else{
				spans(i).className =  "linktab";
			}
		}
	}	
//=====================	
    var divs = document.body.all.tags("DIV");
    for (i=0; i < divs.length; i++) { 
    if (divs(i).className == 'tabPanel') {
        if (divs(i).id == id)
            divs(i).style.display = 'block';
        else
            divs(i).style.display = 'none';
        }
    }
}

function checkImage(image){
	var subsrc;
	
	subsrc=image.substring(image.lastIndexOf(".")+1, image.length)
	subsrc=subsrc.toLowerCase();

	if ((subsrc != "gif") && (subsrc != "jpg") && (subsrc != "jpeg"))
		return false;
	else
		return true;
}
function checkDocumentFile(filename){
	var subsrc;
	
	subsrc=filename.substring(filename.lastIndexOf(".")+1, filename.length)
	subsrc=subsrc.toLowerCase();

	if ((subsrc != "doc"))
		return false;
	else
		return true;
}

function isValidDate(month,day,year){
	//check day of month
	if((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 10) || (month == 12)){
		if((day < 1) || (day > 31)){
			return false;
		}
	}
	if((month == 4) || (month == 6) || (month == 9) || (month == 11)){
		if((day < 1) || (day > 30)){
			return false;
		}
	} 
	if(month == 2){
		if((year%4 == 0 && year%100 != 0) || (year%400 == 0)){
			if(day < 1 || day > 29 ){
				return false;
			}
		}
		else{
			if(day < 1 || day > 28){
				return false;
			}
		}
	}
	return true;
}

//----------------------------------------------------
//CREATE AN PART OBJECT AND DEFINE ITS PROPERTIES
//----------------------------------------------------
function PartItem(part_id, part_number){
	this.part_id = part_id;
	this.part_number = part_number;
	
	this.getPartID = getPartID;
	this.getPartNumber = getPartNumber;
}

function getPartID(){
	return this.part_id;
}

function getPartNumber(){
	return this.part_number;
}

//----------------------------------------------------
//CREATE AN CATALOG OBJECT AND DEFINE ITS PROPERTIES
//----------------------------------------------------
function CatalogItem(catalog_id, catalog_qty){
	this.catalog_id = catalog_id;
	this.catalog_qty = catalog_qty;
	
	this.getCatalogID = getCatalogID;
	this.getCatalogQty = getCatalogQty;
}

function getCatalogID(){
	return this.catalog_id;
}

function getCatalogQty(){
	return this.catalog_qty;
}

//----------------------------------------------------
//CREATE AN LOOKUP OBJECT AND DEFINE ITS PROPERTIES
//----------------------------------------------------
function LookupItem(country_value, lookup_value){
	this.country_value = country_value;
	this.lookup_value = lookup_value;
	
	this.getCountryValue = getCountryValue;
	this.getLookupValue = getLookupValue;
}

function getCountryValue(){
	return this.country_value;
}

function getLookupValue(){
	return this.lookup_value;
}




//------------------ ARR OBJECT ----------------------------------
function Items(ID, SortPos){
	this.ID = ID;
	this.SortPos = SortPos;
	
	this.getID = getID;
	this.getSortPos = getSortPos;
	
	this.setID = setID;
	this.setSortPos = setSortPos;
}

function getID(){
	return this.ID;
}

function getSortPos(){
	return this.SortPos;
}

function setID(ID){
	this.ID = ID;
}

function setSortPos(SortPos){
	this.SortPos = SortPos;
}

//-----------TRIM (String)----------------
 String.prototype.trim = function() {
            a = this.replace(/^\s+/, '');
            return a.replace(/\s+$/, '');
        };