function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=200,left = 490,top = 412');");
}

function changeDiv1(the_div,the_change){
  var the_style = getStyleObject(the_div);
  if (the_style != false)
  {
    the_style.display = the_change;
  }
}


function toggleCheck(the_div,the_check){
  var dd = findD(the_div);
  if (dd) {
	  if (findD(the_check).checked == true)  {
		dd.style.display = 'block';
	  } else {
		dd.style.display = 'none';
	  }
  }
}


function hideAll1(){
  changeDiv1("rough1","none");
}

function hideAll2(){
  changeDiv1("dir2","none");
  changeDiv1("dir1","none");
}

function hideAll3() {
  changeDiv1("prod2","none");
  changeDiv1("prod1","none");
}

function hideAll4(){
  changeDiv1("add2","none");
  changeDiv1("add1","none");
}

function hideAll5(){
  changeDiv1("desc2","none");
  changeDiv1("desc1","none");
}


function getStyleObject(objectId) {
  if (document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
    return document.all(objectId).style;
  } else {
    return false;
  }
}

function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function toCount(entrance,exit,text,characters) {
  var entranceObj=getObject(entrance);
  var exitObj=getObject(exit);
  var length=characters - entranceObj.value.length;
  if(length <= 0) {
    length=0;
    text='<span class="disable"> '+text+' </span>';
    entranceObj.value=entranceObj.value.substr(0,characters);
  }
  exitObj.innerHTML = text.replace("{CHAR}",length);
}

function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }

  var ids = new Array('firstname', 'lastname', 'streetaddress', 'city', 'state', 'zippostal', 'country', 'phone', 'email', 'website', 'filmtitle', 'director', 'status1', 'logline', 'pinformation', 'statement', 'filmstatus', 'filefield', 'distribution', 'interactive', 'outreach', 'totalbudget', 'secured', 'fundingsources', 'fundstrategy', 'budgetfilefield', 'sample1title', 'sample1length', 'sample2title', 'sample2length', 'sample3title',  'sample3length');
  var values = new Array('', '');

  function populateArrays() {
    // assign the default values to the items in the values array
    for (var i = 0; i < ids.length; i++)
    {
      var elem = document.getElementById(ids[i]);
      if (elem)
        if (elem.type == 'checkbox' || elem.type == 'radio')
          values[i] = elem.checked;
        else
          values[i] = elem.value;
    }
  }
  
  var needToConfirm = true;

  //window.onbeforeunload = confirmExit;
  function confirmExit() {
    if (needToConfirm)   {
      // check to see if any changes to the data entry fields have been made
      for (var i = 0; i < values.length; i++)
      {
        var elem = document.getElementById(ids[i]);
        if (elem)
          if ((elem.type == 'checkbox' || elem.type == 'radio')
                  && values[i] != elem.checked)
            return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Submit Application button, your changes will be lost.  Are you sure you want to exit this page?";
          else if (!(elem.type == 'checkbox' || elem.type == 'radio') &&
                  elem.value != values[i])
            return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save Application button, your changes will be lost.  Are you sure you want to exit this page?";
      }

      // no changes - return nothing
    }
  }



function  drwTrnspFLSHID(which, vars, color, w, h, id, div) {
	var vdiv = document.getElementById(div);
	var Tag = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + w + '" height="' + h + '" id="' + id + '" align="middle">'
	+ '<param name="allowScriptAccess" value="sameDomain" />'
	+ '<param name="flashvars" value="' + vars + '"></param>'
	+ '<param name="movie" value="' + which + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="' + color + '" /><embed src="' + which + '" quality="high" wmode="transparent" bgcolor="' + color + '" width="' + w + '" height="' + h + '" name="' + id + '" align="middle" allowScriptAccess="sameDomain"  flashvars="' + vars + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
	+ '</object>';
	
	vdiv.innerHTML = Tag;
	//document.write(Tag);
}


function goPanel(what) {

	var val = 'nothing';
	for( i = 0; i < document.forms['apply'].applying.length; i++ ){
		if( document.forms['apply'].applying[i].checked == true ) {
			val = document.forms['apply'].applying[i].value;
		}
	}
	
	if (what != 'new') {

		var lodging = '';
		for( i = 0; i < document.forms['apply'].lodging.length; i++ ){
			if( document.forms['apply'].lodging[i].checked == true ) {
				lodging = document.forms['apply'].lodging[i].value;
			}
		}
		
		var checkStr = "";
		if (document.forms['apply'].firstname.value == "") {
			checkStr += "Please enter your first name.\n";
		}
		if (document.forms['apply'].lastname.value == "") {
			checkStr += "Please enter your last name.\n";
		}
		if (document.forms['apply'].streetaddress.value == "") {
			checkStr += "Please enter your street address.\n";
		}
		if (document.forms['apply'].city2.value == "") {
			checkStr += "Please enter your city.\n";
		}
		
		if (document.forms['apply'].country2[document.forms['apply'].country2.selectedIndex].value == 1) {
			checkStr += "Please select your country.\n";
		}
		if (document.forms['apply'].zippostal.value == "") {
			checkStr += "Please enter your postal code.\n";
		}
		if (document.forms['apply'].phone1.value == "") {
			checkStr += "Please enter your best Daytime phone.\n";
		}
		if (document.forms['apply'].phone2.value == "") {
			checkStr += "Please enter another phone number.\n";
		}
		if (document.forms['apply'].email.value == "") {
			checkStr += "Please enter your email address.\n";
		}
		if (document.forms['apply'].emergcontact.value == "") {
			checkStr += "Please enter an emergency contact name.\n";
		}
		if (document.forms['apply'].emergnumber.value == "") {
			checkStr += "Please enter an emergency number.\n";
		}
		
		if (checkStr != "") {
			alert(checkStr);
		}  else {
			if (val == 'Full Time') {
				if (lodging == '') {
					alert('Do you have your own lodging in Utah during the Festival?');
				} else {

					changeDiv1('contactpanel','none');
					changeDiv1('signuppanel','block');
					changeDiv1('fulltimedescription','block');
					changeDiv1('departmentpanel','block');
					
					changeDiv1('filmindustrytable','block');
					
					changeDiv1('managementtable','block');
					changeDiv1('managementdetails','none');
					changeDiv1('finalpanel','block');
					
					scroll(0,0);
				}
			} else if (val == 'Sign Up') {
				if (lodging == '') {
					alert('Do you have your own lodging in Utah during the Festival?');
				} else {

					changeDiv1('contactpanel','none');
					changeDiv1('signuppanel','block');
					changeDiv1('signupdescription','block');
					changeDiv1('departmentpanel','block');
					changeDiv1('filmindustrytable','block');
					changeDiv1('managementtable','none');
					changeDiv1('managementdetails','none');
					changeDiv1('finalpanel','block');
					scroll(0,0);
				}
			} else if (val == 'same') {
				if (lodging == '') {
					alert('Do you have your own lodging in Utah during the Festival?');
				} else {
					document.forms['apply'].submit();
				}
			} else if (val == 'Next Year') {
				document.forms['apply'].submit();
			} else if (val == 'Remove Me') {
				document.forms['apply'].submit();
			} else {
				alert ('Please check the program(s) for which you are applying.') ;
			}
		}
		
	} else if (calcBday()) {
	

		if ((document.forms['apply'].volbefore[0].checked)  || (document.forms['apply'].volbefore[1].checked)) {
		if (val == 'Full Time') {

			changeDiv1('firstpanel','none');
			changeDiv1('contactpanel','block');

			//changeDiv1('departmentpanel','block');

			changeDiv1('newfulltime','block');

			changeDiv1('managementtable','block');
			changeDiv1('managementdetails','none');

			//changeDiv1('finalpanel','block');

			changeDiv1('lodgingcouch','block');
			changeDiv1('lodginginfo','block');
			scroll(0,0);

		} else if (val == 'Sign Up') {
			changeDiv1('firstpanel','none');
			changeDiv1('contactpanel','block');

			//changeDiv1('departmentpanel','block');

			changeDiv1('newsignup','block');

			changeDiv1('managementtable','none');
			changeDiv1('managementdetails','none');
			scroll(0,0);
			//changeDiv1('finalpanel','block');

		} else {
			alert ('Please check the program(s) for which you are applying.') ;
		}
		} else {
			alert ('Have you volunteered in the past for the Sundance Institute?.') ;

		}
		

	} else {
	
	
		//alert ('Please complete the form elements describing your day or birth.') ;
		alert ('We\'re sorry, it appears you will not be 21 by January 19, 2010. Volunteers must be 21 years of age or older on their first day of volunteering to participate. You are unable to submit an application for the 2010 Festival, but we encourage you to fill out an application when you will be 21 for the Festival!');
		
	}
	
	
}

function calcBday() {

	/*
	This should calculate if this date falls AFTER 1/19/1989, then the following message should appear and the person should not be able to go to the application page:

	We're sorry, it appears you will not be 21 by January 19, 2010. Volunteers must be 21 years of age or older on their first day of volunteering to participate. You are unable to submit an application for the 2010 Festival, but we encourage you to fill out an application when you will be 21 for the Festival!

	*/
	//document.forms['apply'].bMonth2[document.forms['apply'].bMonth2.selectedIndex].value > 0
	//bYear2
	if (document.forms['apply'].bYear2[document.forms['apply'].bYear2.selectedIndex].value == "--") {
		return false;
	}

	if (document.forms['apply'].bDay2[document.forms['apply'].bDay2.selectedIndex].value == "--") {
		return false;
	}
	
	if (document.forms['apply'].bMonth2[document.forms['apply'].bMonth2.selectedIndex].value == "--") {
		return false;
	}
	
	if (document.forms['apply'].bYear2[document.forms['apply'].bYear2.selectedIndex].value > 1989) {
		return false;
	} else if (document.forms['apply'].bYear2[document.forms['apply'].bYear2.selectedIndex].value == 1989) {
		if (document.forms['apply'].bMonth2[document.forms['apply'].bMonth2.selectedIndex].value > 1) {
			return false;
		} else {
			if (document.forms['apply'].bDay2[document.forms['apply'].bDay2.selectedIndex].value > 19) {
				return false;
			}
		}
	}

	return true;
}



function findD (d)  {
	var it = document.getElementById(d);
	if ((it != 'undefined') && it) {
	
	return it;
	} else {
		return null;
	}
}


function show_propss(obj, objName) {
	var result = "";
	if ((typeof (obj) != "undefined") && obj) {
		for (var i in obj) {
			//result += objName + "." + i + "::";
			if ((typeof (obj[i]) != "undefined") && obj[i]) {
				if (typeof (obj[i]) == "object") {
					//show_propss(obj[i], "\t" + i)
					result += objName + "." + i + " = object." + obj[i] + "\n";
				} else {
					//alert(typeof(obj[i]));
					result += objName + "." + i + " = " + obj[i] + "\n";
				}
			}
		}
	}
	return result;
}



function confRedirect(d, s) {
	
	findD(d).style.display = 'none';
	
    if (confirm("Returning volunteers should use the Alumni Form, would you like to be redirected to the Alumni Form?")) {
    	document.location = "/Applications/volunteer/login.asp";
    	
    } else {
    //alternate
  
    }
}
