
function isImage(str)
{
	var pos, tail, len;
	len=str.length;

	tail=str.substring(len-3,len);
	if(tail=="jpg" || tail=="gif" || tail=="bmp" || tail=="pcx" || tail=="tif" || tail=="png" || tail=="tga")
		return true;
	else
		return false;
	 
}

function isPDFDoc(doc)
{
	var pos, tail, len;
	len=doc.length;

	tail=doc.substring(len-3,len);

	if(tail=="pdf" || tail=="PDF"){
		return true;
	}else{
		return false;
	}
}

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 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 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){
	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=yes, dependent=yes," + "top=" + top + ",left=" + left + "'";
	popup = window.open("","test",setting);
	popup.location.href=url + ext_url;
	
	if (popup.opener == null) { 
   		popup.opener = self; 
	}
}

//-----------------------------------------------------
//CREATE AN PROD_SYSTEM OBJECT AND DEFINE ITS PROPERTIES
//-----------------------------------------------------
function prodlineItem(prodline_id, cat_id, prodline_name){
	this.prodline_id=prodline_id;
	this.cat_id=cat_id;
	this.prodline_name=prodline_name;
	
	this.getProdLineID=getProdLineID;
	this.getCategoryID=getCategoryID;
	this.getProdLineName=getProdLineName;
}

function getProdLineID(){
	return this.prodline_id;
}

function getCategoryID(){
	return this.cat_id;
}

function getProdLineName(){
	return this.prodline_name;
}

