function element(id) {
 if(document.getElementById != null) {
  return document.getElementById(id);
 }
 if(document.all != null) {
  return document.all[id];
 }
 if(document.layers != null) {
  return document.layers[id];
 }
 return null;
} 

function profile_submission_clear(lel){
   $(lel).select();
}

var county_ary = Array();
var category_ary = Array();


function add_cat(cat) {
    category_ary.push(cat);    
    //alert('category ' + category_ary);
}


function add_count(count) {
    county_ary.push(count);
    //alert('county ' + county_ary);    
}


function lel(in_array, type){

if(type=='category'){
	//check to see if link_id is already in cat array, if it is remove it
	for(x=0; x < category_ary.length; x++){
	//alert('got in for loop' + x);
		var link = category_ary[x];				
		if(link==in_array){					
			category_ary.splice(x,1);
			element(in_array).style.background='#dddddd';
			element(in_array).style.color='#79a6b9';            
            var cat_values = category_ary.join();
            element('category_field').value = cat_values;
            //alert(element('category_field').value);
            return false;            
		}else{
			category_link_in_array = 'false';
		}		
	}
	//if array is empty or the link is not yet in the array, add link to array, turn on background, add value to hidden field	
	if (category_ary.length == 0 || category_link_in_array=='false'){
		element(in_array).style.background='#79a6b9';
		element(in_array).style.color='#ffffff';        
		category_ary.push(in_array);
		var cat_values = category_ary.join();
		//alert('Got here, cat values are ' + cat_values);
		element('category_field').value = cat_values;
		//alert('Assigned values to category_field');		
	}	
	//alert(element('category_field').value);
    return false;
}
		
if(type=='county'){		
	//check to see if link_id is already in county array, if it is remove it
	for(x=0; x < county_ary.length; x++){
		var link = county_ary[x];				
		if(link==in_array){					
			county_ary.splice(x,1);
			element(in_array).style.background='#dddddd';
			element(in_array).style.color='#79a6b9';        
            
            var county_values = county_ary.join();
    		element('county_field').value=county_values;
            //alert(element('county_field').value);
			return false;
		}else{
			county_link_in_array = 'false';
		}		
	}
	//if array is empty or the link is not yet in the array, add link to array, turn on background, add value to hidden field	
	if (county_ary.length == 0 || county_link_in_array=='false'){		
		element(in_array).style.background='#79a6b9';
		element(in_array).style.color='#ffffff';        				
		county_ary.push(in_array);
		var county_values = county_ary.join();
		//alert('Got here, county values are ' + county_values);
		element('county_field').value=county_values;
		//alert('Assigned values to county fields ' + county_values);		
	}
    //alert(element('county_field').value);
	return false;
	
}
}

//PROVIDERS NETWORK POPUP
function displayProviderForm() {
	ajax('provider-reg.php','date='+date,fill,'event');
   moveEventBox(placement);
}

function hideProviderForm() {
  dElem.style.display = 'none';
  grayOut(false);
}

function ajax(url, vars, callbackFunction, elemName){
  var request = window.XMLHttpRequest ?
  new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  request.onreadystatechange = function() {
    if (request.readyState == 4 && request.status == 200) {
      if (request.responseText) {
        callbackFunction(request.responseText, elemName);
      }
    }
  };
  request.send(vars);
}

function fill(responseText,elemName) {
	var e = $(elemName);
	e.innerHTML = "<div id='eventInner1'></div><div id='eventInner2'><div onclick=\"hideEvent()\" id='eventClose'></div><div id='eventInner'>" + responseText + "</div></div><div class='cB'></div>";
	e.style.display = 'block';
}

function moveEventBox(position) {
  dElem = $('event');
  dElem.style.top  = '-350px';
  dElem.style.left =   '130px';
  dElem.style.zIndex = 51;
}

function grayOff() {
  hidePark()
  hideEvent();
  grayOut(false);
}

function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 55;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.onclick = grayOff;
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
        var pH1 = document.body.scrollHeight;
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
      var pH1 = document.body.offsetHeight;
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
       var pH1 = 0;
    }
    var pH2 = getWindowHeight();
    if (pH2 > pH1) {
      pageHeight=pH2+'px';
    }
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';
    dark.onclick=grayOff;
  } else {
     dark.style.display='none';
  }
}

function getWindowHeight() {
  var wh;
  d = document;
  if (typeof window.innerHeight != 'undefined') {
    wh = window.innerHeight;  // NN and Opera version
  } else {
    if (d.documentElement &&
        typeof d.documentElement.clientHeight!='undefined' &&
        d.documentElement.clientHeight != 0) {
      wh = d.documentElement.clientHeight;
    } else {
      if (d.body && typeof d.body.clientHeight != 'undefined') {
        wh = d.body.clientHeight;
      }
    }
  }
  return wh;
}

function eventOnload(date) {
  grayOut(true);
  eventDisp('1',onloadDate,'');
}

var tDisp;

function timedHover(id,date,placement) {
  tDisp = setTimeout("eventDisp('"+id+"','"+date+"','"+placement+"');grayOut(true);",500);
}


function timedHoverPark(id) {
  tDisp = setTimeout("parkDisp('"+id+"');grayOut(true);",500);
}

function cancelHover() {
  clearTimeout(tDisp);
}

var xmlhttp=false;
try {
 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
 try {
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 } catch (E) {
  xmlhttp = false;
 }
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 xmlhttp = new XMLHttpRequest();
}  

function checkform(){
	if($("name").value==""){alert("Please enter your name."); return false;}
	if($("name2").value==""){alert("Please enter your friend's name."); return false;}
	if($("email").value==""){alert("Please enter your email address."); return false;}
	if($("email2").value==""){alert("Please enter your friend's email address."); return false;} 
	if($("subject").value==""){alert("Please enter a subject."); return false;}
	return true;
}
 
var inner = "";
var inner_event = "";

function send_friend(event_id){
	
	var name = $('name').value;
	var name2 = $('name2').value;
	var email = $('email').value;
	var email2 = $('email2').value;
	var subject = $('subject').value;
	var message = $('message').value;
	
	pg = "send-a-friend.php?name="+escape(name)+"&name2="+escape(name2)+"&email="+escape(email)+"&email2="+escape(email2)+"&subject="+escape(subject)+"&message="+escape(message)+"&event_id="+escape(event_id)+"";
	xmlhttp.open("GET", pg, true);
 
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		    //alert(xmlhttp.responseText);
            var splits = xmlhttp.responseText.split('@|@|@');
            if(splits[0] != "") {
		        inner_event = $('response_text_inner_event').innerHTML;
		        //make_appear();
		        $('response_text_inner_event').innerHTML = splits[1];
            } else {
                inner = $('response_text_inner').innerHTML;
		        //make_appear();
		        $('response_text_inner').innerHTML = splits[1];
            }
		}	
	}
 xmlhttp.send(null)
}

function make_appear(event_id){
	grayOut(true);
if(event_id == "" || event_id == undefined){
    if(inner != ""){$('response_text_inner').innerHTML = inner;}
    var dim = Position.positionedOffset($('send-a-friend'));
	var height = dim[1];
	var width = dim[0];
    $('response_text_inner').style.display = 'block';
	$('response_text_inner').style.padding = '10px';
	$('response_text_inner').style.width = '600px';
	$('response_text_inner').style.height = '400px';
	$('response_text_inner').style.position = 'absolute';	
	var real_pos = height - 463;    
	$('response_text_inner').style.top = real_pos+'px';
	$('response_text_inner').style.left = '220px';
	$('response_text_inner').style.backgroundColor = 'white';
	$('response_text_inner').style.borderWidth = '2px';	
	$('response_text_inner').style.borderColor = '#ccc';
	$('response_text_inner').style.zIndex = '99';
} else {
    if(inner_event != ""){$('response_text_inner_event').innerHTML = inner_event;}
    var dim = Position.positionedOffset($('send-a-friend2'));
	var height = dim[1];
	var width = dim[0];
    $('response_text_inner_event').style.display = 'block';
	$('response_text_inner_event').style.padding = '10px';
	$('response_text_inner_event').style.width = '600px';
	$('response_text_inner_event').style.height = '400px';
	$('response_text_inner_event').style.position = 'absolute';
	var real_pos = height - 95 ;
	$('response_text_inner_event').style.top = real_pos+'px';
	$('response_text_inner_event').style.left = '93px';
	$('response_text_inner_event').style.backgroundColor = '#eee';
	$('response_text_inner_event').style.borderWidth = '2px';	
	$('response_text_inner_event').style.borderColor = '#ccc';
	$('response_text_inner_event').style.zIndex = '99';
}
	
}

function make_disappear(div_name){
    var freddy = $(div_name);
	freddy.style.display = 'none';        
}

function changeNumPlayers(){

  var box = element('quantity');
  var num = box.value;
  if(num==0){
   for(var i=1;i<4;i++){
    element('reqMate'+i).style.display='none';
    element('reg'+i).style.display='none';
   }
   return;
  }
  for(var i=1;i<4;i++){
   if(i<num){
    element('reqMate'+i).style.display='none';
    element('reg'+i).style.display='';
   }else{
    element('reqMate'+i).style.display='';
    element('reg'+i).style.display='none';
   }
 }
}

function autofiller(){
 if(element('prefill_golfer').checked ===  true){
	 element('name').value = element('spon_name').value;
		element('company').value = element('spon_company').value;
		element('address').value = element('spon_address').value;
		element('address2').value = element('spon_address2').value;
		element('city').value = element('spon_city').value;
		//element('state').options[element('state').selectedIndex].value = element('spon_state').options[element('spon_state').selectedIndex].value;
		element('state').value = element('spon_state').value;
		element('zip').value = element('spon_zip').value;
		element('phone').value = element('spon_phone').value;
		element('email').value = element('spon_email').value;
	}
	else if(element('prefill_golfer').checked ===  false){
	 element('name').value = '';
		element('company').value = '';
		element('address').value = '';
		element('address2').value = '';
		element('city').value = '';
		//element('state').options[element('state').selectedIndex].value = '';
		element('state').value = '';
		element('zip').value = '';
		element('phone').value = '';
		element('email').value = '';
	}
}
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;


