/*      Universal Form Checking
	Script made by Dmitry Kuryata, KeeberSoft (c) 2000
*/
var ck_forms = new Array(), ck_findex=0;
var ck_fields = new Array(), ck_ffindex=0;
var m_b1="", m_b2=" is a required field.", m_t="";

function ck_InitForm(newform) {
  ck_forms[ck_findex] = new Array();
  ck_forms[ck_findex][0] = newform;
  ck_forms[ck_findex][1] = 0;
  ck_findex++;
}

function ck_SetMsg(type, msg) {
   switch (type) {
     case 'blank1':
	m_b1 = msg;
	break;
     case 'blank2':
	m_b2 = msg;
	break;
     case 'type':
	m_t = msg;
	break;
     default:
   }
}

function ck_AddField(newfield, ftype, freq, fname) {// ftype - string, freq - 0/1 (n/y), fname - string
  for (i=0;i<ck_findex;i++) {
    if (ck_forms[i][0]==newfield.form) {
      ck_fields[ck_ffindex] = new Array(newfield, ftype, freq, fname);
      ck_forms[i][1]++;
      ck_forms[i][ck_forms[i][1]+1] = ck_ffindex;
      ck_ffindex++;
    }
  }
}

function ck_DebugPrint() {
  document.write("====== forms, fields and attributes =====<br>");
  for (i=0;i<ck_findex;i++) {
   document.write(ck_forms[i][0].name);
   document.write("<br>");
   for (j=0;j<ck_forms[i][1];j++) {
      document.write(ck_fields[ck_forms[i][j+2]][0].name);
      document.write("<br>");
      document.write(ck_fields[ck_forms[i][j+2]][1]+", "+ck_fields[ck_forms[i][j+2]][2]+", "+ck_fields[ck_forms[i][j+2]][3]);
      document.write("<br>");
    }
  }
}

function ck_SubmitForm(sform) {
  for (i=0;i<ck_findex;i++) {
    if (ck_forms[i][0]==sform) {
      for (j=0;j<ck_forms[i][1];j++) {  // check for requirement
	if (ck_fields[ck_forms[i][j+2]][0].value==''&&ck_fields[ck_forms[i][j+2]][2]==1) {
	  alert(m_b1+'"'+ck_fields[ck_forms[i][j+2]][3]+'"'+m_b2);
	  return false;
        }
	// check for type conformity 
	if (ck_fields[ck_forms[i][j+2]][0].value!='') {
	switch (ck_fields[ck_forms[i][j+2]][1]) {
	  case 'date':
	    d = new Date(ck_fields[ck_forms[i][j+2]][0].value);
	    z=d.toString(); //alert(z);
	    if (z=='NaN'){
	      alert('The "'+ck_fields[ck_forms[i][j+2]][3]+'" field may only contain a valid date.');
	      ck_fields[ck_forms[i][j+2]][0].value='';
	      return false;
	    }
	    break;
	  case 'expdate':
	    if (isExpDate(ck_fields[ck_forms[i][j+2]][0].value)!=1) {
	      alert('The "'+ck_fields[ck_forms[i][j+2]][3]+'" field may only contain a valid date (mm/yy).');
	      return false;
	    }
	    break;
	  case 'numeric':
	    if (isNumeric(ck_fields[ck_forms[i][j+2]][0].value)!=1) {
	      alert('The "'+ck_fields[ck_forms[i][j+2]][3]+'" field may only contain numbers.');
	      return false;
	    }
	    break;
	  case 'float':
	    if (isFloat(ck_fields[ck_forms[i][j+2]][0].value)!=1) {
	      alert('The "'+ck_fields[ck_forms[i][j+2]][3]+'" field may only contain numbers.');
	      return false;
	    }
	    break;
	  case 'money':
	    if (isMoney(ck_fields[ck_forms[i][j+2]][0].value)!=1) {
	      alert('The "'+ck_fields[ck_forms[i][j+2]][3]+'" field may only a valid dollar amount.');
	      return false;
	    }
	    break;
	  case 'creditcard':
	    if (isCreditCard(ck_fields[ck_forms[i][j+2]][0].value)!=1) {
	      alert('The "'+ck_fields[ck_forms[i][j+2]][3]+'" field may only contain numbers.');
//alert(ck_fields[ck_forms[i][j+2]][0].value);
	      return false;
	    }
	    break;
	  case 'email':
	    if (isEmail(ck_fields[ck_forms[i][j+2]][0].value)!=1) {
	      if (m_t=='') {
	       alert('The "'+ck_fields[ck_forms[i][j+2]][3]+'" field may only contain a valid email address.');}
	      else alert(m_t);		
	      return false;
	    }
	    break;
	  default:	  
         }
	}
/*
	ck_fields[ck_forms[i][j+2]][0] - field (object)
        ck_fields[ck_forms[i][j+2]][1] - req (0/1)
	ck_fields[ck_forms[i][j+2]][2] - type (string)
	ck_fields[ck_forms[i][j+2]][3] - msg (string)
*/
      }
    }
  }
  return true;
}

function isNumeric (InString) {
if(InString.length==0) return (false);
var RefString="1234567890";
for (Count=0; Count < InString.length; Count++) {
        TempChar= InString.substring (Count, Count+1);
        if (RefString.indexOf (TempChar, 0)==-1)
        return (false);
}
return (true);
}

function isFloat (InString) {
if(InString.length==0) return (false);
var RefString="1234567890,.";
for (Count=0; Count < InString.length; Count++) {
        TempChar= InString.substring (Count, Count+1);
        if (RefString.indexOf (TempChar, 0)==-1)
        return (false);
}
return (true);
}

function isMoney (InString) {
if(InString.length==0) return (false);
var RefString="1234567890,. $";
for (Count=0; Count < InString.length; Count++) {
        TempChar= InString.substring (Count, Count+1);
        if (RefString.indexOf (TempChar, 0)==-1)
        return (false);
}
return (true);
}

function isCreditCard (InString) {
if(InString.length==0) return (false);
var RefString="1234567890 ";
for (Count=0; Count < InString.length; Count++) {
        TempChar= InString.substring (Count, Count+1);
        if (RefString.indexOf (TempChar, 0)==-1)
        return (false);
}
return (true);
}

function isEmail(str) {
if (str.indexOf ('@', 0) == -1) {
       return (false);
} else
       return (true);
}

function isExpDate(str) {
  if (str.indexOf ('/', 0) == -1)
	return (false);
  else {
	t = str.substring(0,str.indexOf ('/', 0));
	if (isNumeric(t)!=1||t>12||t==0)
	  return (false);
	t = str.substring(str.indexOf ('/', 0)+1,str.length);
	if (isNumeric(t)!=1||t>50)
	  return (false);
  }
  return (true);
}

var winflag=false;
var top_margin=110;
var left_margin=233;
var right_margin=233;
var bottom_margin=185;
var w_width=485;	//default
var w_height=575;	//default
var old_url="";
var win;
//


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function w_size(){
	if(screen){
		w_width=screen.width-left_margin-right_margin;
		w_height=screen.availHeight-top_margin-bottom_margin-30;
	} 
};

function w_close(){
	if(win!=null)
		if(!win.closed){
			win.close();
 			}
};

function isAOL(f)
{
  if (window.navigator.userAgent.toLowerCase().indexOf("aol")!=-1)
      return true;
  return false;
};

function retnull(f)
{
  if (isAOL())
    window.location.href = f
return;
}
function openlink(url) {
openLinks(url);
return
}

function openLinks(url)
{
//if (isAOL())
//     return false;

if (win == null) 
	{
	  w_size();
	  old_url=url;

  	 top_margin=screen.availHeight/2-150;
	 left_margin=screen.width/2-150;

	  win = window.open(url,null,"top="+top_margin+",left="+left_margin+",height=340,width=300,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
	  
	  winflag=true;
	}
else {
	if(win!=null)
	{
        w_close();
	w_size();
	old_url=url;
	
	top_margin=screen.availHeight/2-150;
	left_margin=screen.width/2-150;

	win = window.open(url, "test","top="+top_margin+",left="+left_margin+",height=320,width=300,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
	}
	else{
		if(window.navigator.appName.toLowerCase().indexOf("netscape")!=-1)
		{
			if(old_url!=url)
			{
				win.location.href=url;
				old_url=url;
			}
			win.focus();
		}
		else{
			win.close();
			w_size();
			old_url=url;
			window.setTimeout("openlinks(\""+url+"\")",300);
		    }
 	   }
      }
   return false;
}

function openNews(url)
{
//if (isAOL())
//     return false;

if (win == null) 
	{
	  w_size();
	  old_url=url;

  	 top_margin=screen.availHeight/2-200;
	 left_margin=screen.width/2-370;

	  win = window.open(url,null,"top="+top_margin+",left="+left_margin+",height=400,width=730,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
	  
	  winflag=true;
	}
else {
	if(win!=null)
	{
        w_close();
	w_size();
	old_url=url;
	
	top_margin=screen.availHeight/2-200;
	left_margin=screen.width/2-370;

	win = window.open(url, "test","top="+top_margin+",left="+left_margin+",height=400,width=730,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
	}
	else{
		if(window.navigator.appName.toLowerCase().indexOf("netscape")!=-1)
		{
			if(old_url!=url)
			{
				win.location.href=url;
				old_url=url;
			}
			win.focus();
		}
		else{
			win.close();
			w_size();
			old_url=url;
			window.setTimeout("openlinks(\""+url+"\")",300);
		    }
 	   }
      }
   return false;
}


var exit=true;
function popuponexit()
{
  if (exit) {
 top_margin=225;
 left_margin=340;
 right_margin=340;
 bottom_margin=240; 
    openLinks('FreeBooklet.asp?mode=1&R=1');
   }
}
