function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function relExternal() {
  if(document.getElementsByTagName) {
    var arA = document.getElementsByTagName('a');
    for (var i = 0; i < arA.length; i++) 
      {	
        if(arA[i].rel )
        {
            var a_rel = arA[i].rel;
            var relExp = /external/gi;
            var relExpResult = a_rel.match(relExp);
            if(relExpResult && relExpResult.length > 0)
            {						
              arA[i].target="_blank";
              arA[i].title += ' [opens in a new window] ';
            }
            
        }
      }
  } // end if
}

  //check to see that at least one of the I want to know about checkboxes are checked
  
//this function is used to add a function to onload. 
function addContactLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

//attach the submit event
function checkIwantToKnowMoreAboutEvent()
{
    if(document.getElementById('form_ContactUs'))
    {
    var contactForm = document.getElementById('form_ContactUs');
    contactForm.onsubmit = checkIwantToKnowMoreAbout;
    }
}

//check to see if at least one is ticked
function checkIwantToKnowMoreAbout()
{

    var contactForm = document.getElementById('form_ContactUs');
    var usr_std_str_stand = document.getElementById('usr_std_str_stand');
    var usr_std_str_acre = document.getElementById('usr_std_str_acre');
    var usr_std_str_grove = document.getElementById('usr_std_str_grove');
    var usr_std_str_group = document.getElementById('usr_std_str_group');
    
    //at least one must be checked
    if( usr_std_str_stand.checked != true && usr_std_str_acre.checked != true && usr_std_str_grove.checked != true && usr_std_str_group.checked != true )
    {
        alert('You must choose at least one option you would like more details about');
        //alert message 
        return false;
    }
    else
    {
        return true;
    }
}


//check to see if at least one is ticked
function checkDateSubmitted()
{
    if(document.getElementById('designfundform') || document.getElementById('editfunddetails'))
    {
        if(document.getElementById('designfundform'))
        {
            var designfundform = document.getElementById('designfundform');
        }
        else if(document.getElementById('editfunddetails'))
        {
            var designfundform = document.getElementById('editfunddetails');
        }
        
        
        designfundform.onsubmit= function(){
           
            var curDate = new Date();
            
            var curTime = curDate.getTime();
            
           
            var usr_req_day = document.getElementById('usr_req_day');
            var usr_req_month = document.getElementById('usr_req_month');
            var usr_req_year = document.getElementById('usr_req_year');
            
            usr_req_day = usr_req_day.options[usr_req_day.selectedIndex].value;
            usr_req_month = usr_req_month.options[usr_req_month.selectedIndex].value;
            usr_req_year = usr_req_year.options[usr_req_year.selectedIndex].value;
            
            var closingDate = new Date(usr_req_year,(usr_req_month - 1),usr_req_day);
            var closingTime = closingDate.getTime();
            //alert('usr_req_day = '+usr_req_day + ' usr_req_month = '+usr_req_month + ' usr_req_year = '+usr_req_year);
            //alert('curTime = '+curTime + ' closingtime = '+closingTime);
            if( curTime >= closingTime )
            {
                alert('Your fund closing day must be in the future'); 
                return false;
            }
            else
            {
                return true;
            }
        }
   
    }
    else
    {
        return true;   
    }
}

//attach the load function

addContactLoadEvent(checkIwantToKnowMoreAboutEvent);
addLoadEvent(checkDateSubmitted);
addLoadEvent(relExternal);


