
function copystatus(){
    window.status="© 2006 The Chicago District Golf Association.   All Rights Reserved.";
};

function netscapeKeyPress(e) {
        //alert (e.which);
};

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>' + title + '</title>'); 
   docprint.document.write('<link rel="stylesheet" type="text/css" href="http://www.mygolfadmin.net/css/styleadm.css">')
   docprint.document.write('<link rel="stylesheet" type="text/css" href="http://www.mygolfadmin.net/css/login.css">')
   docprint.document.write('<link rel="stylesheet" type="text/css" href="http://www.mygolfadmin.net/css/generic.css">')
   docprint.document.write('<link rel="stylesheet" type="text/css" href="http://www.mygolfadmin.net/css/style.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 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 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 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 RadioChecked(radioObj) {
	if(!radioObj)
		return (false);
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return  (true);
		else
			return (false);
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return  (true);
		}
	}
	return (false);
}

function netscapeKeyPress(e) {
        //alert (e.which);
}

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 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;   
}
