/* Even 'column' script
Derived from a script by Alejandro Gervasio. 
Modified to work in FireFox by Stefan Mischook for Killersites.com
Modified by Erica Melton to work in WST
How it works: just apply the CSS class of 'column' to your pages' main columns.
Add "matchColumns();" to body onload.
*/
function matchColumns()
{ 
  var divs,contDivs,maxHeight,divHeight,d; 
	
  // get all <div> elements in the document 
  divs=document.getElementsByTagName('div'); 
  contDivs=[]; 

  // initialize maximum height value 
  maxHeight=0; 

  // iterate over all <div> elements in the document 
  for(var i=0;i<divs.length;i++){ 
    // make collection with <div> elements with class attribute 'container' 
    if(/\bcolumn\b/.test(divs[i].className))
	  { 
      d=divs[i]; 
      contDivs[contDivs.length]=d; 
		
      // determine height for <div> element 
      if(d.offsetHeight)
	    { divHeight=d.offsetHeight;}
      else if(d.style.pixelHeight)
	    { divHeight=d.style.pixelHeight;} 

      // calculate maximum height 
      maxHeight=Math.max(maxHeight,divHeight); 
      } 
    } 

    // assign maximum height value to all of container <div> elements 

    for(var i=0;i<contDivs.length;i++)
	{ contDivs[i].style.height=maxHeight + "px"; } 	
} 

/* AJAX FUNCTION */
function ajaxFunction(url,divid)
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        document.getElementById(divid).innerHTML = xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
  	
// When page (dom) is ready...
$(document).ready(function(){
	    /********************************************
	     Add un-obstrusive Print Button to anywhere we put id="printMe"
	    *******************************************/ 
            $(function() {
              addSearchLink();
            });
            $(function(){
              addPrintButton();
            });
            function addSearchLink() {
                $('<a href="/event_search">Return to events</a> <br/><br/> ')
                .appendTo('#printMe');
            };
            
            function addPrintButton() {
              $('<button class="fg-button ui-state-default fg-button-icon-right ui-corner-all">Print this page</button>')
                .click(function(){window.print();})
                .appendTo('#printMe');
            };

		/********************************************
		Set	Form object masks
		********************************************/
		$("#racerphone").mask("999-999-9999");
		$("#raceremergencyphone").mask("999-999-9999");
		$("#racerzip").mask("99999");
		$("#racerdob").mask("99/99/9999");

		/********************************************
		DatePicker: this sets date object, gets year, then goes back 90 years for date range.
		********************************************/
		var CT = new Date()
		var ThisYear = CT.getFullYear();
		var Less90 = ThisYear-110
		var totalDate = Less90+':'+ThisYear;
		//Provide DatePicker to Date of Birth field
		$('#racerdob').datepicker({
		    dateFormat: 'mm/dd/yy',
		    maxDate: '-2Y',
			yearRange: totalDate,
			changeMonth: true,
			changeYear: true,
			showOn: 'button', buttonImageOnly: true, buttonImage: '/images/calicon.gif'
		}); 


	    /********************************************
	     Delete objects from cart
	    *******************************************/ 	
	    $(function() {
	        $('.deleteCart').click(function(event){
	    	        event.preventDefault();
			        $('#cartObject').load('/ajax.asp?page=del&id=' + $('.deleteCart').attr('name'));
	         });
	     });

	    /********************************************
	     Add Addons to cart
	    *******************************************/ 	
	    $(function() {
	        $('.addonToCart').click(function(event){
	    	        event.preventDefault();
			        $('#cartObject').load('/ajax.asp?page=add&aid=' + $('.addonToCart').attr('aid') + '&eid=' + $('.addonToCart').attr('eid'));
	         });
	     });
	     	     
/********************************************
Show RD Email Address
*******************************************/ 	
	$(function() {
		$("#emailaddress").dialog({
			autoOpen: false,
			title: 'Race director e-mail address'
		});
	});
/********************************************
Show Search Help
*******************************************/ 	
	$(function() {
		$("#searchHelp").dialog({
			autoOpen: false,
			title: 'Search Help'
		});
	});
/********************************************
Participant List
*******************************************/ 		
	$(function() {
	    $('.participantList').click(function(e){
			    e.preventDefault();
    			var $this = $(this);
    			var myURL = $this.attr('href');
			    
			    var horizontalPadding = 30;
			    var verticalPadding = 30;
	            $('<iframe id="externalSite" name="externalSite" src="' + myURL + '" />').dialog({
	                title: ($this.attr('title')) ? $this.attr('title') : 'Event Participants',
	                autoOpen: true,
	                width: 700,
	                height: 500,
	                modal: true,
	                resizable: true,
				    autoResize: true,
	                overlay: {
	                    opacity: 0.5,
	                    background: "black"
	                }
	            }).width(700 - horizontalPadding).height(500 - verticalPadding);	
    					        
		    });
		    });	
/********************************************
Invite Form - not working as of 2-9-10
*******************************************/ 		    
	$(function() {
		$("#inviteform").dialog({
			bgiframe: true,
			autoOpen: false,
			height: 500,
			width:450,
			title: 'Send event to a friend',
			modal: true
		});
	});		 
/********************************************
code for iframe to payment gateway NOT WORKING as of 2-9-10
*******************************************/ 		    
$(function() {
	$('form#chargePopUpFormXXX').submit(function(e){
//			e.preventDefault();
			var myURL = 'https://www.staging.linkpointcentral.com/lpc/servlet/lppay';
			var $this = $(this);
			var horizontalPadding = 30;
			var verticalPadding = 30;
	        $('<iframe id="externalSite" name="externalSite" src="' + myURL + '" />').dialog({
	            title: ($this.attr('title')) ? $this.attr('title') : 'Please enter credit card info.',
	            autoOpen: true,
	            width: 700,
	            height: 500,
	            modal: true,
	            resizable: true,
				autoResize: true,
	            overlay: {
	                opacity: 0.5,
	                background: "black"
	            },
	            button: {
	                "Cancel":function() { $(this).appendTo('form').dialog('close')}
	            },
	            closeOnEscape: false,
	            close: function() { window.location = '/Event Search';
	            }
	        }).width(700 - horizontalPadding).height(500 - verticalPadding);	

		});
    });	


/********************************************
Field list for blocking restricted characters on client side.
*******************************************/ 
/* Register & Account create/update */
$('#racerfirstname').alphanumeric({allow:" "});
$('#racerlastname').alphanumeric({allow:", "});
$('#raceraddress1').alphanumeric({allow:", "});
$('#raceraddress2').alphanumeric({allow:", "});
$('#racercity').alphanumeric({allow:"- "});
$('#racerstate').alphanumeric();
$('#racerzip').numeric();
$('#raceremail').alphanumeric({allow:"@.- "}); /*added: - 7-27-10*/
$('#racerphone').alphanumeric({allow:"- "});
$('#racerdob').alphanumeric({allow:"/- "});
$('#raceremergencycontact').alphanumeric({allow:", "});
$('#raceremergencyphone').alphanumeric({allow:"-/ "});
$('#racerteamname').alphanumeric({allow:"- "});
$('#racerinitials').alphanumeric();
$('#racerpassword').alphanumeric();
/* search */
$('#quickSearch').alphanumeric({allow:",- "});
/* logins */
$('#user').alphanumeric({allow:"@. "});
$('#pw').alphanumeric();

/* custom fields */
$('#custom1').alphanumeric({allow:", "});
$('#custom2').alphanumeric({allow:", "});
$('#custom3').alphanumeric({allow:", "});
$('#custom4').alphanumeric({allow:", "});
$('#custom5').alphanumeric({allow:", "});


/* http://itgroup.com.ph/alphanumeric/ Details:

   1. allow - add exempted characters to the rule of prevention
   2. ichars - define a custom set of characters to prevent
   3. allcaps - allow only capital letters to be entered
   4. nocaps - allow only lowercase characters to be entered
   
$('.sample2').alphanumeric({allow:"., "});
$('.sample3').alpha({nocaps:true});
$('.sample4').numeric();
$('.sample5').numeric({allow:"."});
$('.sample6').alphanumeric({ichars:'.1a'});


	*/
});
