
function copystatus(){
    window.status="© 2006 The Chicago District Golf Association.   All Rights Reserved.";
};

function netscapeKeyPress(e) {
        //alert (e.which);
};

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function setCheckedValueChar(radioObj,newValue) {
	
	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++)
	{
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString())
		{
			radioObj.checked = true;
		}
	}
}


function Len(str)   {  return String(str).length;  }

function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }


function InStr(strSearch, charSearchFor)
{
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}

function Clickheretoprint(title)
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=800, height=600, left=100, top=25"; 
  var content_vlue2 = document.getElementById("print_content").innerHTML; 

  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>Sunshine Through Golf Foundation (www.sunshinethroughgolf.org)</title>'); 
   docprint.document.write('<link rel="stylesheet" type="text/css" href="http://www.sunshinethroughgolf.org/comm/style.css">')
   docprint.document.write('<link rel="stylesheet" type="text/css" href="http://www.sunshinethroughgolf.org/cust/cstyle.css">')
	docprint.document.write('<link rel="stylesheet" type="text/css" href="http://www.sunshinethroughgolf.org/comm/generic.css">')
  
   docprint.document.write('</head><body onLoad="window.print();"><center>');  
   
   
   docprint.document.write('<div id="container2">'); 
   docprint.document.write('<div id="overlap">' + title + '</div>'); 
   docprint.document.write('<div id="underlap"></div>'); 
   docprint.document.write('</div>'); 
   
   
   docprint.document.write('<div>');          
   docprint.document.write(content_vlue2);        
   docprint.document.write('</div></center></body></html>');
   docprint.document.close(); 
   docprint.focus(); 
}

function check(button,i) {
	var pval = form1["na" + i].value
	//alert(
	if (button.checked && pval == button.value) {
	button.checked=false;
		form1["na" + i].value = "x"
		button.checked=false;
	}
	else
	{	
		form1["na" + i].value = button.value
	}

};

  
function launch(url,name) {
  window.open(url, name);
};

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function chkVal(TheForm,TheFld,Val)	{
	
	if(Left(Val,1) == "<") {TheForm[TheFld].value = "";}	
};

function chkVal2(TheForm,TheFld,Val,nVal)	{
	
	if(Val == "") {TheForm[TheFld].value = nVal;}	
};

function limitext(TheForm,TheFld,Val,len,max)	{
	var maxlength = max;
	var currlength = len;	
	if(maxlength < currlength) {
		TheForm[TheFld].value = TheForm[TheFld].value.substring(0, maxlength);
		alert("Maximum Character Limit Met - " + maxlength);		
	}
};

function validate(form) {
ini = form.ini.value;
if (ini=='') 
	{
		alert('Your initials are a required field. Please enter before Submitting.');
		return false;
	}
else
	{
		if (form.bAccept.checked==false)
			{
				alert('You must check that you certify the information is accurate.');
				return false;
			}
	}
}

function replace(string,text,by) {
    // Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function userConfirm() { 
	return window.confirm ("Are you sure you want to delete this record?");
} 

function userConfirmMsg(msg) { 
	var newmsg = msg
	return window.confirm(newmsg);
} 

function userConfirmF() { 
	return window.confirm ("Are you sure you want to remove the this file?") 
} ;

function userConfirmVal(msg,val) { 
	var newmsg = msg + ": " + val
	return window.confirm(newmsg) 
} ;

function popup(url,name,h,w) {
  window.open(url, name, 'left=340,top=80,width=' + w + ',height=' + h + ',scrollbars,resizable');
}

function popupFull(url,name) {
	var h = screen.availHeight-40
	var w = screen.availWidth-20
	//alert(h);
	window.open(url, name, 'top=0,left=0,width=' + w + ',height=' + h + ',scrollbars,resizable');
}

function showtip(current,e,text) {
   if (document.all)
   {
      thetitle=text.split('<br>')
      if (thetitle.length > 1) {
        thetitles=""
        for (i=0; i<thetitle.length; i++)
           thetitles += thetitle[i] + "\r\n"
        current.title = thetitles
      }
      else current.title = text
    }
   else if (document.layers) {
       document.tooltip.document.write( 
           '<layer bgColor="#FFFFE7" style="border:1px ' +
           'solid black; font-size:12px;color:#000000;">' + text + '</layer>')
       document.tooltip.document.close()
       document.tooltip.left=e.pageX+5
       document.tooltip.top=e.pageY+5
       document.tooltip.visibility="show"
    }
}


function visi(nr)
{
//alert("hi");
	if (document.layers)
	{
		vista = (document.layers[nr].visibility == 'hide') ? 'show' : 'hide'
		document.layers[nr].visibility = vista;
	}
	else if (document.all)
	{
		vista = (document.all[nr].style.visibility == 'hidden') ? 'visible'	: 'hidden';
		document.all[nr].style.visibility = vista;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.visibility == 'hidden') ? 'visible' : 'hidden';
		document.getElementById(nr).style.visibility = vista;

	}
}

function hidetip() {
    if (document.layers)
        document.tooltip.visibility="hidden";
}


function submitform(form,url) {
   form.action= url;   
   form.submit();  
}

function disableButton(theButton)
{
 theButton.value="Processing...";
 theButton.disabled = true; 
}

function sendValue(s,fld)
{
	var selvalue = s.value;
	window.opener.document.form1.fld.value = selvalue;
	window.close();
}

function fMoveDown(yr)
{
	var cyYear = yr;
	var lyYear = form2.cyYear.value;
	var lyoncamp = form2.cyoncamp.value;
	var lyoffcamp = form2.cyoffcamp.value;
	var lycommute = form2.cycommute.value;
	
	form2.lyYear.value = lyYear
	form2.lyoncamp.value = lyoncamp
	form2.lyoffcamp.value = lyoffcamp
	form2.lycommute.value = lycommute
	form2.cyYear.value = cyYear
	form2.cyoncamp.value = ''
	form2.cyoffcamp.value = ''
	form2.cycommute.value = ''

}

function Form_Validator(theForm)
{
   if (theForm.bname.value == "")	  {
    alert("Please enter a value for the \"Cardholder Name\" field.");
    theForm.bname.focus();
    return (false);	  }

	// alter if allowing amex
   if ((theForm.x_card_num.value == "") || (theForm.x_card_num.value.length != 16))	{
    alert("Please enter a valid \"Credit Card Number\".");
    theForm.x_card_num.focus();
    return (false);	    }
    
    
  if ((theForm.x_card_code.value == "") || (theForm.x_card_code.value.length < 3)) {
    alert("Please enter a valid \"Security Code\".");
    theForm.x_card_code.focus();
    return (false);	  }
    
  if ((theForm.expmo.value == "") || (theForm.expyr.value == "")) {
    alert("Please enter a value for the \"Card Expiration\".");
    theForm.expmo.focus();
    return (false);	  
  }  else {
    
		var now = new Date();	// this function is designed to be Y2K compliant.
		var mo = theForm.expmo.value;
		var yr = theForm.expyr.value
        var expiresIn = new Date(yr,mo,0,0,0);		// create an expired on date object with valid thru expiration date
        expiresIn.setMonth(expiresIn.getMonth());		// adjust the month, to first day, hour, minute & second of expired month
        if( now.getTime() > expiresIn.getTime() ) {
       
			alert("Your Credit Card appears to have Expired.");
			theForm.expmo.focus();
			return (false);	  
		}
    }
    
  if ((theForm.baddr.value == "") || (theForm.bcity.value == "") || (theForm.bstate.value == "") || (theForm.bzip.value == "")) {
    alert("Please enter your Complete \"Billing Address\".");
    theForm.baddr.focus();
    return (false);	  }
    
  if (theForm.phbiz.value == "") {
    alert("Please enter a value for your \"Daytime Phone #\" field.");
    theForm.phbiz.focus();
    return (false);	  } 
  return (true);
}

function ValidateEntryTest(theForm)
{	
	var myCardNo = theForm.x_card_num.value;
	alert(myCardNo.length);
	return (false);
	
}

function ValidateEntry(theForm)
{	
    if ((theForm.cmd.value != "badpl") && (parseFloat(theForm.fmco.value) != 0))	  {    
		var club = theForm.clubid.options[theForm.clubid.selectedIndex].value;
		if (club == 0) {	
		alert("Please indicate your \"Club Affiliation\".");
		return (false);	  }
   }
   
   if (theForm.fee.value != 0) {
   
	 if (theForm.bname.value == "")	  {
	  alert("Please enter a value for the \"Cardholder Name\" field.");
	  theForm.bname.focus();
	  return (false);	  }	

	 //if ((theForm.x_card_num.value == "") || (theForm.x_card_num.value.length != 16))	{
	 // alert("Please enter a valid \"Credit Card Number\".");
	 // theForm.x_card_num.focus();
	 // return (false);	  }
	 
	 var myCardNo = theForm.x_card_num.value;			
		if (myCardNo == "") {
			alert("Please enter a valid \"Credit Card Number\".");
			theForm.x_card_num.focus();
			return (false);	  }	  
	  
		var myCardType = getCheckedValue(theForm.cctype);	
		if (!checkCreditCard (myCardNo,myCardType)) {
			alert (ccErrors[ccErrorNo])
			theForm.x_card_num.focus();
		return (false);	  }
		
		
	  
	if ((theForm.x_card_code.value == "") || (theForm.x_card_code.value.length < 3)) {
	  alert("Please enter a valid \"Security Code\".");
	  theForm.x_card_code.focus();
	  return (false);	  }
    
	if ((theForm.expmo.value == "") || (theForm.expyr.value == "")) {
	  alert("Please enter a value for the \"Card Expiration\".");
	  theForm.expmo.focus();
	  return (false);	  	  
	}  else {
	  
			var now = new Date();	// this function is designed to be Y2K compliant.
			var mo = theForm.expmo.value;
			var yr = theForm.expyr.value
	      var expiresIn = new Date(yr,mo,0,0,0);		// create an expired on date object with valid thru expiration date
	      expiresIn.setMonth(expiresIn.getMonth());	// adjust the month, to first day, hour, minute & second of expired month
	      if( now.getTime() > expiresIn.getTime() ) {
	     
				alert("Your Credit Card appears to have Expired.");
				theForm.expmo.focus();
				return (false);	  
			}
	  }
	  
	if ((theForm.baddr.value == "") || (theForm.bcity.value == "") || (theForm.bstate.value == "") || (theForm.bzip.value == "")) {
	  alert("Please enter your Complete \"Billing Address\".");
	  theForm.baddr.focus();
	  return (false);	  }
	  
	if (theForm.phbiz.value == "") {
	  alert("Please enter a value for your \"Daytime Phone #\".");
	  theForm.phbiz.focus();
	  return (false);	  }
  }       
  return (true);
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function netscapeKeyPress(e) {
        //alert (e.which);
}

function VerifyTeamSrchForm(theForm)
{
	if (getCheckedValue(theForm.pid)=="") 	{
	 alert("Please select the Registrant.");
	 return (false);	  }
	if (getCheckedValue(theForm.pid2)=="") 	{
	 alert("Please select Player 2.");
	 return (false);	  }

}

function VerifyTeamForm(theForm)
{
	if (theForm.fname.value == "" && theForm.lname.value == "" && theForm.ghin.value == "")	  {
	 alert("Please enter a name or CDGA # for at least the first player.");
	 theForm.ghin.focus();
	 return (false);	  }
	 
	//if (theForm.fname2.value == "" && theForm.lname2.value == "" && theForm.ghin2.value == "")	  {
	//alert("Please enter a name or CDGA # for both players.");
	// theForm.ghin2.focus();
	// return (false);	  }

}

function VerifySemForm(theForm)
{		 
	if (theForm.fname.value == "" || theForm.lname.value == "")	  {
	 alert("Please enter your \"Full Name\".");
	 theForm.fname.focus();
	 return (false);	  }
		 
	if (theForm.addr1.value == "" || theForm.city.value == "" || theForm.state.value == "" || theForm.zip.value == "" )	  {
	 alert("Please enter your complete \"Address\".");
	 theForm.addr1.focus();
	 return (false);	  }	
		 
	if (theForm.email.value == "")	  {
	 alert("Please enter a valid \"Email Address\".");
	 theForm.email.focus();
	 return (false);	  }    
      	
  return (true);
}

function ValidateRegForm(theForm)
{
	if (theForm.fname.value == "" && theForm.lname.value == "" && theForm.ghin.value == "")	  {		
		 theForm.ghin.focus();
		 return (false);	  }
	 
	 if (theForm.ghin.value != "" && getCheckedValue(theForm.assoc) == "")	  {		
		alert("Please select your \"Association\".");
		 theForm.ghin.focus();
		 return (false);	  }
	if (theForm.ghin.value == "")	{
	
		if (theForm.lname.value != "" && theForm.fname.value == "" || theForm.email.value == "")	  {		
			 theForm.email.focus();
			 alert("Last Name, First Name and Email are ALL Required.");
			 return (false);	  }
			 
		if (theForm.email.value != "" && theForm.fname.value == "" || theForm.lname.value == "")	  {		
			 theForm.email.focus();
			 alert("Last Name, First Name and Email are ALL Required.");
			 return (false);	  } 
     }
  return (true);
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function SetFieldValue(TheForm,radio,fld,nval) {
	//this is based on a 0/1 radio value
	
	var val = TheForm[radio].value;
	//alert(val);
	if(val==1) {
		TheForm[fld].value = nval
	} else {
		TheForm[fld].value = ''
	}


}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr,Fld){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The " + Fld + " format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid " + Fld + "month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid " + Fld + " day");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit " + Fld + " year between "+minYear+" and "+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid " + Fld);
		return false;
	}
return true;
}

function isDate2(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	var isok=true;
	strYr=strYear
	
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		isok=false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		isok=false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		isok=false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		isok=false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		isok=false;
	}
	return isok;
}

function ValidateDOB(){
	var dt=document.form1.dob
	if (isDate(dt.value,'Date of Birth')==false){
		dt.focus()
		return false;
	}
    return true;
 }
 
 function IsFutureDate( str1 )
{   
    var dateNow = new Date();  
    var dateForm = new Date(str1);  
    return dateNow < dateForm;
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char; 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

function IsInteger2(sText)
{
   var ValidChars = "0123456789";
   var IsOK=true;
   var Char; 
   for (i = 0; i < sText.length && IsOK == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsOK = false;
         }
      }
   return IsOK;   
}

function IsDecimal(sText)
{
   var ValidChars = ".";
   var IsNumber=false;
   var Char; 
   for (i = 0; i < sText.length && IsNumber == false; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = true;
         }
      }
   return IsNumber;   
}

function sethiddenval() {
	form2.isok.value = 9873;
	//alert(form2.value.isok);
}
