// Set a cookie:



function setCookie(name, value, expires, path, domain, secure) {



	var curCookie = name + "=" + escape(value) +



	((expires) ? "; expires=" + expires.toGMTString() : "") +



	((path) ? "; path=" + path : "") +



	((domain) ? "; domain=" + domain : "") +



	((secure) ? "; secure" : "");



	document.cookie = curCookie;



}



// Retrieve a cookie:



function getCookie(name) {



	var dc = document.cookie;



	var prefix = name + "=";



	var begin = dc.indexOf("; " + prefix);



	if (begin == -1) {



		begin = dc.indexOf(prefix);



		if (begin != 0) return null;



	} else



		begin += 2;



	var end = document.cookie.indexOf(";", begin);



	if (end == -1)



		end = dc.length;



	return unescape(dc.substring(begin + prefix.length, end));



}





/*  

	This code came from StoreSecured file "script.js" 



	Not really sure how much I need.



*/



function checkBrowser(){

	this.ver=navigator.appVersion

	this.dom=document.getElementById?1:0

	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;

	this.ie4=(document.all && !this.dom)?1:0;

	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;

	this.ns4=(document.layers && !this.dom)?1:0;

	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)

	return this

}



//With nested layers for netscape, this function hides the layer if it's visible and visa versa

function showHideAuto(div,nest){

	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 

	if(obj.visibility=='visible' || obj.visibility=='show' || obj.visibility=='block') obj.visibility='hidden'

	else obj.visibility='visible'

}

function showHideForm(div,field,nest){

  if (document.forms[0].elements(field).checked)

  {

  	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;

	  obj.display='block'

  }

  	else

  {

  	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 

	  obj.display='none'

  }

}



//Shows the div

function show(div,nest){

	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;

	obj.visibility='visible'

}

//Hides the div

function hide(div,nest){

	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 

	obj.visibility='hidden'

}

/*

  -------------------------------------------------------------------------

	                    JavaScript Form Validator 

                                Version 2.0.2

	Copyright 2003 JavaScript-coder.com. All rights reserved.

	You use this script in your Web pages, provided these opening credit

    lines are kept intact.

	The Form validation script is distributed free from JavaScript-Coder.com



	You may please add a link to JavaScript-Coder.com, 

	making it easy for others to find this script.

	Checkout the Give a link and Get a link page:

	http://www.javascript-coder.com/links/how-to-link.php



    You may not reprint or redistribute this code without permission from 

    JavaScript-Coder.com.

	

	JavaScript Coder

	It precisely codes what you imagine!

	Grab your copy here:

		http://www.javascript-coder.com/

    -------------------------------------------------------------------------  

*/

function Validator(frmname)

{

  this.formobj=document.forms[frmname];

	if(!this.formobj)

	{

	  //alert("BUG: couldnot get Form object "+frmname);

		return;

	}

	if(this.formobj.onsubmit)

	{

	 this.formobj.old_onsubmit = this.formobj.onsubmit;

	 this.formobj.onsubmit=null;

	}

	else

	{

	 this.formobj.old_onsubmit = null;

	}

	this.formobj.onsubmit=form_submit_handler;

	this.addValidation = add_validation;

	this.setAddnlValidationFunction=set_addnl_vfunction;

	this.clearAllValidations = clear_all_validations;

}

function set_addnl_vfunction(functionname)

{

  this.formobj.addnlvalidation = functionname;

}

function clear_all_validations()

{

	for(var itr=0;itr < this.formobj.elements.length;itr++)

	{

		this.formobj.elements[itr].validationset = null;

	}

}

function form_submit_handler()

{

	for(var itr=0;itr < this.elements.length;itr++)

	{

		if(this.elements[itr].validationset &&

	   !this.elements[itr].validationset.validate())

		{

		  return false;

		}

	}

	if(this.addnlvalidation)

	{

	  str =" var ret = "+this.addnlvalidation+"()";

	  eval(str);

    if(!ret) return ret;

	}

	if (submitForm()) {

     return true;

  }

  else

  {

     return false;

  }



}



function add_validation(itemname,descriptor,errstr)

{

  if(!this.formobj)

	{

	  //alert("BUG: the form object is not set properly");

		return;

	}//if

	var itemobj = this.formobj[itemname];

  if(!itemobj)

	{

	  //alert("BUG: Couldnot get the input object named: "+itemname);

		return;

	}

	if(!itemobj.validationset)

	{

	  itemobj.validationset = new ValidationSet(itemobj);

	}

  itemobj.validationset.add(descriptor,errstr);

}

function ValidationDesc(inputitem,desc,error)

{

  this.desc=desc;

	this.error=error;

	this.itemobj = inputitem;

	this.validate=vdesc_validate;

}

function vdesc_validate()

{

 if(!V2validateData(this.desc,this.itemobj,this.error))

 {

    this.itemobj.focus();

		return false;

 }

 return true;

}

function ValidationSet(inputitem)

{

    this.vSet=new Array();

	this.add= add_validationdesc;

	this.validate= vset_validate;

	this.itemobj = inputitem;

}

function add_validationdesc(desc,error)

{

  this.vSet[this.vSet.length]= 

	  new ValidationDesc(this.itemobj,desc,error);

}

function vset_validate()

{

   for(var itr=0;itr<this.vSet.length;itr++)

	 {

	   if(!this.vSet[itr].validate())

		 {

		   return false;

		 }

	 }

	 return true;

}

function validateEmailv2(email)

{

// a very simple email validation checking. 

// you can add more complex email checking if it helps 

    if(email.length <= 0)

	{

	  return true;

	}

    var splitted = email.match("^(.+)@(.+)$");

    if(splitted == null) return false;

    if(splitted[1] != null )

    {

      var regexp_user=/^\"?[\w-_\.]*\"?$/;

      if(splitted[1].match(regexp_user) == null) return false;

    }

    if(splitted[2] != null)

    {

      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;

      if(splitted[2].match(regexp_domain) == null) 

      {

	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;

	    if(splitted[2].match(regexp_ip) == null) return false;

      }// if

      return true;

    }

return false;

}

function V2validateData(strValidateStr,objValue,strError) 

{ 

    var epos = strValidateStr.search("="); 

    var  command  = ""; 

    var  cmdvalue = ""; 

    if(epos >= 0) 

    { 

     command  = strValidateStr.substring(0,epos); 

     cmdvalue = strValidateStr.substr(epos+1); 

    } 

    else 

    { 

     command = strValidateStr; 

    } 

    switch(command) 

    { 

        case "req": 

        case "required": 

         { 

           if(eval(objValue.value.length) == 0) 

           { 

              if(!strError || strError.length ==0) 

              { 

                strError = objValue.name + " : Required Field"; 

              }//if 

              alert(strError);

              objValue.focus

              return false; 

           }//if 

           break;             

         }//case required 

        case "maxlength": 

        case "maxlen": 

          { 

             if(eval(objValue.value.length) >  eval(cmdvalue)) 

             { 

               if(!strError || strError.length ==0) 

               { 

                 strError = objValue.name + " : "+cmdvalue+" characters maximum "; 

               }//if 

               alert(strError + "\n[Current length = " + objValue.value.length + " ]");

               objValue.focus

               return false; 

             }//if 

             break; 

          }//case maxlen 

        case "minlength": 

        case "minlen": 

           { 

             if(eval(objValue.value.length) <  eval(cmdvalue)) 

             { 

               if(!strError || strError.length ==0) 

               { 

                 strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 

               }//if               

               alert(strError + "\n[Current length = " + objValue.value.length + " ]");

               objValue.focus

               return false;                 

             }//if 

             break; 

            }//case minlen 

        case "alnum": 

        case "alphanumeric": 

           { 

              var charpos = objValue.value.search("[^A-Za-z0-9]"); 

              if(objValue.value.length > 0 &&  charpos >= 0)

              { 

               if(!strError || strError.length ==0) 

                { 

                  strError = objValue.name+": Only alpha-numeric characters allowed "; 

                }//if 

                alert(strError + "\n [Error character position " + eval(charpos+1)+"]");

                objValue.focus

                return false; 

              }//if 

              break; 

           }//case alphanumeric 

        case "num": 

        case "numeric": 

           { 

              var charpos = objValue.value.search("[^0-9]"); 

              if(objValue.value.length > 0 &&  charpos >= 0) 

              { 

                if(!strError || strError.length ==0) 

                { 

                  strError = objValue.name+": Only digits allowed "; 

                }//if               

                alert(strError + "\n [Error character position " + eval(charpos+1)+"]");

                objValue.focus

                return false; 

              }//if 

              break;               

           }//numeric 

        case "alphabetic": 

        case "alpha": 

           { 

              var charpos = objValue.value.search("[^A-Za-z]"); 

              if(objValue.value.length > 0 &&  charpos >= 0) 

              { 

                  if(!strError || strError.length ==0)

                { 

                  strError = objValue.name+": Only alphabetic characters allowed "; 

                }//if                             

                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 

                objValue.focus

                return false; 

              }//if 

              break; 

           }//alpha



		case "alnumhyphen":

			{

              var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); 

              if(objValue.value.length > 0 &&  charpos >= 0) 

              { 

                  if(!strError || strError.length ==0) 

                { 

                  strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"; 

                }//if                             

                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 

                objValue.focus

                return false; 

              }//if 			

			break;

			}

        case "email": 

          { 

               if(!validateEmailv2(objValue.value)) 

               { 

                 if(!strError || strError.length ==0) 

                 { 

                    strError = objValue.name+": Enter a valid Email address "; 

                 }//if                                               

                 alert(strError); 

                 objValue.focus

                 return false; 

               }//if 

           break; 

          }//case email 

        case "date":

          { 

               if(!isValidDate(objValue.value))

               { 

                 if(!strError || strError.length ==0) 

                 { 

                    strError = objValue.name+": Enter a valid date";

                 }//if                                               

                 alert(strError); 

                 objValue.focus

                 return false; 

               }//if 

           break; 

          }//case email

        case "lt": 

        case "lessthan": 

         { 

            if(isNaN(objValue.value)) 

            { 

              alert(objValue.name+": Should be a number "); 

              return false; 

            }//if 

            if(eval(objValue.value) >=  eval(cmdvalue))

            { 

              if(!strError || strError.length ==0) 

              { 

                strError = objValue.name + " : value should be less than "+ cmdvalue; 

              }//if               

              alert(strError);

              objValue.focus

              return false;                 

             }//if             

            break; 

         }//case lessthan 

        case "gt": 

        case "greaterthan": 

         { 

            if(isNaN(objValue.value)) 

            { 

              alert(objValue.name+": Should be a number "); 

              return false; 

            }//if 

             if(eval(objValue.value) <=  eval(cmdvalue)) 

             { 

               if(!strError || strError.length ==0) 

               { 

                 strError = objValue.name + " : value should be greater than "+ cmdvalue; 

               }//if               

               alert(strError); 

               objValue.focus

               return false;                 

             }//if             

            break; 

         }//case greaterthan 

        case "regexp": 

         { 

		 	if(objValue.value.length > 0)

			{

	            if(!objValue.value.match(cmdvalue)) 

	            { 

	              if(!strError || strError.length ==0) 

	              { 

	                strError = objValue.name+": Invalid characters found "; 

	              }//if                                                               

	              alert(strError); 

	              objValue.focus

	              return false;                   

	            }//if 

			}

           break; 

         }//case regexp 

        case "dontselect": 

         { 

            if(objValue.selectedIndex == null) 

            { 

              //alert("BUG: dontselect command for non-select Item"); 

              return false; 

            } 

            if(objValue.selectedIndex == eval(cmdvalue)) 

            { 

             if(!strError || strError.length ==0) 

              { 

              strError = objValue.name+": Please Select one option "; 

              }//if                                                               

              alert(strError);

              objValue.focus

              return false;                                   

             } 

             break; 

         }//case dontselect 

    }//switch 

    return true; 

}

/*

	Copyright 2003 JavaScript-coder.com. All rights reserved.

*/





function Left(str, n) {

        if (n <= 0)

            return "";

        else if (n > String(str).length)

            return str;

        else

            return String(str).substring(0, n);

    }







    function RangeValidator(obj, StartRange, EndRange) 

	{        

        if (parseFloat(obj.value) >= parseFloat(StartRange) && parseFloat(obj.value) <= parseFloat(EndRange)) 

	{

            return true;

        }

        else 

	{

            obj.value = Left(obj.value, String(EndRange).length);

            return false;

        }

	}



function goodchars(e, goods)

{

  var key, keychar;

  key = getkey(e);

  if (key == null) return true;

  // get character

  keychar = String.fromCharCode(key);

  keychar = keychar.toLowerCase();

  goods = goods.toLowerCase();

  // check goodkeys

  if (goods.indexOf(keychar) != -1)
  return true;

  // control keys

  if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )

  return true;

  // else return false

  return false;

}

function getkey(e)

{

  if (window.event)

  return window.event.keyCode;

  else if (e)

  return e.which;

  else

  return null;

}

function textCounter(field, countfield, maxlimit) {

if (field.value.length > maxlimit) // if too long...trim it!

field.value = field.value.substring(0, maxlimit);

// otherwise, update 'characters left' counter

else 

countfield.value = maxlimit - field.value.length;

}



function isValidDate(dateStr) {

// Checks for the following valid date formats:

// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

// Also separates date into month, day, and year variables



var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;



// To require a 4 digit year entry, use this line instead:

// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;



var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {

return false;

}

month = matchArray[1]; // parse date into variables

day = matchArray[3];

year = matchArray[4];

if (month < 1 || month > 12) { // check month range

return false;

}

if (day < 1 || day > 31) {

return false;

}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {

return false

}

if (month == 2) { // check for february 29th

var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));

if (day>29 || (day==29 && !isleap)) {

return false;

   }

}

return true;  // date is valid

}





