<!--
// ----------------------------------------
// @ remove space
// ----------------------------------------	
function trim(Str){
 return Str.replace (/ +/g," ").replace (/^ +/,"").replace (/ +$/,"");   
}

// ----------------------------------------
// @ new window open
// ----------------------------------------	
function Openwin(loc,wid,he,scr,res){
	LeftPosition = (screen.width) ? (screen.width-wid)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-he)/2 : 0;
	window.open(loc,'newwin', 'top='+TopPosition + ',left='+LeftPosition + ',width='+wid + ',height='+he + ',scrollbars='+scr + ',resizable='+res+ ',toolbar=no').focus();
}

// ----------------------------------------
// @ check all checkbox
// ----------------------------------------	
function selAll(){				
	var field=document.listform.dataid;	
	
	if (field != undefined) {
		if (field.length == undefined) {
			field.checked=true;	
		}	else {				
			for (j=0; j<field.length; j++)
				field[j].checked=true;									
		}	
	}
	
	cf = 'true';		
}	

// ----------------------------------------
// @ release check all checkbox
// ----------------------------------------				
function deSelAll() {
	var field=document.listform.dataid;
	
	if (field != undefined) {
		if (field.length == undefined) {
			field.checked=false;	
		}
		else {
		 	for (j=0; j<field.length; j++)
				field[j].checked=false;				
		}				
	}
	  	
	cf = 'false';		  	
}

// ----------------------------------------
// @ return checked
// ----------------------------------------				
function checkboxChk(field){
				
	var ischeck = false;

	if (field != undefined) {
		if (field.length == undefined) {
			if (field.checked) ischeck=true;	
		}else {				
			for (j=0; j<field.length; j++) {
				if (field[j].checked) {
					ischeck=true;										
					break;
				}
			}
		}	
	}
	return ischeck;
}

// ----------------------------------------
// @ return div object
// ----------------------------------------				
function getObject(objectID) {
	if (document.getElementById && document.getElementById(objectID)) {
		return document.getElementById(objectID)
	} else if (document.all && document.all(objectID)) {		// IE4
		return document.all(objectID);
	} else if (document.layers && document.layers[objectID]) {		//NS4
		return document.layers[objectID];
	} else {
		return false;
	}
}

// ----------------------------------------
// @ change search tab
// ----------------------------------------				
function getSearchQS() {
	var frm = document.supplier_search;	
	var qs = "key.stk";	
	
	var kw = trim (frm.sk.value);
	if (kw != "") {
		kw = kw.replace(/\./g, "!");
		kw = escape (kw);	
		qs += ".sk_" + kw;
	}	
	
	if (frm.ar) {
		if (frm.ar.value == area_msg) return qs;
		var ar = trim (frm.ar.value);
		if (ar != "") {		
			ar = ar.replace(/\./g, "!");
			ar = escape (ar);
			qs += ".ar" + ar;
		}
	}
	return qs;
}


// ----------------------------------------
// @ cookie setting
// ----------------------------------------				
function SetCookie (name, value) {	
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");	
}

// ----------------------------------------
// @ get cookie
// ----------------------------------------				
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";",offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while ( i< clen ) {
		var j = i + alen;
		if (document.cookie.substring(i,j) == arg)
		return getCookieVal(j);
		i = document.cookie.indexOf(" ",i) + 1;
		if (i==0) break;
	}
	return null;
}
function deleteCookie(name) {	
	var argv = deleteCookie.arguments;  
	var argc = deleteCookie.arguments.length;  

	var path = (argc > 1) ? argv[1] : null;  
	
	document.cookie = name + "=; expires=" + (new Date()).toGMTString() + 			
	((path == null) ? "" : ("; path=" + path));
}

// ----------------------------------------
// @ call web page
// ----------------------------------------			
function loadHTMLDoc(url)
{
  //alert(url);
  req = false;
  if(window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
        } catch(e) {
      req = false;
        }
  }
  else if(window.ActiveXObject)
  {
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
    	try {
      	req = new ActiveXObject("Microsoft.XMLHTTP");
    	} catch(e) {
      	req = false;
    	}
  	}
  }

  if(req) {    
    req.open("GET", url, true);
    req.setRequestHeader('Cache-Control','0');
    //alert(req.getRequestHeader('Cache-Control'));
    req.send();
  }
}


// ----------------------------------------
// @ entity checking
// ----------------------------------------		
var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
 
function isValid(parm,val) {
  if (parm == "") return false;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}
 
function isNum(parm) {return isValid(parm,numb);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);}

// -------------------------------------------------------
// @ change country(usa or canada) if state is selected
// --------------------------------------------------------		
function changecountry(obj){
	var theValue=obj.options[obj.selectedIndex].value.substr(0,3);
	if(theValue != ""){
		if(theValue==605) {
			document.regform.fnation.options[0].selected=true;
			document.regform.fother.disabled = true;
		} else {
			document.regform.fnation.options[1].selected=true;
			document.regform.fother.disabled = false;
		}
	}
}
function changestate(obj){
	var theValue=obj.options[obj.selectedIndex].value;
	if(theValue == "60500000"){		
		document.regform.fregion.options[0].selected=true;
		document.regform.fother.disabled = true;
	} else {
		document.regform.fregion.options[document.regform.fregion.options.length-1].selected=true;
		document.regform.fother.disabled = false;
	}
}

// -------------------------------------------------------
// @ in subscription step
// --------------------------------------------------------		
function chkagree() {
	if (document.regform.rcvmail.checked) {
		return true;
	} else {			
		msg = "Agreement";
		msg += "\n___________________________________________\n\n";
		msg += "I have reviewed and agree to the Terms of Use\n";
		msg += "and Privacy Policy of Openfos.";
		if (confirm (msg)) 
			document.regform.rcvmail.checked = true;			
		return false;
	}
}

// -------------------------------------------------------
// @ confirm to delete catalog
// --------------------------------------------------------		
function removecatalog(seq) {
	if (confirm("Are you sure to delete?")) {
		f = document.regform;
		f.act.value = 'remove';
		f.rid.value = seq;
		f.submit();
	}	
}

// -------------------------------------------------------
// @ show more / show less
// --------------------------------------------------------		
function showmore(divid) {	
	if (!document.getElementById) return false;
	var div = document.getElementById(divid); 
	var div_more = document.getElementById(divid+"-more"); 	
	if (div) {
		div.style.display = "none";
		div_more.style.display = "block";
	}		
}
function showmore_state(divid) {
	if (!document.getElementById) return false;
	var div = document.getElementById(divid); 	
	div.style.height = "100%";
	div.style.overflow = "auto";
	// change show more
	var div_more = document.getElementById(divid+"-more");	
	if (div_more && div_more.childNodes.length > 0) {
		div_more.className = "flt-show-less";
		div_more.childNodes[0].setAttribute("href","javascript:showless_state('" + divid + "')")				
		div_more.childNodes[0].childNodes[0].nodeValue = "show less";	
	}
}
function showless_state(divid) {	
	if (!document.getElementById) return false;
	var div = document.getElementById(divid); 		
	div.style.height = "10em";
	div.style.overflow = "hidden";
	// change show less
	var div_more = document.getElementById(divid+"-more");
	if (div_more && div_more.childNodes.length > 0) {
		div_more.className = "flt-show-more";
		div_more.childNodes[0].setAttribute("href","javascript:showmore_state('" + divid + "')")				
		div_more.childNodes[0].childNodes[0].nodeValue = "show more";		
	}
}
//-->	