/* --- (INFORMATION) ----------------------------------------------------
File:
Author:
Date Created:
Last Modified:
Last Modified By:
Description:

------------------------------------------------------------ (END) --- */

/* START MAIN EVENTS CALENDAR */
function go_event_date(intNewDate, intNewMonth)
{
	// display the loading image
	document.getElementById( 'main_events_block' ).innerHTML = "<div align='center' style='margin: 0px; padding-top: 150px; width: 300px;'><img src='images/ajax_loading.gif' /><br>Loading...</div>";
	DWREngine._execute("function_event_calendar.cfm", null, 'readMainEventCalendarFunction', intNewDate, intNewMonth, getMainEventsResult);
}
function getMainEventsResult(result)
{
	document.getElementById('main_events_block').innerHTML = result;
}
/* END MAIN EVENTS CALENDAR */


/* MONTH SELECT BOX FROM MAIN EVENTS CALENDAR */
function reload_date(form) {
	var myindex = form.main_event_calendar.selectedIndex
	var chimney = form.main_event_calendar.options[myindex].value;
	go_event_date(1, chimney);
}



/* START MISSION CALENDAR */
function go_date(thenewdate)
{
	var neweventdate = thenewdate;
	// display the loading image
	document.getElementById( 'calendar_container' ).innerHTML = "<div align='center'><br /><br /><br /><br /><br /><br /><br /><img src='images/ajax_loading.gif' /><br>Loading...</div>";
	// clear the error div
	DWREngine._execute("function_calendar.cfm", null, 'getNewDate', neweventdate, getDateResult);
}
function getDateResult(result)
{
	document.getElementById('calendar_container').innerHTML = result;
}
/* END MISSION CALENDAR */


/* START PHOTO GALLERY */
function getPhoto(photo)
{
	var photoid = photo;

	// display the loading image
	document.getElementById( 'photo_container' ).innerHTML = "<div align='center'><br /><br /><br /><br /><br /><br /><br /><img src='images/ajax_loading.gif' /><br>Loading...</div>";
	// clear the error div
	//document.getElementById( 'impact_fact_container' ).innerHTML = "";
	DWREngine._execute("function_photo.cfm", null, 'getPhoto', photoid, getPhotoResult);
}
function getPhotoResult(result)
{
	
	document.getElementById('photo_container').innerHTML = result;
}
/* END PHOTO GALLERY */

function PopPic(photoid) 
	{
		w = 475;//Math.floor(800);
	     h = 323; Math.floor(screen.availHeight-60);
		jx = window.open('photo.cfm?photoid=' + photoid,'regwindow', 'width='+w+',height='+h+',top=1, left=1, resizable=no, scrollbars=no, status=no');
	
	}
function PopPicTall(photoid) 
	{
		w = 323;//Math.floor(800);
	     h = 475; Math.floor(screen.availHeight-60);
		jx = window.open('photo.cfm?photoid=' + photoid,'regwindow', 'width='+w+',height='+h+',top=1, left=1, resizable=no, scrollbars=no, status=no');
	
	}


/* FORM VALIDATION */

function ClearName(textbox) {
  if (textbox.value == 'Type Your Name Here') { textbox.value='';}
}

function FillName(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Name Here';}
}

function ClearPhone(textbox) {
  if (textbox.value == 'Type Your Phone Number Here') { textbox.value='';}
}

function FillPhone(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Phone Number Here';}
}

function ClearEmail(textbox) {
  if (textbox.value == 'Type Your Email Here') { textbox.value='';}
}

function FillEmail(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Email Here';}
}

function ClearSubject(textbox) {
  if (textbox.value == 'Type Your Subject Here') { textbox.value='';}
}

function FillSubject(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Subject Here';}
}

function ClearMessage(textbox) {
  if (textbox.value == 'Type Your Message Here') { textbox.value='';}
}

function FillMessage(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Message Here';}
}
function ClearAddress(textbox) {
  if (textbox.value == 'Type Your Address Here') { textbox.value='';}
}

function FillAddress(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Address Here';}
}
function ClearYOB(textbox) {
  if (textbox.value == 'Type Your Year Of Birth Here') { textbox.value='';}
}

function FillYOB(textbox) {
  if (textbox.value == '') { textbox.value='Type Your Year Of Birth Here';}
}
function ClearCity(textbox) {
  if (textbox.value == 'Type Your City Here') { textbox.value='';}
}

function FillCity(textbox) {
  if (textbox.value == '') { textbox.value='Type Your City Here';}
}
/* LIMIT THE YEAR OF BIRTH FIELD TO FOUR CHARACTERS */
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


/* IMPACT AND VOLUNTEERING FORM VALIDATION */
/* VALID EMAIL FOR FORM */
function validEmail(email) {
	invalidChars = ' !#$%^&*(){}[]+=~`?/:;,"'

	
	if (email == "") {
		return false;
	}
	for (i=0; i<invalidChars.length; i++) { //does it contain any invalid characters?
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1) {
			return false;
		}
	}
	atPos = email.indexOf("@",1)  		//there must be one "@" symbol
		if (atPos == -1) {
		return false;
	}
	if (email.indexOf("@",atPos+1) != -1) { //and only one "@"
		return false;
	}
	periodPos = email.indexOf(".",atPos+1)  //and at least one "." after the "@"
		if (periodPos == -1) {
		return false;
	}
	if (email.charAt(atPos+1) == ".") {	//is there a "." right after the "@"
		return false;
	}
	if (periodPos+3 > email.length) {  	//must be at least 2 characters after the "."
		return false;
	}
	return true;
}
function formValidation(form) {
	//var form_name = form.name.value.toLowerCase();
	//alert(form_name);	
	if (form.name.value.toLowerCase() == 'type your name here') {
		alert("A Valid Name Is Required.");
		form.name.focus();
		form.name.select();
		return false;
	}
	if (form.name.value == '') {
		alert("Please Fill In Your Name.");
		form.name.focus();
		form.name.select();
		return false;
	}
	//if (form.phone_number.value == '') {
		//alert("A Phone Number is required.");
		//form.phone_number.focus();
		//form.phone_number.select();
		//return false;
	//}
	if (!validEmail(form.email.value)) {
		alert("A valid E-mail Address is required.");
		form.email.focus();
		form.email.select();
		return false;
	}
		
//if we made it to here, everything's valid, so return true
return true
}

function form_jump_month(form) {
	var myindex = form.select_month.selectedIndex
	//if (myindex==0) return false;
	{
		parent.location=form.select_month.options[myindex].value;
		return true;
	}
}
/* IMPACT FORM RADIO BUTTON UNCHECK */
function clear_impact_radio_buttons() 
{
	getRadios = document.getElementsByTagName("input")
	for (x=0; x < getRadios.length; x++) 
	{
		if (getRadios[x].type == "radio" && getRadios[x].checked)
		//alert(getRadios[x].value)
		if (getRadios[x].value != 0)
		{
			getRadios[x].checked = false;
		}
	}
}
function clear_general_radio_buttons() 
{
	getRadios = document.getElementsByTagName("input")
	for (x=0; x < getRadios.length; x++) 
	{
		if (getRadios[x].type == "radio" && getRadios[x].checked)
		//alert(getRadios[x].value)
		if (getRadios[x].value == 0)
		{
			getRadios[x].checked = false;
		}
	}
}

/* LIST YOUR ORGANIZATION FORM */
/* EMPLOYMENT FORM VALIDATION*/
function ListOrganValidation(form) {
	if (form.organ_name.value == '') {
		alert("Please fill in your organization name.");
		form.organ_name.focus();
		form.organ_name.select();
		return false;
	}
	/*
	if (form.organ_url.value == '') {
		alert("Please fill in your organization url.");
		form.organ_url.focus();
		form.organ_url.select();
		return false;
	}
	*/
	if (form.contact_name.value == '') {
		alert("Please fill in your contact name.");
		form.contact_name.focus();
		form.contact_name.select();
		return false;
	}
		
	if (!validEmail(form.contact_email.value)) {
		alert("A valid E-mail Address is required.");
		form.contact_email.focus();
		form.contact_email.select();
		return false;
	}
	return true;
}

/* SUBMIT MONTH ON MAIN EVENTS CALENDAR PAGE */
function reloadForm()
{
	//if(document.current_month.onsubmit())
	//{
		document.form_event_calendar.submit();
	//}
}

/* MAIN EVENTS CALENDAR FORM */
function PublicCalendarValidation(form) {
	if (form.contact_name.value == '') {
		alert("Please fill in your contact name.");
		form.contact_name.focus();
		form.contact_name.select();
		return false;
	}
		
	if (!validEmail(form.contact_email.value)) {
		alert("A valid E-mail Address is required.");
		form.contact_email.focus();
		form.contact_email.select();
		return false;
	}
	if (form.organ_name.value == '') {
		alert("Please fill in your organization name.");
		form.organ_name.focus();
		form.organ_name.select();
		return false;
	}
	
	if (form.event_title.value == '') {
		alert("Please fill in your event title.");
		form.event_title.focus();
		form.event_title.select();
		return false;
	}
	
	return true;
}



/* MY ISRAEL FORM VALIDATION */
function formMyIsraelValidation(form) {
	//var form_name = form.name.value.toLowerCase();
	//alert(form_name);	
	
	if (form.first_name.value == '') {
		alert("Please Fill In Your First Name.");
		form.first_name.focus();
		form.first_name.select();
		return false;
	}
	if (form.last_name.value == '') {
		alert("Please Fill In Your Last Name.");
		form.last_name.focus();
		form.last_name.select();
		return false;
	}
	//if (form.phone_number.value == '') {
		//alert("A Phone Number is required.");
		//form.phone_number.focus();
		//form.phone_number.select();
		//return false;
	//}
	if (!validEmail(form.email.value)) {
		alert("A valid E-mail Address is required.");
		form.email.focus();
		form.email.select();
		return false;
	}
	

		
//if we made it to here, everything's valid, so return true
return true
}

/* SUBMIT CONTACT FORM */
function submit_contact_form()
{
	if(document.form_survey.onsubmit())
	{
	document.form_survey.submit();
	}
}

function Reset_Me() {
if (confirm("Are you sure you want to clear form?")) {
document.form_survey.reset();
}
}

/* START MAIN EVENTS CALENDAR */
function myIsraelPhoto(intBlock, intMember, intPhoto)
{
	// display the loading image
	document.getElementById("myIsraelBlock" + intBlock).innerHTML = "<div align='center' style='margin: 0px; padding-top: 80px; width: 366px;'><img src='images/ajax_loading.gif' /><br>Loading...</div>";
	DWREngine._execute("function_my_israel_photo.cfm", null, 'readMyIsraelPhotoFunction', intBlock, intMember, intPhoto, getMyIsraelPhoto);
}
function getMyIsraelPhoto(result)
{
	var intBlockID   = result.charAt(3);
	document.getElementById("myIsraelBlock" + intBlockID).innerHTML = result;
}
/* END MAIN EVENTS CALENDAR */
