var xmlHttp;
function showChooser(cnt,obj, inputId, divId, start, end, format, isTimeChooser) {
	
	//alert(document.getElementById("cnts").value);
	//alert(cnt);
    if (document.getElementById) {
        var input = document.getElementById(inputId);
        var div = document.getElementById(divId);
        if (input !== undefined && div !== undefined) {
            if (input.DateChooser === undefined) {
                input.DateChooser = new DateChooser(input, div, start, end, format, isTimeChooser,cnt);
            }
            input.DateChooser.setDate(Date.parseDate(input.value, format));
            if (input.DateChooser.isVisible()) {
                input.DateChooser.hide();
            }
            else {
                input.DateChooser.show();
            }
        }
    }
}





 



function dateChooserSetDate(inputId, value) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
    var input = document.getElementById(inputId);
  
    // var cnt=document.getElementById('cnt').value;
    
    if (input !== undefined && input.DateChooser !== undefined) {
        input.DateChooser.setDate(Date.parseDate(value, input.DateChooser._format));
        if (input.DateChooser.isTimeChooser()) {
            var theForm = input.form;
            var prefix = input.DateChooser._prefix;
            input.DateChooser.setTime(
                parseInt(theForm.elements[prefix + 'hour'].options[
                    theForm.elements[prefix + 'hour'].selectedIndex].value)
                    + parseInt(theForm.elements[prefix + 'ampm'].options[
                    theForm.elements[prefix + 'ampm'].selectedIndex].value),
                parseInt(theForm.elements[prefix + 'min'].options[
                    theForm.elements[prefix + 'min'].selectedIndex].value));
        }
        input.value = input.DateChooser.getValue(); 
        var currentTime = new Date();
        var month = currentTime.getMonth() + 1;
		var day = currentTime.getDate();
		var year = currentTime.getFullYear();
		if(month < '10')
        month="0" + month;
        if(day < '10')
        day="0" + day;
		var todate=year + "-" + month + "-" + day;
		//alert(input.value);alert(todate);
       // alert(input.value < 'todate');
        //if(input.value < 'todate'){
        	
        	//alert("enter valid date");
       // }
       
      // else{
        var xx=input.value 
        var flags1=xx.split("-");
        var year=flags1[0];
        var mon=flags1[1];
        var date=flags1[2];
        
        
        input.value = date + "-" + mon + "-" + year;
        
        input.DateChooser.hide();
        var dates=xx;
        var cnts=input.DateChooser.cont();
        // var restid=document.getElementById('rids').value;
    
       //alert(cnts);
 
            var url_title="holiday_check.php";
var url_title=url_title + "?id=" + dates + "&count1=" + cnts;

xmlHttp.open("GET",url_title,true)
xmlHttp.onreadystatechange=dateChange;


xmlHttp.send(null) 
     //  }
    } 
}


function dateChange(){
	var x=xmlHttp.responseText;
	//document.getElementById("docs1").innerHTML=x;

	var flags=x.split("@");
	var hol=flags[0];
	
	var des=flags[1];
	var date=flags[2];
	var count=flags[3];
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(hol==1){
		//alert("Holiday"); 
		document.getElementById("date_event1"+count).value="";
		alert("Holiday" + "!!" + des); 
		//document.getElementById("docs"+count).innerHTML="<font color='red'>Holiday" + "!!" + des + "</font>";
		}
		if(hol==3){
		//alert("Holiday"); 
		document.getElementById("date_event1"+count).value="";
		alert("Enter a Valid date greater than todate");
		//document.getElementById("docs"+count).innerHTML="<font color='red'>Enter a Valid date greater than todate</font>";
		}
			
			
	}

}


function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
} 








function dateChooserDateChange(theForm, prefix) {
    var input = document.getElementById(
        theForm.elements[prefix + 'inputId'].value);
    var newDate = new Date(
        theForm.elements[prefix + 'year'].options[
            theForm.elements[prefix + 'year'].selectedIndex].value,
        theForm.elements[prefix + 'month'].options[
            theForm.elements[prefix + 'month'].selectedIndex].value,
        1);
   
    newDate.setDate(Math.max(1, Math.min(newDate.getDaysInMonth(),
                    input.DateChooser._date.getDate())));
    input.DateChooser.setDate(newDate);
    if (input.DateChooser.isTimeChooser()) {
        input.DateChooser.setTime(
            parseInt(theForm.elements[prefix + 'hour'].options[
                theForm.elements[prefix + 'hour'].selectedIndex].value)
                + parseInt(theForm.elements[prefix + 'ampm'].options[
                theForm.elements[prefix + 'ampm'].selectedIndex].value),
            parseInt(theForm.elements[prefix + 'min'].options[
                theForm.elements[prefix + 'min'].selectedIndex].value));
    }
    input.DateChooser.show();
    
}

function getAbsolutePosition(obj) {
    var result = [0, 0];
    while (obj != null) {
        result[0] += obj.offsetTop;
        result[1] += obj.offsetLeft;
        obj = obj.offsetParent;
    }
    return result;
}

function DateChooser(input, div, start, end, format, isTimeChooser,cnt) {
    this._input = input;
    this._div = div;
    this._start = start;
    this._end = end;
    this._format = format;
    this._date = new Date();
     this._cnt = cnt;
  
    this._isTimeChooser = isTimeChooser;
    // Choose a random prefix for all pulldown menus
    this._prefix = "";
    var letters = ["a", "b", "c", "d", "e", "f", "h", "i", "j", "k", "l",
        "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
    for (var i = 0; i < 10; ++i) {
        this._prefix += letters[Math.floor(Math.random() * letters.length)];
    }
}

DateChooser.prototype._isVisible = false;


DateChooser.prototype.isVisible = function() {
    return this._isVisible;
}


DateChooser.prototype.isTimeChooser = function() {
    return this._isTimeChooser;
}

DateChooser.prototype.cont = function() {
    return this._cnt;
}

DateChooser.prototype.getValue = function() {
    return this._date.dateFormat(this._format);
}

DateChooser.prototype.hide = function() {
    this._div.style.visibility = "hidden";
    this._div.style.display = "none";
    this._div.innerHTML = "";
    this._isVisible = false;
}


DateChooser.prototype.show = function() {
    this._div.style.display = "block";
    this._div.style.visibility = "visible";
    this._div.style.position = "absolute";
    var inputPos = getAbsolutePosition(this._input);
    this._div.style.top = (inputPos[0] + this._input.offsetHeight) + "px";
    this._div.style.left = (inputPos[1] + this._input.offsetWidth) + "px";
    this._div.innerHTML = this.createChooserHtml();
    this._isVisible = true;
}

DateChooser.prototype.initializeDate = function() {
    if (this._input.value != null && this._input.value != "") {
        this._date = Date.parseDate(this._input.value, this._format);
    }
    else {
        this._date = new Date();
    }
}


DateChooser.prototype.setDate = function(date) {
    this._date = date ? date : new Date();
}


DateChooser.prototype.setTime = function(hour, minute) {
    this._date.setHours(hour);
    this._date.setMinutes(minute);
}


DateChooser.prototype.createChooserHtml = function() {
    var formHtml = "<input type=\"hidden\" name=\""
        + this._prefix + "inputId\" value=\""
        + this._input.getAttribute('id') + "\">"
        + "\r\n  <select name=\"" + this._prefix 
        + "month\" onChange=\"dateChooserDateChange(this.form, '"
        + this._prefix + "');\">";
    for (var mon in Date.monthNames) {
        formHtml += "\r\n    <option value=\"" + mon + "\""
            + (mon == this._date.getMonth() ? " selected=\"1\"" : "")
            + ">" + Date.monthNames[mon] + "</option>";
    }
    formHtml += "\r\n  </select>\r\n  <select name=\""
        + this._prefix + "year\" onChange=\"dateChooserDateChange(this.form, '"
        + this._prefix + "');\">";
    for (var i = this._start; i <= this._end; ++i) {
        formHtml += "\r\n    <option value=\"" + i + "\""
            + (i == this._date.getFullYear() ? " selected=\"1\"" : "")
            + ">" + i + "</option>";
    }
    formHtml += "\r\n  </select>";
    formHtml += this.createCalendarHtml();
    if (this._isTimeChooser) {
        formHtml += this.createTimeChooserHtml();
    }
    return formHtml;
}


DateChooser.prototype.createTimeChooserHtml = function() {
    // Add hours
    var result = "\r\n  <select name=\"" + this._prefix + "hour\">";
    for (var i = 0; i < 12; ++i) {
        result += "\r\n    <option value=\"" + i + "\""
            + (((this._date.getHours() % 12) == i) ? " selected=\"1\">" : ">")
            + i + "</option>";
    }
    // Add extra entry for 12:00
    result += "\r\n    <option value=\"0\">12</option>";
    result += "\r\n  </select>";
    // Add minutes
    result += "\r\n  <select name=\"" + this._prefix + "min\">";
    for (var i = 0; i < 60; i += 15) {
        result += "\r\n    <option value=\"" + i + "\""
            + ((this._date.getMinutes() == i) ? " selected=\"1\">" : ">")
            + String.leftPad(i, 2, '0') + "</option>";
    }
    result += "\r\n  </select>";
    // Add AM/PM
    result += "\r\n  <select name=\"" + this._prefix + "ampm\">";
    result += "\r\n    <option value=\"0\""
        + (this._date.getHours() < 12 ? " selected=\"1\">" : ">")
        + "AM</option>";
    result += "\r\n    <option value=\"12\""
        + (this._date.getHours() >= 12 ? " selected=\"1\">" : ">")
        + "PM</option>";
    result += "\r\n  </select>";
    return result;
}

DateChooser.prototype.createCalendarHtml = function() {
    var result = "\r\n<table cellspacing=\"0\" class=\"dateChooser\">"
        + "\r\n  <tr><th>S</th><th>M</th><th>T</th>"
        + "<th>W</th><th>T</th><th>F</th><th>S</th></tr>\r\n  <tr>";
    // Fill up the days of the week until we get to the first day of the month
    var firstDay = this._date.getFirstDayOfMonth();
    var lastDay = this._date.getLastDayOfMonth();
    if (firstDay != 0) {
        result += "<td colspan=\"" + firstDay + "\">&nbsp;</td>";
    }
   
    var i = 0;
    while (i < this._date.getDaysInMonth()) {
        if (((i++ + firstDay) % 7) == 0) {
            result += "</tr>\r\n  <tr>";
        }
        var thisDay = new Date(
            this._date.getFullYear(),
            this._date.getMonth(), i);
        var js = '"dateChooserSetDate(\''
            + this._input.getAttribute('id') + "', '"
            + thisDay.dateFormat(this._format) + '\');"'
        result += "\r\n    <td class=\"dateChooserActive"
            // If the date is the currently chosen date, highlight it
            + (i == this._date.getDate() ? " dateChooserActiveToday" : "")
            + "\" onClick=" + js + ">" + i + "</td>";
    }
   
    if (lastDay != 6) {
        result += "<td colspan=\"" + (6 - lastDay) + "\">&nbsp;</td>";
    }
    return result + "\r\n  </tr>\r\n</table>";
}


function amount_cal(id,drink){
	alert(id);
	//alert(num_week);
	//alert(id);
	alert(drink);exit;
	if(document.getElementById('date_event1'+id).value=="")
	{
		alert("enter the date");
		document.getElementById("drink" +id).value="";
		return	
	}

	//alert(document.getElementById("drink" +id));
	
xmlHttp=GetXmlHttpObject_amt();
	if (xmlHttp==null)
		{
		alert ("Browser does not support HTTP Request")
		return
		} 
	
		var food=document.getElementById("type_veg" +id).value;
	if(food=="")
	{
		alert("enter food");
		document.getElementById("drink" +id).value="";
		return	
	}
	if(drink=="")
	{
		alert("enter drink");
		return	
	}
		var dats = document.getElementById('date_event1'+id).value;
        var xx=dats;
        var flags1=xx.split("-");
        var year=flags1[0];
        var mon=flags1[1];
        var date=flags1[2];
        dats =mon + "-" + date + "-" + year;
	
	var url_title="amount_cal.php";
	var url_title=url_title + "?food=" + food + "&drink=" + drink+ "&cnt=" + id;

	xmlHttp.open("GET",url_title,true)
	xmlHttp.onreadystatechange=amt_cal;
	
	
	xmlHttp.send(null) 
}

function amt_cal(){
	var x=xmlHttp.responseText;
	
	var y=document.getElementById("total").value;
	var flags=x.split("@");
	var food_price=flags[0];
	var counts=flags[1];
	var id=counts;
	var drink=document.getElementById("drink" +id).value;
	var food=document.getElementById("type_veg" +id).value;
	var cuisine=document.getElementById("cuisine" +id).value;
	var dats=document.getElementById('date_event1'+id).value;
	//alert(document.getElementById("orders_id" +id).value);
	if(document.getElementById("orders_id" +id).value!=""){
	var ord_id=document.getElementById("orders_id" +id).value;
	var old_price=document.getElementById("amt" +counts).value;
	
	
	}
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	
	
	document.getElementById("amt"+counts).value=food_price;	
	document.getElementById("total").value =+food_price + + + y;	
	document.getElementById("tot").value =+food_price + + + y;	
	if(document.getElementById("orders_id" +id).value!=""){
	var tot11=document.getElementById("total").value;	
	var tot12=document.getElementById("tot").value;
	tot11=tot11-old_price;
	tot12=tot12-old_price;	
	document.getElementById("total").value =tot11;
	document.getElementById("tot").value =tot12;
	}
	
	document.getElementById("add_values").value+=cuisine + "@" + food + "@" + drink + "@" + dats + "@" + food_price + "#" ;	
	if(document.getElementById("orders_id" +id).value!=""){
	document.getElementById("change_values").value+=cuisine + "@" + food + "@" + drink + "@" + dats + "@" + food_price+ "@" + ord_id + "#" ;	
	}
	}

}

function submitse(){
	if(document.getElementById('total').value=="")
	{
		alert("enter the date");
		return false;
	}
	
	if(!document.getElementById('checks').checked){
			alert("You should accept terms and conditions");
			
			return false;
			}
			
}


function GetXmlHttpObject_amt()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
} 

function change_cuisine(id,cont,values){
	
id++;
for(i=id;i<=cont;i++){
var cuisine=document.getElementById("cuisine" +i).value=values;
}	
	
}


function change_veg(id,cont,values){
	
id++;
for(i=id;i<=cont;i++){
var cuisine=document.getElementById("type_veg" +i).value=values;
}	
	
}

function change_drink(id,cont,values){
	
	id++;
	for(i=id;i<=cont;i++){
	var cuisine=document.getElementById("drink" +i).value=values;
	}
		
	}
	
	
	
	//it calculates snacks + food prices
	function amount_school(id,drink){
	//alert(num_week);
	//alert(id);//alert(drink);
	if(document.getElementById('date_event1'+id).value=="")
	{
		alert("enter the date");
		document.getElementById("drink" +id).value="";
		return	
	}

	
	
xmlHttp=GetXmlHttpObject_school();
	if (xmlHttp==null)
		{
		alert ("Browser does not support HTTP Request")
		return
		} 
	
		var food=document.getElementById("type_veg" +id).value;
	if(food=="")
	{
		alert("enter food");
		document.getElementById("drink" +id).value="";
		return	
	}
	if(drink=="")
	{
		alert("enter snacks");
		return	
	}
		var dats = document.getElementById('date_event1'+id).value;
        var xx=dats;
        var flags1=xx.split("-");
        var year=flags1[0];
        var mon=flags1[1];
        var date=flags1[2];
        dats =mon + "-" + date + "-" + year;
	
	var url_title="amount_school.php";
	var url_title=url_title + "?food=" + food + "&drink=" + drink+ "&cnt=" + id;

	xmlHttp.open("GET",url_title,true)
	xmlHttp.onreadystatechange=amt_school;
	
	
	xmlHttp.send(null) 
}

function amt_school(){
	var x=xmlHttp.responseText;
	
	var y=document.getElementById("total").value;
	var flags=x.split("@");
	var food_price=flags[0];
	var counts=flags[1];
	var id=counts;
	
	var drink=document.getElementById("drink" +id).value;
	
	var food=document.getElementById("type_veg" +id).value;
	var cuisine=document.getElementById("cuisine" +id).value;
	var dats=document.getElementById('date_event1'+id).value;
	//alert(document.getElementById("orders_id" +id).value);
	if(document.getElementById("orders_id" +id).value!=""){
	var ord_id=document.getElementById("orders_id" +id).value;
	var old_price=document.getElementById("amt" +id).value;
	
	
	
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	
	
	document.getElementById("amt"+id).value=food_price;	
	document.getElementById("total").value =+food_price + + + y;	
	document.getElementById("tot").value =+food_price + + + y;	
	if(document.getElementById("orders_id" +id).value!=""){
	var tot11=document.getElementById("total").value;	
	var tot12=document.getElementById("tot").value;
	tot11=tot11-old_price;
	tot12=tot12-old_price;	
	document.getElementById("total").value =tot11;
	document.getElementById("tot").value =tot12;
	}
	
	document.getElementById("add_values").value+=cuisine + "@" + food + "@" + drink + "@" + dats + "@" + food_price + "#" ;	
	if(document.getElementById("orders_id" +id).value!=""){
	document.getElementById("change_values").value+=cuisine + "@" + food + "@" + drink + "@" + dats + "@" + food_price+ "@" + ord_id + "#" ;	
	}
	}
	document.getElementById("adds" +id).disabled=true;
	document.getElementById("amt" +id).disabled=true;
}
}
function GetXmlHttpObject_school()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
} 

function change_cuisine(id,cont,values){
	
id++;
for(i=id;i<=cont;i++){
var cuisine=document.getElementById("cuisine" +i).value=values;
}	
	
}
