function form_validate(formName) {
  var ret_val=true;

  var clist=$(".req");

  for (var i=0;i<clist.length;i++) {
    var f=clist.eq(i);
    if (f.attr('value')=="" ||
        (f.attr('type')=="checkbox" && !f.attr('checked'))) {

      f.addClass("redselected");
      /*      $("#formmessage").text("You must fill out all required fields"); */
      ret_val=false;
    } else {
      f.removeClass("redselected");
    }
  }

  if (!ret_val) {
    alert("You must fill out all required fields");
    return ret_val;
  }
  ajaxFunction('validateCode', formName, "", "");
  return ret_val;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



function activeDate(divID) {
    unactiveDate();
	if ((document.getElementById('divDate'+divID))&&((document.getElementById('divDate'+divID).className != 'dateListActive')))
	{
      document.getElementById('divDate'+divID).className="dateListActive2";	
	}
}

function unactiveDate() {
    for (var i=0; i<11; i++)
	{
	  if (document.getElementById('divDate'+i).className == 'dateListActive')
	    continue;
	  document.getElementById('divDate'+i).className = "dateList";
		
	}
}

function activeCalendarMonth(divID, numEvents) {
    unactiveCalendarMonth(numEvents);
    document.getElementById('calendarMonthDiv'+divID).className="calendarMonthEvent2";	
}

function unactiveCalendarMonth(numEvents) {
    for (var i=1; i<=numEvents; i++)
	{
	  document.getElementById('calendarMonthDiv'+i).className = "calendarMonthEvent1";
		
	}
}

function activeEventType(divID) {
    unactiveEventType();
	if ((document.getElementById('divEventType'+divID))&&((document.getElementById('divEventType'+divID).className != 'eventCategoryActive')))
	{
      document.getElementById('divEventType'+divID).className="eventCategoryActive2";	
	}
}

function unactiveEventType(numEvents) {
    for (var i=0; i<numEvents; i++)
	{
	  if (document.getElementById('divEventType'+i).className == 'eventCategoryActive')
	    continue;
	  document.getElementById('divEventType'+i).className = "eventCategory";
		
	}
}

function activeCalendar(divID, numEvents) {
    unactiveCalendar(numEvents);
    document.getElementById('calendarDiv'+divID).className="eventBoxActive";	
}

function unactiveCalendar(numEvents) {
    for (var i=1; i<=numEvents; i++)
	{
	  document.getElementById('calendarDiv'+i).className = "eventBox";
		
	}
}

function activeIfpod(divID, numIfpod) {
    unactiveIfpod(numIfpod);
	if ((document.getElementById('ifpodDiv'+divID))&&((document.getElementById('ifpodDiv'+divID).className != 'ifpodBoxActive')))
	{
    document.getElementById('ifpodDiv'+divID).className="ifpodBoxActive2";	
	}	
}

function unactiveIfpod(numIfpod) {
    for (var i=1; i<=numIfpod; i++)
	{
	  if (document.getElementById('ifpodDiv'+i).className == 'ifpodBoxActive')
	    continue;		
	  document.getElementById('ifpodDiv'+i).className = "ifpodBox";
		
	}
}

function _loaded(){
	// put the clients latest choices in the selection menu (data stored in the masthead frame)...
	if (parent.result.document.location.href == '<?=$global_baseurl?>cinema/blank.php'){
		document.selectform.sortselect.selectedIndex = parent.parent.masthead.document.performance_dataform.sortselect.value;
		document.selectform.personselect.selectedIndex = parent.parent.masthead.document.performance_dataform.personselect.value;
		document.selectform.lengthselect.selectedIndex = parent.parent.masthead.document.performance_dataform.lengthselect.value;
		document.selectform.yearselect.selectedIndex = parent.parent.masthead.document.performance_dataform.yearselect.value;
		document.selectform.numberselect.selectedIndex = parent.parent.masthead.document.performance_dataform.numberselect.value;
		document.selectform.formatselect.selectedIndex = parent.parent.masthead.document.performance_dataform.formatselect.value;
		document.selectform.submit();
	}  // end if.
}

function submitselect(page_reset){
	// upon submitting the form, save the client's selection choices in the masthead for later...
	if (page_reset != 'keeppage') document.selectform.page.value = 1;    // reset the page to 1, this is a new search
/*	parent.parent.masthead.document.performance_dataform.page.value = document.selectform.page.value;
	parent.parent.masthead.document.performance_dataform.sortselect.value = document.selectform.sortselect.selectedIndex;
	parent.parent.masthead.document.performance_dataform.personselect.value = document.selectform.personselect.selectedIndex;
	parent.parent.masthead.document.performance_dataform.lengthselect.value = document.selectform.lengthselect.selectedIndex;
	parent.parent.masthead.document.performance_dataform.yearselect.value = document.selectform.yearselect.selectedIndex;
	parent.parent.masthead.document.performance_dataform.numberselect.value = document.selectform.numberselect.selectedIndex;
	parent.parent.masthead.document.performance_dataform.formatselect.value = document.selectform.formatselect.selectedIndex;*/
	document.selectform.submit();
}

function ajaxFunction(type, formName, offset, cid){

	var ajaxRequest = null;  // The variable that makes Ajax possible!

   try {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
   } catch (e) {

   try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("This feature was disabled by your browser.");
				return false;
			}
		}
	}
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
//    ajaxRequest.setRequestHeader("Content-Type","application/x-javascript; charset:ISO-8859-1");			
		if(ajaxRequest.readyState==4 || ajaxRequest.readyState=="complete"){
          if (type == 'validateCode')
		  {
//            alert("result"+ajaxRequest.responseText);
			if (ajaxRequest.responseText == 'pass')
			{
		      if (formName)
                document.forms[formName].submit();			  
			  else
                document.forms["theform"].submit();
			}
			else  
              alert("Validation code must match.");			
		 }
      }
	}

    if (type == 'validateCode'){
        var queryString = "?code=" + document.getElementById('code').value; 		  
        ajaxRequest.open("GET", "/securimage/validateCode.php" + queryString, true);
	    ajaxRequest.send(null);		 	  
	}	
		
}

