var letter=/[^a-zA-Z]/;

function CheckName(name)
{
	var namelen = name.length;	
	var error ="";	
	var count=0;		

	if (namelen==0)
		{
		return false;
		}
	if ( namelen<2) 
		{
		return false;
		}
	if(letter.test(name))
		{
		return false;
		}	

	return true;
}

function closeit() 
{
	setTimeout("self.close()",1);
}


function CheckCheckBox(checkboxnum)
/*The client/user must check at least one checkbox*/	
{
	var error ="";	/*to see if the string have error or not*/   
	var count=0;		/*count the errors*/	
	
	for (var j = 0; j < checkboxnum ; j++) {
            if (document.orderform.ordertype[j].checked == false)
            	{
            	count++;
            	}
        }	
	if(count==checkboxnum)
		{
		return false;
		}

	return true;
}


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 isEmail(email) {
	var r = new RegExp("^[A-Za-z0-9_\\.-]+@([A-Za-z0-9_-]+\\.)+[A-Za-z0-9_-]+$");
	return r.test(email);
}
function isBlank(s){
	var r = new RegExp("^\\s*$");
	return r.test(s);
}
function isDecimal(s,d,signed){
    var r = "^[0-9";
    if(signed) r+="-";
    r += "]+";
    if(d>0) r+="(\\.[0-9]{0,"+d+"})*";
    r += "$";
    r = new RegExp(r);
    return r.test(s);
}

function trim(s){
	var r = new RegExp("^\\s*(.*?)\\s*$");
	r.exec(s);
	return RegExp.$1;
}


function X_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=X_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; oval=MM_findObj(args[i]); msg=args[i+1];
	if (!oval) continue;
	if(!(oval instanceof Array)) llength=1;
	else llength=oval.length;
    for(j=0;j<llength;j++) {
		if (llength==1) val=oval;
		else val=oval(j);
	    if (val) { nm=val.name; if ((val=val.value)!="") {
		  if (test.indexOf('isEmail')!=-1) {
		  	/*
		  	p=val.indexOf('@');
			if (p<1 || p==(val.length-1))
			*/
			if(!isEmail(val)) errors+='- '+(msg==''?nm+' must contain an e-mail address.\n':msg+'\n');
		} else if (test.indexOf('isDate')!=-1) { 
					if (!checkDate(val)) errors+='- '+(msg==''?nm+' must contain a date.(like dd/mm/yyyy")\n':msg+'\n');
			   }
			   else if (test!='R') {
						if (isNaN(val)) errors+='- '+(msg==''?nm+' must contain a number.\n':msg+'\n');
						if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
						min=test.substring(7,p); max=test.substring(p+1);
						if (parseFloat(val)<parseFloat(min) || parseFloat(max)<parseFloat(val)) errors+='- '+(msg==''?nm+' must contain a number between '+min+' and '+max+'.\n':msg+'\n');
		}
		else if(val<0) errors+='- '+(msg==''?nm+' must contain a positive number.\n':msg+'\n');
		} } else if (test.charAt(0) == 'R') errors += '- '+(msg==''?nm+' is required.\n':msg+'\n'); }
	}  
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.X_returnValue = (errors == '');
  return document.X_returnValue;
}


function SelMove(src,des,exce,d1,d2,del,check) { 	
	if (!src) return false;
	var oSrc=MM_findObj(src,d1);
	if (!oSrc) return false;
	if (!des) {
		for (i=0;i<oSrc.options.length;i++) {
			if (oSrc.options(i).selected){
				if (oSrc.options(i).innerText!=exce) {
					oSrc.options.remove(i);
					i--;
				}
			}
		}
	}
	else {
		var oDes=MM_findObj(des,d2);
		if (!oDes) return false;
		for (i=0;i<oSrc.options.length;i++) {
			var oSrcOption =oSrc.options.item(i);
			if (oSrcOption.selected){
				if(check){
					var cr = check(oDes,oSrcOption);
					if(cr==-1){
						continue
					}
					else if(cr==-2){
						return false;
					}
				}
				if(oSrcOption.innerText!=exce) {
					var oOption = document.createElement("OPTION");
					oDes.options.add(oOption);
					oOption.innerText = oSrcOption.innerText;
					oOption.value = oSrcOption.value;
					oSrcOption.selected=false;
					if(del) {oSrc.options.remove(i);i--;}
				}				
			}
		}	
	}
}
function selAll(src){
	if (!src) return false;
	var oSrc=MM_findObj(src);
	if (!oSrc) return false;
	var ops = oSrc.options;
	for(var i =0;i<ops.length;i++){
		ops[i].selected = true;
	}
	return ops.length>0;
}
