var NS = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) > 3)) ? true : false;

function JSForm(form) {
  this.name = "Get Set Class";
  this.form = form;  
    if (form){
       this.form =  form;
    } else {
       this.form =  0;
    }
}

new JSForm(0);
var iopopup = new Object();
window.onunload = doClose;

function doClose() {  
  if(iopopup.win && !iopopup.win.closed) { iopopup.win.close(); }
}

/* Start of Validation functions */

var bad_Chars = "/$`~%^*()+=\\|[]{}<>\"";

function isValidChar(testStr) {
 var t, n
 n = testStr.toString();
  for (var i = 0; i < n.length; i++) {
    t= n.charAt(i)
	if(bad_Chars.indexOf(t) > -1) { return false; }
  }
 return true
  }

function isValidChar_nospc(testStr) {
 var x,t, n
 n = testStr;
 x = bad_Chars + " ";
  for (var i = 0; i <= n.length-1; i++) {
    t= n.charAt(i)
    if(x.indexOf(t) > -1) { return false; }
  }
 return true
}

function isBlank(testStr) {
 var n = testStr;
 n = n.toString();
  if (n.length == 0)
    return true
  for (var i = 0; i <= n.length-1; i++) {
    if (n.charAt(i) != " ")
      return false
  }
  return true
}

function testOneNum(str) {
 var temp = str.toString()
 var x
  for (var i = 0; i < temp.length; i++) {
    x = temp.charAt(i)
    if (x < "0" || x > "9") {
      return false
    }
  }
  return true
}

function isANumeric(num,posOnly) {
 var t = num.toString(); var cnt = 0;
 if (t.lastIndexOf(".") != -1) {
   var tp = t.split(".")
   if (!posOnly)
     cnt = (tp[0].charAt(0)=="-" && tp[0].length > 1) ? 1 : 0;
   else
     cnt = 0	 
   if(!testOneNum(tp[0].substring(cnt,tp[0].length))) {
	 return false
   }  
   if(!testOneNum(tp[1]))
    return false
	
 } else {  
   if (!posOnly)
     cnt = (t.charAt(0)=="-" && t.length > 1) ? 1 : 0;
   else
     cnt = 0
   if(!testOneNum(t.substring(cnt,t.length))) {
	 return false
   }
 }
return true
}

function isSpace(index) {
  var ch = this.charAt(index);
  return (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r');
}



function trimRightSpaces() {
  var input_string = this;
  if (input_string.length == 0)
    return input_string;
  var output_string = new String();
  var idx = input_string.length - 1;
  while (input_string.isSpace(idx) && idx > 0) idx--;
  output_string = input_string.substring(0, idx + 1);
  return output_string;
}


function trimLeftSpaces() {
  var output_string = this;
  var len = output_string.length;
  if (len == 0)
    return output_string;
  var index = 0;
  while(output_string.isSpace(index) && index < len)
  {
    index++;
  }
  output_string = output_string.substring(index);
  return output_string;
}

function removeConsecutiveSpaces() {
  var input_string = this;
  var idx = 0;
  var output_string = new String();
  while (idx < input_string.length) {
    if (input_string.isSpace(idx)) {
      if (output_string.length > 0 &&
          !output_string.isSpace(output_string.length - 1))
        output_string += ' ';
    } else {
      output_string += input_string.charAt(idx);
    }
    idx++;
  }
 return output_string;
}

function trimAllSpaces(testStr) {
  var message = new String(testStr);
    message = message.trimLeft();
    message = message.trimRight();
    message = message.trimConsecutiveSpaces();
    return message;
}

function getFebDays(Year) {
Year = Year.toString();
var t = new Date();
var cur_yr = t.getFullYear();
cur_yr = cur_yr.toString();
cur_yr = cur_yr.substring(0,2);
var Yr;
if(Year.length==2) {
  Yr = eval(cur_yr + Year)
} else {
  Yr = parseInt(Year);
}
  if ((Yr % 4 == 0 && Yr % 100 != 0) || Yr % 400 == 0) {
    return 29
  } else {
    return 28
  }
}


String.prototype.isSpace = isSpace;
String.prototype.trimRight = trimRightSpaces;
String.prototype.trimLeft = trimLeftSpaces;
String.prototype.trimSpaces = trimAllSpaces;
String.prototype.isValidChar = isValidChar;
String.prototype.isValidChar_nospc = isValidChar_nospc;
String.prototype.trimConsecutiveSpaces = removeConsecutiveSpaces;

function isValidDate(str) {
  if(str == null) { return false; }
  if(isBlank(str)) { return false; }

  var t = str.toString();
  if(t.indexOf("/")==-1) { return false; } 
  
  var t2 = t.split("/");
  if(t2.length!=3) { return false; }

  var b = t2[0]; // mo
  var d = t2[1]; // day
  var f = t2[2]; // yr
  
  if (isBlank(b)|| isBlank(d) || isBlank(f)) { return false; }  
  if (isNaN(b) || isNaN(d) || isNaN(f) || f.length != 2) { return false; }

  // checking for whole numbers for mm dd and yy
  if (Math.floor(b) != b || Math.floor(d) != d || Math.floor(f) != f){ return false;}
  //basic error checking
  if (b<1 || b>12 || d<1 || d>31 || f<0 || f>9999 || f.length==1 || f.length==3) { return false; }

	// months with 30 days
	if (b==4 || b==6 || b==9 || b==11) {
		if (d==31)  { return false; }
	}

	// february, leap year
	if (b==2) {
		// feb
	  if (d>29) { return false; }
	  if (d==29 && ((f/4)!=parseInt(f/4)))  { return false; }
	}
  return true
}

function set(f_name,f_value) {
 var formlen = new Object(); var e_type = ""; var select_len;
  formlen.ee = (this.form.elements[f_name]) ? true : false;
  f_name.toString(); f_value.toString();
   if (formlen.ee==true) {
     var t = this.form.elements[f_name];  
     var var_len = (t.length) ? true : false;
	 if(var_len==true) {
	   if(t.type!="select-one" && t.type!="select-multiple" && t.type!="text" && t.type!="hidden" && t.type!="textarea" && t.type!="file" && t.type!="password") { 
	     e_type = (t.length > 1)? eval("this.form."+f_name+"[0].type") : t.type;
	   } else {
	     e_type = t.type;
	   }
	 } else {
	   e_type = t.type;
	 }	 
   if(e_type=="checkbox") { // ckbox ck by true false
     t.checked = (f_value=="true") ? true : false;
   } else if(e_type=="select-one" || e_type=="select-multiple") {
     select_len = t.length;
     for(var j=0 ; j<select_len; j++){
        if(t.options[j].value.toLowerCase()==f_value.toLowerCase()) { t.options[j].selected = true; }
     } 
     return; 
   } else if(e_type=="radio") { // radio ck by value
      if(t.length==1) { t.checked=(eval("this.form."+f_name+".value"==f_value)) ? true : false; return }
	  select_len = t.length; var x2;
      for(var j=0 ; j<select_len; j++) {
	    x2 = eval("this.form."+f_name+"["+j+"]");
	    if(x2.value==f_value) {
		  x2.checked = true; break;
        }
      }
   } else {
     t.value = f_value; 
   }
 } 
return;  
}

function get(name) {
  var formlen = new Object(); var type = ""; var value=""; 
  formlen.ee = (this.form.elements[name]) ? true : false;
  var var_len;   
   if (formlen.ee==true) {
      var t = this.form.elements[name];	  
	    var_len = (t.length) ? true : false;
	   if(var_len==true) {
	     if(t.type!="select-one" && t.type!="select-multiple" && t.type!="text" && t.type!="hidden" && t.type!="textarea" && t.type!="file" && t.type!="password") {
	       type = (t.length > 1)? eval("this.form."+name+"[0].type") : t.type;
	     } else {
	       type = t.type;
	     }
	   } else {
	      type = t.type;
	   }		
	 if(type=="radio") { 
	   if(!var_len) { value = (t.checked) ? eval("this.form."+name+".value") : ""; 
		 return value;
	   }
	   for(var j=0; j<t.length; j++) {
		 if (eval("this.form."+name+"["+j+"].checked")) { 
		   value = eval("this.form."+name+"["+j+"].value");
	       break;
		 }
       }
	 } else if(type=="checkbox") {
	   if(var_len != true) { 
	     if(t.checked==true) { 
		   value = eval("this.form."+name+".value");
		 }
		return value;
	   } else {  
	     if(t.length==1) { 
		   value = (t.checked==true)? t.value : "";
           return value;
		 }
	     for(var j=0; j<t.length; j++) {
		   if (eval("this.form."+name+"["+j+"].checked")) { 
		     if (value.length > 0) { value += ","; }
		     value += eval("this.form."+name+"["+j+"].value");
	       }
         }  // for loop
	     return value;
		}
	 } else if(type=="select-multiple") {
	    selectlen = t.length;
	    for(var j=0; j<selectlen; j++) {
		   if (t.options[j].selected) { 
		    if (value.length > 0) { value += ","; }
               value += t.options[j].value;
           } 
		 } 
	 } else if(type=="select-one") {	
		value = t.options[t.selectedIndex].value; return value;
	 } else {
        value = t.value;
	 }
  }  
  
return value;
}

function getType(fname) {
  var formlen = new Object(); var type = ""
  formlen.ee = (this.form.elements[fname]) ? true : false;
  if (formlen.ee==true) {
    var t = this.form.elements[fname];	
    var var_len = (t.length) ? true : false;
    if(var_len==true) {
      if(t.type!="select-one" && t.type!="select-multiple" && t.type!="text" && t.type!="hidden" && t.type!="textarea" && t.type!="file" && t.type!="password") {
	     type = (t.length > 1)? eval("this.form."+fname+"[0].type") : t.type;
	  } else {
	     type = t.type;
	  }
    } else {
	   type = t.type;
    }		
  }  
  return type;	
}

JSForm.prototype.get = get;
JSForm.prototype.set = set;
JSForm.prototype.getType = getType;




    function checkForm() {
    // validate the email address for: @ sign, .com ...
	// validate the blanks
	// call create popup function and  
	
	  var v = document.mainForm
      var f = new JSForm(v)
      var tp = f.get("Email").toString()  // grab its value
   
      if (tp.length > 0 && tp.value != "Email Address" && (tp.lastIndexOf("@") == -1 || tp.lastIndexOf(".")==-1 || (tp.lastIndexOf(".") <= (tp.lastIndexOf("@")+1)))) {
	     alert("Please enter a valid Email address")
		 v.Email.focus();
	  } else {	 		
			getAgreement();
 	  }
  }

