// JavaScript Document

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function checkWindowSize() {
	// Check for the inner height of the browser window in different OS / Clients
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	
	
	var theHeight = ((myHeight - 490)/2);
	
	document.getElementById("IndexTable").style.marginTop = theHeight;
	}

function checkService()
{
	var myService = document.getElementById("Service").value;
	if (myService == 'Mowing')
	{
		document.getElementById("Day").style.display='block';
		document.getElementById("Time").style.display='none';
	}
	else if (myService == 'Snow Removal')
	{
		document.getElementById("Day").style.display='none';
		document.getElementById("Time").style.display='block';
	}	
}
	
function displayClubPage(id)
{
    var strURL = "J-Club-D.asp?id=" + id;
  
    window.location = strURL;
}

/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
function trimAll( strValue )
{
    var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) 
    {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

    //check for leading & trailing spaces
    objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
    if(objRegExp.test(strValue)) 
    {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
    return strValue;
}

/************************************************
DESCRIPTION: Validates that a string contains valid
  US phone pattern.
  Ex. (999) 999-9999 or (999)999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
function validateUSPhone( strValue ) 
{
    var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;

    //check for valid us phone with or without space between
    //area code
    return objRegExp.test(strValue);
}

/*****************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
******************************************************************/
function  validateNumeric( strValue ) 
{
    var objRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

    //check for numeric characters
    return objRegExp.test(strValue);
}


/************************************************
DESCRIPTION: Validates that a string a United
  States zip code in 5 digit format. 99999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

*************************************************/
function validateUSZip( strValue ) 
{
    var objRegExp  = /(^\d{5}$)/;

    //check for valid US Zipcode
    return objRegExp.test(strValue);
}


/************************************************
DESCRIPTION: Validates that a string contains 
    only a valid integer number.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
**************************************************/
function validateInteger( strValue ) 
{
    var objRegExp = /(^-?\d\d*$)/;

    //check for integer characters
    return objRegExp.test(strValue);
}


/************************************************
DESCRIPTION: Validates that a string contains a
  valid URL pattern.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: the URL may begin with either http://www. 
or https://www. or ftp://www. or just www. once 
followed by any word character one or more times, 
followed by a dot and any number of word characters 
at least once but no more than twice.
*************************************************/
function validateUrl( strValue )
{
    //var objRegExp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
    var objRegExp = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
    
    //check for valid URL
    return objRegExp.test(strValue);
}


/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
function validateEmail( strValue ) 
{
   var objRegExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
   //some other possible email expressions.....
   //var objRegExp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
   //var objRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

   //check for valid email
   //return objRegExp.test(strValue);
   
   if (objRegExp.test(strValue))
   {
      //test email for illegal characters
      var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/
      if (strValue.match(illegalChars)) 
      {
          return false;
      }
   }
   return true;
}

/************************************************
DESCRIPTION: Determines if date is valid.

PARAMETERS: 3 integers: Month, Day and Year

RETURNS: true if date is valid, otherwise false.
*************************************************/
function IsValidDate(Mn,Day,Yr)
{
    var DateVal = Mn + "/" + Day + "/" + Yr;
    var dt = new Date(DateVal);

    if(dt.getDate() != Day)
    {
        //alert('The Day of this date value is not valid.');
        return false;
    }
    else if(dt.getMonth() != Mn-1)
    {
        //this is for the purpose JavaScript starts the month from 0
        //alert('The Month of this date value is not valid.');
        return false;
    }
    else if(dt.getFullYear() != Yr)
    {
        //alert('The Year of this date value is not valid.');
        return false;
    }
        
    return true;
}


function openWindow(toRun)
{ 
    var newwindow;
    var properties;
    var url;
//alert("toRun="+ toRun);

//toRun="yes";
        if (toRun == "yes")
        {
//           if (newwindow) 
//                newwindow.close(); 
//            url = 'Club-F-Response.html';
//            properties = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=487,height=300,top=300,left=350'; 
//            newwindow = window.open(url,'',properties); 
//            newwindow.focus(); 
         	window.open('Club-F-Response.html','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=487,height=300,top=300,left=350').focus();
            var strURL = "./index.asp";
            window.location = strURL;

        }
}

//---------------------------------------------------
// Converts problem characters to JavaScript Escaped values

function JSConvStr(s)
{
   s = s.replace(/\r\n|\r/g, '\n');   //normalize
   s = s.replace(/\\/g, '\\\\');      //escape the backslash character
   s = s.replace(/'/g, '\\\'');       //escape the single quoting character
   s = s.replace(/\"/g, '\\"');		  //escape the double quoting character
   s = s.replace(/\n/g, '\\n');       //escape the newline character
//   return '\'' + s + '\'';
return s;
}


//---------------------------------------------------
// The following functions provide sliding DIV functionality

var timerlen = 5;
var slideAniLen = 250;

var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();

function slidedown(objname){
        if(moving[objname])
                return;

        if(document.getElementById(objname).style.display != "none")
                return; // cannot slide down something that is already visible

        moving[objname] = true;
        dir[objname] = "down";
        startslide(objname);
}

function slideup(objname){
        if(moving[objname])
                return;

        if(document.getElementById(objname).style.display == "none")
                return; // cannot slide up something that is already hidden

        moving[objname] = true;
        dir[objname] = "up";
        startslide(objname);
}

function startslide(objname){
        obj[objname] = document.getElementById(objname);

        endHeight[objname] = parseInt(obj[objname].style.height);
        startTime[objname] = (new Date()).getTime();

        if(dir[objname] == "down"){
                obj[objname].style.height = "1px";
        }

        obj[objname].style.display = "block";

        timerID[objname] = setInterval('slidetick(\'' + objname + '\');',timerlen);
}

function slidetick(objname){
        var elapsed = (new Date()).getTime() - startTime[objname];

        if (elapsed > slideAniLen)
                endSlide(objname)
        else {
                var d =Math.round(elapsed / slideAniLen * endHeight[objname]);
                if(dir[objname] == "up")
                        d = endHeight[objname] - d;

                obj[objname].style.height = d + "px";
        }

        return;
}

function endSlide(objname){
        clearInterval(timerID[objname]);

        if(dir[objname] == "up")
                obj[objname].style.display = "none";

        obj[objname].style.height = endHeight[objname] + "px";

        delete(moving[objname]);
        delete(timerID[objname]);
        delete(startTime[objname]);
        delete(endHeight[objname]);
        delete(obj[objname]);
        delete(dir[objname]);

        return;
}

function toggleSlide(objname){
  var linkId = String(objname) + "Link";
  if(document.getElementById(objname).style.display == "none"){
    // div is hidden, so let's slide down
    slidedown(objname);
    document.getElementById(linkId).innerHTML  = "hide nominees";
  }else{
    // div is not hidden, so slide up
    slideup(objname);
    document.getElementById(linkId).innerHTML  = "show nominees";
  }
}