function TestMandatory(Ctrl){
 var k;
 if (Ctrl.value==""){
  ValidatePrompt (Ctrl,"Please fill all mandatory fields.");
  return (false);}
  for (k=0;k<Ctrl.value.length;k++){
   if (!(Ctrl.value.charAt(k)==' ')) return (true);}
  Ctrl.value='';
  ValidatePrompt(Ctrl,"Please fill all mandatory fields.");
  return (false);}
function TestText(Ctrl){
 var k;
 if (Ctrl.value==""){
    return (false);}
  for (k=0;k<Ctrl.value.length;k++) {
    if (!(Ctrl.value.charAt(k)==' ')) return (true);}
  Ctrl.value = '';
  return (false);}
function DropdownMandatory(Ctrl) {
  if (Ctrl.selectedIndex == 0) {
    ValidatePrompt (Ctrl, "Please fill all mandatory fields.");
    return (false);} 
  else
    return (true);}
function RadioMandatory(Ctrl){
  for (i=0;i<Ctrl.length;i++){
    if (Ctrl[i].checked == true){
      return (true);}}
  alert("Please check a checkbox.");
  return (false);}
function CompareStrings(Ctrla,Ctrlb) {
  if(Ctrla.value!=Ctrlb.value) {
   Ctrlb.value="";
   ValidatePrompt (Ctrlb, "Confirmation is not same as original.");
   return(false);}
  return(true);}
function CompareDate(form,Ctrl,a,b,c,d) {
  var from_date = b + a;
  var to_date = d + c;
  if(parseFloat(from_date)>parseFloat(to_date)){
    ValidatePrompt (Ctrl,"The date order is not correct.");
    return (false);}
  return (true);}
function CompareDate2(form,Ctrl,a,b,c,d,e,f) {
  var from_date = c + b + a;
  var to_date = f + e + d;
  if(parseFloat(from_date)>parseFloat(to_date)){
    ValidatePrompt (Ctrl,"The date order is not correct.");
    return (false);}
  return (true);}
function TestDropdown(Ctrl) {
  if (Ctrl.selectedIndex == 0) {
    return (false);} 
  else
    return (true);}
function ValidatePrompt (Ctrl, PromptStr) {
  alert (PromptStr);
  Ctrl.focus();
  return;}
function IfConfirm(form,msg) {
  agree = confirm(msg);
  if (agree) {
    return (true)}
  return (false)}
function ConfirmElementDelete() {
  agree = confirm('Are you sure you want to delete this element?');
  if (agree) {
    return (true);}
  return (false);}
function IsNumeric(Ctrl){
  var strValidChars = "0123456789.-";
  var strChar;
  var blnResult = true;
  for (i = 0; i<Ctrl.value.length && blnResult == true; i++){
    strChar = Ctrl.value.charAt(i);
    if (strValidChars.indexOf(strChar) == -1){
      blnResult = false;}}
  if (blnResult == false){
    ValidatePrompt (Ctrl,"This value must be numeric.");
    return false;}
  return true;}
function IsInteger(Ctrl,min,max){
  var strValidChars = "0123456789";
  var strChar;
  var blnResult = true;
  for (i = 0; i<Ctrl.value.length && blnResult == true; i++){
    strChar = Ctrl.value.charAt(i);
    if (strValidChars.indexOf(strChar) == -1){
      blnResult = false;}}
  if (blnResult == false){
    ValidatePrompt (Ctrl,"This value must be numeric.");
    return false;}
  if ((Ctrl.value<min)||(Ctrl.value>max)){
    ValidatePrompt (Ctrl,"This value must be between "+min+" and "+max);
    return false;}
  return true;}
function IfConfirmLink(msg) {
  agree = confirm(msg);
  if (agree) {
    return (true)}
  return (false)}
function CheckDate(dd,mm,yyyy) {
 var day=dd.value;
 var month=mm.value;
 var year=yyyy.value;
 var bissextile=0;
 var err=0;
 if ((year%4==0)||(year%100==0)||(year%400==0)) bissextile=1;
 if (month>12) err=1;
 if ((month==2)&&(bissextile==1)&&(day>29)) err=1;
 if ((month==2)&&(bissextile!=1)&&(day>28)) err=1;
 if (((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))&&(day>31)) err=1;
 if (((month==4)||(month==6)||(month==9)||(month==11))&&(day>30)) err=1;
 if (err!=0) {
  ValidatePrompt (dd,"The date format is not correct.");
  return (false);}   
 return true;}
function CheckDate2(Ctrl) {
 var err=0;
 var input=Ctrl.value;
 var validformat=/^\d{2}\/\d{2}\/\d{4}$/;
 if (!validformat.test(input)) err=1;
 if (err==0) {
  var day=input.split("/")[0];
  var month=input.split("/")[1];
  var year=input.split("/")[2];
  var bissextile=0;
  if ((year%4==0)||(year%100==0)||(year%400==0)) bissextile=1;
  if (month>12) err=1;
  if ((month==2)&&(bissextile==1)&&(day>29)) err=1;
  if ((month==2)&&(bissextile!=1)&&(day>28)) err=1;
  if (((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))&&(day>31)) err=1;
  if (((month==4)||(month==6)||(month==9)||(month==11))&&(day>30)) err=1;}
 if (err!=0) {
  ValidatePrompt (Ctrl,"The date format is not correct.");
  Ctrl.value="";
  return (false);}   
 return true;}
function OpenWindow(url,name,features) {
  window.open(url,name,features);}
function CheckAlphaNum(Ctrl,min,max) {
  var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  var ok = "yes";
  var temp;
  if ((Ctrl.value.length<min) || (Ctrl.value.length>max)){
    ok = "no";}
  for (var i=0; i<Ctrl.value.length; i++) {
    temp = "" + Ctrl.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";}
  if (ok == "no") {
    ValidatePrompt (Ctrl,"Please enter between "+min+" and "+max+" alphanumeric characters.\r\rValid characters:\r"+valid);
    return false;}
  return true;}
function TestEmailMsg(Ctrl){
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(Ctrl.value)){
    return (true);}
  ValidatePrompt (Ctrl, "The email address format is not correct.");
  return (false);}
function JumpMenu(selObj,restore){
  eval("parent.location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;}
