// JavaScript Document
//Release 2005-06-21
//validat the form field require & format.
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+args[i+1]+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+args[i+1]+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+args[i+1]+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+args[i+1]+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

//validation the same password & comform password entry before submit after MM_validateForm
function ConfirmPassword(form_pass1,form_pass2){
	if(document.MM_returnValue){
	  if(form_pass1.value != form_pass2.value){
		alert('Password enter not the same !');
		return document.MM_returnValue = false
	  }else{
		return document.MM_returnValue =true;
	  }
	}else{
		return document.MM_returnValue;
	}	  
}

//ask to confirm delete
function ConfirmDelete(field,id){
	var msg = "Confirm delete this "+ field + " : "+ id;
	if(confirm(msg)== true) 
		return true;
	else 
		return false;

	return false;
}
//check filetype
//1st arg = filename;
//2nd arg = popup alert or not
//3th arg = empty field popup error or not.
//3th & following extension to check
function CheckFileType() {
  var args 		= CheckFileType.arguments;
  var filename 	= args[0];
  var popupmsg 	= args[1];
  var e_empty = args[2];  
  var oktype 	= false;
  
  if(filename == ''){
  	if(e_empty == 'y'){
	  alert("Please select the image file !");
	  return false;
	}else{
	  return;
	}
  }
  ext = filename.substring(filename.length-4,filename.length);
  ext = ext.toLowerCase();  

 for (i=3; i<(args.length); i++){
 	if(ext == args[i]){
		oktype = true;
		break;
	}
 }

  if(oktype == true) {
      return true; 
  }else{
  	if(popupmsg=='y'){
		var msg = 'You selected an invalid filetype '+ext+' file;\n Please select a following file type!\n'
		 for (i=3; i<(args.length); i++){
		 	msg = msg+args[i]+'\n';
		 }
		 alert(msg);
	}
    return false; }
}