var remail=/^([_&a-zA-Z0-9-]+(\.[_&a-zA-Z0-9-]+)*@[&a-zA-Z0-9-]+\.+[&a-zA-Z0-9-]+)/;
var gloDivId;
function checkEmail(fieldvalue) {
  if(remail.test(fieldvalue))
      return false;
    else
      return true;
}

function createXmlObject() {
  if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
  } else if(window.ActiveXObject) {
    xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
  }
}

function trim(str) {
  return str.replace(/^\s*|\s*$/g,"");
}


function getDtnosel(nm,dtm) {
  //chkTheatreschDate();
  document.getElementById('test').style.display = 'block';
  document.getElementById('bookinginfo').style.display = 'none';
  var mdatech = document.getElementById('seldateno').value;
  document.getElementById('seldatshow'+nm+1).style.display = 'block';
  document.getElementById('seldatshow'+nm+0).style.display = 'none';
  document.getElementById('seldatshow'+mdatech+0).style.display = 'block';
  document.getElementById('seldatshow'+mdatech+1).style.display = 'none';
  document.getElementById('seldateno').value = nm;
  document.getElementById('mdate').value = dtm;
  document.getElementById('dddate').innerHTML = dtm;
  document.getElementById('default').style.display ='none';
  document.getElementById('tid').value = "";
  document.getElementById('mclass').value = "";
  document.getElementById('mclass').options.length = "1";
  document.getElementById('fid').options.length = "1";
  document.getElementById('fid').value = "";
  document.getElementById('mschedule').options.length = "1";
  document.getElementById('mschedule').value = "";
  
  return false;
}

function getValnosel(nmvl) {
  for(var i=1; i<=10; i++) {
    if(nmvl==i) {
	  document.getElementById('selnoseats1'+i).style.display = 'block';
	  document.getElementById('selnoseats0'+i).style.display = 'none';
	} else {
	  document.getElementById('selnoseats0'+i).style.display = 'block';
      document.getElementById('selnoseats1'+i).style.display = 'none';
	}
  }
  document.getElementById('mseat').value = nmvl;
  document.getElementById('sseat').innerHTML = nmvl;
  var dtm = document.getElementById('mdate').value;
  document.getElementById('dddate').innerHTML = dtm;
  document.getElementById('test').style.display = 'block';
  document.getElementById('default').style.display ='none';
  document.getElementById('totaldesign').style.display = 'block';
  var f=  tes();	 
  document.getElementById("showtotal").innerHTML = f ;
  document.getElementById('default').style.display ='none';
  return false;
}

function chkDate() {
  var vl = document.getElementById('mdate').value;
  var ctid = document.getElementById('tid').value;
  var cfid = document.getElementById('fid').value;
  var cclass = document.getElementById('mclass').value;
  createXmlObject();
  var ran_unrounded=Math.random()*100000;
  var ran_number=Math.floor(ran_unrounded); 
  var str = "action=showBookingChk&cdate="+vl+"&ctid="+ctid+"&cfid="+cfid+"&cclass="+cclass+"&r="+ran_number;
  var url = "bookingprocess.php";
  xmlhttp.open("POST", url, true);  
  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  xmlhttp.send(str);
  xmlhttp.onreadystatechange = detailsDateChk
}

function detailsDateChk() {
  if (xmlhttp.readyState == 4) {
    var response = xmlhttp.responseText;
    if (response != "") {
        document.getElementById('mshowschedule').innerHTML = response;
        return false;
    }
  }
}

function chkTheatreschDate() {
  //alert("hi");
  var cdate = document.getElementById('mdate').value;
  var ctid = document.getElementById('tid').value;
  var cfid = document.getElementById('fid').value;
  var cclass = document.getElementById('mclass').value;
  var movie=cfid;
 // alert(ctid);
  if(trim(ctid)!="" && trim(cfid)!="" && trim(cclass)!="") {
	  createXmlObject();
	  var ran_unrounded=Math.random()*100000;
	  var ran_number=Math.floor(ran_unrounded); 
	  var str = "action=showBookFullChk&cdate="+cdate+"&ctid="+ctid+"&cfid="+cfid+"&cclass="+cclass+"&r="+ran_number+"&film="+movie;
	  var url = "bookingprocess.php";
	  xmlhttp.open("POST", url, true);  
	  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	  xmlhttp.send(str);
	  xmlhttp.onreadystatechange = detailsInDateTheatresch
  }
}

function changeclass(val2) {

  var clas=val2;
  createXmlObject();
  var ran_unrounded=Math.random()*100000;
  var ran_number=Math.floor(ran_unrounded); 
  var str = "action=showchangeclass&clas1="+clas;
  var url = "bookingprocess.php";
  xmlhttp.open("POST", url, true);  
  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  xmlhttp.send(str);
  xmlhttp.onreadystatechange = detailsDistheatreinfo1
}
function detailsInDateTheatresch() {
  if (xmlhttp.readyState == 4) {
    var response = xmlhttp.responseText;
    if (response != "") {
		var mySplitResult = response.split("##");
        document.getElementById('mhmeshowschedule').innerHTML =  mySplitResult[0];;
		document.getElementById('filmlist').innerHTML = mySplitResult[1];
		document.getElementById('default').style.display ='none';
		changeclass(mySplitResult[2]);
        return false;
    }
  }
}

function chkDistheatreinfo(val) {
 document.getElementById('bookinginfo').style.display = 'block';
document.getElementById('mschedule').options.length = "1";
  var ttid = document.bookinghmfilm1.tid.value;
  var tmdate = document.bookinghmfilm1.mdate.value;
  var theat_id=val;
  createXmlObject();
  var ran_unrounded=Math.random()*100000;
  var ran_number=Math.floor(ran_unrounded); 
  var str = "action=showTheatreRelInfo&ttid="+ttid+"&tmdate="+tmdate+"&r="+ran_number+"&thea_id="+theat_id;
  var url = "bookingprocess.php";
  xmlhttp.open("POST", url, true);  
  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  xmlhttp.send(str);
  xmlhttp.onreadystatechange = detailsDistheatreinfo;
   
}

function chkClassinfo(val) {
 document.getElementById('bookinginfo').style.display = 'block';
document.getElementById('mschedule').options.length = "1";
  var ttid = document.bookinghmfilm1.tid.value;
  var tmdate = document.bookinghmfilm1.mdate.value;
 // alert(ttid);
  var theat_id=val;
  createXmlObject();
  var ran_unrounded=Math.random()*100000;
  var ran_number=Math.floor(ran_unrounded); 
  var str = "action=showClassInfo&ttid="+ttid+"&tmdate="+tmdate+"&r="+ran_number+"&thea_id="+theat_id;
  var url = "bookingprocess.php";
  xmlhttp.open("POST", url, true);  
  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  xmlhttp.send(str);
  xmlhttp.onreadystatechange = detailsDistheatreinfo;
   
}

function detailsDistheatreinfo() {
  if (xmlhttp.readyState == 4) {
    var response = xmlhttp.responseText;
	if (response != "") {
        var mySplitResult = response.split("##");
        document.getElementById('mhmeshowmovie').innerHTML = mySplitResult[0];
		document.getElementById('mhmeshowclass').innerHTML = mySplitResult[1];
		document.getElementById('bookinginfo').innerHTML = mySplitResult[2];
		var dtm = document.getElementById('mdate').value;
	    document.getElementById('dddate').innerHTML = dtm;
        document.getElementById('test').style.display = 'block';
        document.getElementById('default').style.display ='none';
		return false;
    }
  }
}



   function tes() {

   var tot = document.getElementById("test11").value * document.getElementById("mseat").value;
    document.getElementById("t").value =tot;
	return tot;
   }


function detailsDistheatreinfo1() {

  if (xmlhttp.readyState == 4) {
    var response = xmlhttp.responseText;
	//alert(response);

	if (response != "") {
		var mySplitResult = response.split("##");
			//alert(mySplitResult[2]);
        document.getElementById('showclasss').innerHTML =mySplitResult[0] ;
		 document.getElementById("test11").value =mySplitResult[2] ;
		 var f = tes();
		<!-- alert(f);-->
		 document.getElementById("showtotal").innerHTML =f ;
		 document.getElementById('totaldesign').style.display = 'block';
		   document.getElementById('default').style.display ='none';
	 
        return false;
    }
  }
}

function chkbookingFilm() {
  var mclass = window.document.bookingfilm1.mclass.value;
  var mschedule = window.document.bookingfilm1.mschedule.value;
  if(trim(mclass)=="") {
	  alert("Please Choose the Class");
	  window.document.bookingfilm1.mclass.focus();
	  return false;
  } else if(trim(mschedule)=="") {
	  alert("Please Choose the Schedule");
	  window.document.bookingfilm1.mschedule.focus();
	  return false;
  }
  return true;
}

function OptPckDt() {
  window.document.bookingfilm1.mclass.value="";
  window.document.bookingfilm1.mschedule.value="";
}

function chkbookinghmeFilm() {
  var mdate = window.document.bookinghmfilm1.mdate.value;
  var mseat = window.document.bookinghmfilm1.mseat.value;
  var tid = window.document.bookinghmfilm1.tid.value;
  var fid = window.document.bookinghmfilm1.fid.value;  
  var mclass = window.document.bookinghmfilm1.mclass.value;
  var mschedule = window.document.bookinghmfilm1.mschedule.value;
  if(trim(mdate)=="") {
	  alert("Please Choose the Date");
	  return false;
  }  else if(trim(mseat)=="0") {
	  alert("Please Select No of Seats");
	  return false;
  }  else if(trim(tid)=="") {
	  alert("Theatre Name Not Found");
	  window.document.bookinghmfilm1.tid.focus();
	  return false;
  } else if(trim(fid)=="") {
	  alert("Film Name Not Found");
	  window.document.bookinghmfilm1.fid.focus();
	  return false;
  }  else if(trim(mclass)=="") {
	  alert("Please Choose the Class");
	  window.document.bookinghmfilm1.mclass.focus();
	  return false;
  }  else if(trim(mschedule)=="") {
	  alert("Please Choose the Schedule");
	  window.document.bookinghmfilm1.mschedule.focus();
	  return false;
  }
  return true;
}

/*
function chkbookingFilm() {
  var tid = window.document.bookingfilm1.tid.value;
  var fid = window.document.bookingfilm1.fid.value;
  var mdate = window.document.bookingfilm1.mdate.value;
  var mclass = window.document.bookingfilm1.mclass.value;
  var mschedule = window.document.bookingfilm1.mschedule.value;
  var mseat = window.document.bookingfilm1.mseat.value;
  if(trim(tid)=="") {
	  alert("Theatre Name Not Found");
	  return false;
  } else if(trim(fid)=="") {
	  alert("Film Name Not Found");
	  return false;
  }  else if(trim(mdate)=="") {
	  alert("Please Choose the Date");
	  window.document.bookingfilm1.mdate.focus();
	  return false;
  }  else if(trim(mclass)=="") {
	  alert("Please Choose the Class");
	  window.document.bookingfilm1.mclass.focus();
	  return false;
  }  else if(trim(mschedule)=="") {
	  alert("Please Choose the Schedule");
	  window.document.bookingfilm1.mschedule.focus();
	  return false;
  }  else if(trim(mseat)=="") {
	  alert("Please Select No of Seats");
	  window.document.bookingfilm1.mseat.focus();
	  return false;
  }
  return true;
}
*/

function chosest(rno) {
  // alert(rno);
  var tgst = document.getElementById("1"+rno).value;
 //alert(tgst);
  var mnoseat = document.getElementById("mnoseat").value;
  var mrowseats = document.getElementById("mrowseats").value;
  var seatcnt = mrowseats.split(",");
  var seatleng = seatcnt.length;
  //alert(mrowseats);
  if(mrowseats!="") {
    seatleng = seatleng+1;
  }
  // alert(seatleng+ " " + mnoseat+ " "+seatcnt);

  //alert(seatleng);
  if(tgst=='0') {
	if(seatleng <= mnoseat) {
		document.getElementById(rno).style.backgroundColor = "#FF5A00";
		document.getElementById(rno).style.color = "#FFFFFF";
		document.getElementById("1"+rno).value = '1';
		if(mrowseats=="") {
		  rno=rno.toUpperCase();
		  document.chooseseat1.mrowseats.value = "";
		  //document.getElementById("mrowseats").value = rno+"-"+sno;
                  document.chooseseat1.mrowseats.value = rno;
		} else {
		  rno=rno.toUpperCase();
		   //alert(rno);
		  mrowseats= document.chooseseat1.mrowseats.value ;
		  //document.getElementById("mrowseats").value = document.getElementById("mrowseats").value+","+rno+"-"+sno;
          seat = rno;
          document.chooseseat1.mrowseats.value  =  mrowseats+","+seat;
		}
	}
  } else if(tgst=='1') {
	var mrowchgseats = mrowseats.replace(","+rno,"");
	var mrowchgseats1 = mrowchgseats.replace(rno+",","");
	var mrowchgseats2 = mrowchgseats1.replace(rno,"");
	// alert(srch+" - "+mrowchgseats);
	if(mrowchgseats2=="") { mrowchgseats2 = "";}
	document.getElementById(rno).style.backgroundColor = "#39892F";
	document.getElementById(rno).style.color = "#FFFFFF";
	document.getElementById("1"+rno).value = '0';
	document.getElementById("mrowseats").value = mrowchgseats2;
  }
}

function checkfrmseat() {
  var mnoseat = document.getElementById("mnoseat").value;
  var mrowseats = document.getElementById("mrowseats").value;
  var seatcnt = mrowseats.split(",");
  if(seatcnt[0]=="-")
  {
   alert("Number of Seat(s) is Mismatch");
   return false;
  }
  else
  {
  var seatleng = seatcnt.length;
  if(mrowseats!="-") {
    seatleng = seatleng+1;
	if(seatleng <= mnoseat) {
	  alert("Number of Seat(s) is Mismatch");
	  return false;
	}
  } else {
    alert("Please Select Your Seat(s)");
	return false;
  }
  }
}

function showtime1(ttime) {
      var ttime1=ttime;
      createXmlObject();
	  var ran_unrounded=Math.random()*100000;
	  var ran_number=Math.floor(ran_unrounded); 
	  var str = "action=showtimme&ttt="+ttime1;
	  var url = "bookingprocess.php";
	  xmlhttp.open("POST", url, true);  
	  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	  xmlhttp.send(str);
	  xmlhttp.onreadystatechange = detailsInDateTheatresch11

}

function detailsInDateTheatresch11() {
  if (xmlhttp.readyState == 4) {
    var response = xmlhttp.responseText;
    if (response != "") {
        document.getElementById('showwtime').innerHTML =  response;
        return false;
    }
  }
}

/*
function toggleBgColor( elem ) {
    var style2 = elem.style;
    style2.backgroundColor = style2.backgroundColor? "#39892F":"#FF5A00";
}
*/