﻿//// JScript File

//$(document).ready(function(){
//$('#dialog').dialog({
//					autoOpen: false,
//					width: 200,		
//					height: 35
//				});
//$('#divMsg').dialog({
//					autoOpen: false,
//					width: 300,		
//					height: 35								
//				});
//});

function getViewsource()
{    
    var source;
    var strResult=" <div class='cater' id='divCater'>";
    var strHeading="";
    var id;
    var all=document.getElementsByTagName("input");
    var source = document.getElementById("ctl00_BodyContent_txtArea");
    //alert(source.innerHTML);
    var headingfirst=0;
    var tempClass=0;
    
    
    strResult+="<table>";
    
    for (var i = 0; i < all.length; i++) 
        {         
            if (all[i].value!=""  && all[i].id.indexOf("t_")!=-1 &&  all[i].type=="text") 
            {                   
                    var td = all[i];
                    id= td.id.replace("t_","");   
                    
                    var tltd=document.getElementById("tl_"+id);                    
                    var tempHeading=all[i].name;
                    var p=document.getElementById("p_"+id);                    
                    
                    if(td.className!=tempClass && tempClass!=0)
                        {
                            var tdNote=document.getElementById("note_"+tempClass);
                            if(tdNote!=null)
                                {
                                     strResult = strResult + "<tr><td colspan='6'></td><tr>";
                                     strResult = strResult + "<tr><td colspan='6'>"+tdNote.innerHTML+"</td><tr>";
                                     strResult = strResult + "<tr><td colspan='6'></td><tr>";
                                }
                            
                         }                        
                        tempClass = td.className;
                    
                    if(tltd!=null)
                    {   
                        if(strHeading!=tempHeading)
                            {
                                strResult = strResult + "<tr><td colspan='6'> </td></tr>";
                                strResult = strResult + "<tr><td colspan='6'> <div class='dot_line2'></div></td></tr>";
                                strResult = strResult + "<tr><td colspan='6'> </td></tr>";
                                strResult = strResult + "<tr><td style='width:350px;' class='itemHeading'>" + tempHeading + "</td> <td style='width:75px;'  class='caterrowHeading'>Small</td> <td style='width:150px;'> </td> <td style='width:75px;' class='caterrowHeading'> Large </td> <td style='width:150px;'> </td> <td align='right' style='width:150px;' class='caterrowHeading'> Totals </td> </tr>";                                
                                strResult = strResult + "<tr><td style='width:350px;' class='itemHeading'> Minimum 10 people, 24hrs notice required </td> <td style='width:75px;'  class='caterrowHeading'> 	5-8 people</td> <td style='width:150px;'> </td> <td style='width:75px;' class='caterrowHeading'> 	10-15people	 </td> <td style='width:150px;'> </td> <td align='right' style='width:150px;' class='caterrowHeading'>  </td> </tr>";                                
                                strHeading=tempHeading;
                            } 
                        var temp= (navigator.appName.indexOf("Microsoft")!= -1)?p.previousSibling.innerHTML:p.previousSibling.previousSibling.innerHTML;
                        strResult = strResult + "<tr><td style='width:350px;'>" + temp + "</td> <td style='width:75px;'>" +document.getElementById("p_"+id).innerHTML +"</td>";               
                        strResult = strResult + "<td style='width:150px;'>" + td.value + "</td> <td style='width:75px;'>" + document.getElementById("pl_"+id).innerHTML +"</td><td style='width:150px;'>"+tltd.value+"</td>";
                        strResult = strResult + "<td align='right' style='width:150px;'>" + document.getElementById("c_"+id).value +"</td></tr>";                        
                       
                    }
                    else
                    {   
                        if(strHeading!=tempHeading)
                            {
                                if(headingfirst==0)
                                {
                                    
                                    strResult = strResult + "<tr><td class='Heading' colspan='6'> Corporate Catering </td></tr>";
                                    strResult = strResult + "<tr><td colspan='6'> </td></tr>";
                                    strResult = strResult + "<tr><td colspan='6' align='center' class='itemHeading'>Thank you for ordering from Rave Café</td></tr>";
                                    strResult = strResult + "<tr><td colspan='6'> <div class='solid_line5'></div></td></tr>";
                                    strResult = strResult + "<tr><td colspan='6'> </td></tr>";
                                    strResult = strResult + "<tr><td style='width:425px;' class='itemHeading'>" + tempHeading + "</td> <td style='width:275px; padding-right:30px;' align='right' colspan='3'  class='caterrowHeading'>Each</td> <td style='width:150px;' class='caterrowHeading'> Number Required </td> <td style='width:150px;' align='right' class='caterrowHeading'> Totals </td> </tr>";                                
                                    headingfirst=1;
                                }
                                else
                                {
                                    strResult = strResult + "<tr><td colspan='6'> <div class='dot_line2'/></td></tr>";
                                    strResult = strResult + "<tr><td style='width:425px;' class='itemHeading'>" + tempHeading + "</td> <td style='width:275px; padding-right:30px;' colspan='3'  class='caterrowHeading'></td> <td style='width:150px;' class='caterrowHeading'>  </td> <td style='width:150px;' align='right' class='caterrowHeading'> Totals </td> </tr>";                                                                
                                }
                                strHeading=tempHeading;
                            }              
                        var temp= (navigator.appName.indexOf("Microsoft")!= -1)?p.previousSibling.innerHTML:p.previousSibling.previousSibling.innerHTML;
                        strResult = strResult + "<tr><td style='width:425px;'>" + temp + "</td> <td style='width:275px; padding-right:30px;' align='right' colspan='3'>" +document.getElementById("p_"+id).innerHTML +"</td>";               
                        strResult = strResult + "<td style='width:150px;'>" + td.value + "</td> <td align='right' style='width:150px;'>" +document.getElementById("c_"+id).value +"</td></tr>";                                                
                        
                }               
                
            } 
        }      
        
        var tdNote=document.getElementById("note_"+tempClass);
        if(tdNote!=null)
            {
                 strResult = strResult + "<tr><td colspan='6'></td><tr>";
                 strResult = strResult + "<tr><td colspan='6'>"+tdNote.innerHTML+"</td><tr>";
                 strResult = strResult + "<tr><td colspan='6'></td><tr>";
            }
        
        strResult +="<tr><td colspan='6'></td></tr>";
        strResult +="</table>";
        
        
        //var payment= document.getElementById("divPayment");
        
        var input= document.getElementsByTagName("input");
        var j=0;
        
        strResult +="<div class='caterPayment'>";
        strResult +="<table id='tblPayment' style='width:985px;'>";
        for (var i = 0; i < input.length; i++) 
        {
           if (input[i].type=="text") 
            {
                if(input[i].id.indexOf("txtTotalCost")!=-1) 
                {
                    strResult = strResult + "<tr><td  style='padding-right:45px'  align='right'  colspan='4'> <b>Total Cost:</b> " +input[i].value +"</td></tr>";                                   
                    strResult = strResult + "<tr><td colspan='4'> </td></tr>";
                    strResult = strResult + "<tr><td colspan='4'> <div class='dot_line2'></div></td></tr>";
                    strResult = strResult + "<tr><td colspan='4'> </td></tr>";
                }
                
                else
                {
                    if(input[i].name.indexOf("novalidate")!=-1 || input[i].name.indexOf("validate")!=-1)
                    {
                        if(j%2==0)
                        {
                            strResult = strResult + "<tr><td style='width:290px;'>" + input[i].parentNode.previousSibling.innerHTML + "</td> <td style='width:200px;'>" +input[i].value +"</td>";                                   
                        }
                        else
                        {
                            strResult = strResult + "<td style='width:290px;'>" + input[i].parentNode.previousSibling.innerHTML + "</td> <td style='width:200px;'>" +input[i].value +"</td></tr>";                                       
                        }
                        j++;
                    }
                }                
            }
        }        
        
        //var rd=document.getElementById("radioPayment");
        //var strTemp = rd.innerHTML;
        var strTemp = checkRadio();
        //strTemp = strTemp.replace(/\"/g,'\'');
        //strTemp = strTemp.replace("<input id='txtOther' type='text'>", ": "+document.getElementById("txtOther").value)
        if(document.getElementById("txtOther").value!="")
            strTemp+= " :"+document.getElementById("txtOther").value;
        
        strResult = strResult + "<tr><td colspan='4'> </td></tr>";
        strResult = strResult + "<tr><td colspan='4'> <div class='dot_line2'></div></td></tr>";
        strResult = strResult + "<tr><td colspan='4'>Indicate Payment method </td></tr>";        
        strResult = strResult + "<tr><td colspan='4'>";
        strResult = strResult + strTemp;
        strResult = strResult + "</td></tr>";        
        strResult = strResult + "<tr><td colspan='4'> </td></tr>";
        strResult = strResult + "<tr><td colspan='4'> <div class='dot_line2'></div> </td></tr>";
        strResult = strResult + "<tr><td colspan='4'> </td></tr>";
        
        var ul=document.getElementById("ulPayment");
        
        strResult = strResult + "<tr><td colspan='4'>NOTE: </td></tr>";        
        strResult = strResult + "<tr><td colspan='4'> </td></tr>";
        strResult = strResult + "<tr><td colspan='4'> <div class='dot_line2></div></td></tr>";
        strResult = strResult + "<tr><td colspan='4'> </td></tr>";
        strResult +="<tr><td colspan='4'>";
        strResult +=ul.innerHTML;
        strResult +="</td></tr>";        
        strResult = strResult + "<tr><td colspan='4'> </td></tr>";
        strResult = strResult + "<tr><td colspan='4'> <div class='dot_line2'></div></td></tr>";
        strResult = strResult + "<tr><td colspan='4'> </td></tr>";
        
        
        strResult +="</table>";
        strResult +="</div>"; 
        
        
        //strResult +="<div id='divPayment'  class='caterPayment'>";        
        //strResult +=payment.innerHTML;
        //strResult +="</div>";
        strResult +="</div>";
        
        //var divCater=document.getElementById('ctl00_BodyContent_divCater');
        //divCater.innerHTML=strResult;
        //var divcaterPayment=document.getElementById('ctl00_BodyContent_divcaterPayment');
        //divcaterPayment.visible=false;
        source.value=strResult;       
        return true;         
}



 function CallSuccess(res)
 {     
    
 }
 
 function CallFailed(res)
 {
    
 }


function calTotalCost(id)
{
      var divAlert=document.getElementById("divAlert");
      var divAlert2=document.getElementById("divAlert2");
      var tdPrice=document.getElementById("p_"+id);
      var total=document.getElementById("t_"+id);
      var cost=document.getElementById("c_"+id);
      var totalCost=document.getElementById("txtTotalCost");
      
      var price = tdPrice.innerHTML.replace("$","");      
      
      
      //cost.value=(price)*(total.value);
      price=(price)*(total.value);
      if(!isNaN(price))
      {
          var num = new Number(price);      
          
          var tempNum = new Number(((cost.value=='')?0:cost.value));
          
          cost.value=num.toFixed(2);
          
          var costNum = new Number(((totalCost.value=='')?0:totalCost.value));
          var totalc= new Number(costNum + num - tempNum);
          
          totalCost.value = totalc.toFixed(2);
          divAlert.style.visibility="hidden";
          divAlert2.style.visibility='hidden';
        if(price==0)
        {
            total.value="";
            cost.value="";
        }
      }
      else 
      {
        //var msg=document.getElementById("lblMessage");
        //var msgTop=document.getElementById("lblMessageTop");
        total.focus();            
        //msgTop.innerHTML="Please enter number";
        var x = jQuery(total).position().left + jQuery(total).outerWidth();
        var y = jQuery(total).position().top;// - jQuery(document).scrollTop();                            
        //$('#dialog').dialog('option', 'position', [x,y]);
		//$('#dialog').dialog('open');
		
		//divAlert.style.visibility='visible';
		divAlert.style.visibility="visible";
		if(navigator.appName.indexOf("Microsoft")!= -1)
		{
	        divAlert.style.posLeft=(x);
	        divAlert.style.posTop=(y);
		}
		else
		{
		    divAlert.style.marginLeft=(total.parentNode.offsetLeft-200)+'px';
	        divAlert.style.marginTop=(y) +'px';
		}
		window.scroll(0,total.parentNode.offsetTop);
        return false;
      }
      
}


function calTotalCost2(id)
{
      var divAlert=document.getElementById("divAlert");
      var divAlert2=document.getElementById("divAlert2");
      var tdPrice=document.getElementById("p_"+id);
      var tdPriceL=document.getElementById("pl_"+id);
      var total=document.getElementById("t_"+id);
      var totalL=document.getElementById("tl_"+id);
      var cost=document.getElementById("c_"+id);
      
      var totalCost=document.getElementById("txtTotalCost");
      
      var price = tdPrice.innerHTML.replace("$","");                  
      price = price.replace("pp",""); 
      var price1=(price)*(total.value);
      
      price = (tdPriceL!=null)?tdPriceL.innerHTML.replace("$",""):0;      
      
      var price2=(price)*((totalL!=null)?totalL.value:0);
             
          var num = new Number((isNaN(price1)?0:price1)+(isNaN(price2)?0:price2));      
          
          var tempNum = new Number(((cost.value=='')?0:cost.value));
          
          cost.value=num.toFixed(2);
          
          var costNum = new Number(((totalCost.value=='')?0:totalCost.value));
          var totalc= new Number(costNum + num - tempNum);
          
          totalCost.value = totalc.toFixed(2);
          divAlert.style.visibility='hidden';
          divAlert2.style.visibility='hidden';
          
       if(price1==0)
        {
            total.value="";            
        }
       if(price2==0)
        {
            if(totalL!=null)totalL.value="";            
        }
        if(price1==0&&price2==0)
        {            
            cost.value="";
        }
      
      
        var x;
        var y;
        if(isNaN(price1))
            {
                total.focus();    
                if(navigator.appName.indexOf("Microsoft")!= -1)
		        {
                    x = jQuery(total).position().left + jQuery(total).outerWidth();
                    y = jQuery(total).position().top;
                }
                else
                {
                    x = total.parentNode.offsetLeft;
                    y = jQuery(total).position().top;
                }   
                divAlert.style.visibility='visible';
		
		            if(navigator.appName.indexOf("Microsoft")!= -1)
		            {
	                    divAlert.style.posLeft=(x);
	                    divAlert.style.posTop=(y);
		            }
		            else
		            {
		                divAlert.style.marginLeft=(x-200)+'px';
	                    divAlert.style.marginTop=(y) +'px';
		            }		
            		
		            window.scroll(0,total.parentNode.offsetTop);
                    return false; 
            }
        else if(isNaN(price2))
            {
                totalL.focus();                    
                if(navigator.appName.indexOf("Microsoft")!= -1)
		        {
                    x = jQuery(totalL).position().left + jQuery(totalL).outerWidth();
                    y = jQuery(totalL).position().top;
                }
                else
                {
                    x = total.parentNode.offsetLeft;
                    y = jQuery(totalL).position().top;
                }   
                divAlert.style.visibility='visible';
		
		        if(navigator.appName.indexOf("Microsoft")!= -1)
		        {
	                divAlert.style.posLeft=(x);
	                divAlert.style.posTop=(y);
		        }
		        else
		        {
		            divAlert.style.marginLeft=(x-200)+'px';
	                divAlert.style.marginTop=(y) +'px';
		        }		
        		
		        window.scroll(0,total.parentNode.offsetTop);
                return false; 
            }                                 
}


function validatePayment()
{
    //var msg=document.getElementById("lblMessage");
    //var msgTop=document.getElementById("lblMessageTop");
    var divAlertOne=document.getElementById("divAlert");
    var divAlert=document.getElementById("divAlert2");
    var divAlertInner=document.getElementById("divAlertInner");
    var msg=document.getElementById("divMsg");
    var totalCost=document.getElementById("txtTotalCost");
    var txtOther=document.getElementById("txtOther");
    var divPayment=document.getElementById("divPayment");
    var txtEmail = document.getElementById("ctl00_BodyContent_txtEmail");
    var x;
    var y;                              
    
    //msg.innerHTML ="";
    if(totalCost.value=="" || totalCost.value=="0.00")
        {
            //divCater.scrollTop = 0;
            divAlertInner.innerHTML="Please select menu...";
            window.scroll(0,0);
            var all=document.getElementsByTagName("input");
            for (var i = 0; i < all.length; i++) 
                    {         
                        if (all[i].id.indexOf("t_")!=-1 &&  all[i].type=="text") 
                        {   
                            all[i].focus();     
                            divAlert.style.visibility='visible';
                            x = jQuery(all[i]).position().left + jQuery(all[i]).outerWidth();
                            y = jQuery(all[i]).position().top;
                            if(navigator.appName.indexOf("Microsoft")!= -1)
		                    {
	                            divAlert.style.posLeft=(x);
	                            divAlert.style.posTop=(y);
	                        }
	                        else
	                        {
	                            divAlert.style.marginLeft=(all[i].parentNode.offsetLeft-200)+'px';
	                            divAlert.style.marginTop=(y) +'px';
	                        }    
		                    window.scroll(0,all[i].parentNode.offsetTop);                            
                            break;
                        }
                    }  
            return false; 
        }
     
            var all=document.getElementsByTagName("input");
            for (var i = 0; i < all.length; i++) 
                    {         
                        if ((all[i].id.indexOf("t_")!=-1 || all[i].id.indexOf("tl_")!=-1) &&  all[i].type=="text" && isNaN(all[i].value)) 
                        {   
                            all[i].focus();    
                            window.scroll(0,all[i].parentNode.offsetTop);
                            divAlertOne.style.visibility='visible';
                            x = jQuery(all[i]).position().left + jQuery(all[i]).outerWidth();
                            y = jQuery(all[i]).position().top;
                            if(navigator.appName.indexOf("Microsoft")!= -1)
		                    {
	                            divAlertOne.style.posLeft=(x);
	                            divAlertOne.style.posTop=(y);
	                        }
	                        else
	                        {
	                            divAlertOne.style.marginLeft=(all[i].parentNode.offsetLeft-200)+'px';
	                            divAlertOne.style.marginTop=(y) +'px';
	                        }                           
                            return false;
                            break;
                        }
                    }   
            //msgTop.innerHTML="Please enter proper value";
            divAlertOne.style.visibility='hidden';
        

    var all=document.getElementsByName("validate");
    var tableOffsetTop=document.getElementById("tblPayment").offsetTop;
    for (var i = 0; i < all.length; i++) 
        {         
            if (all[i].value=="") 
            { 
                all[i].focus();                              
                divAlertInner.innerHTML="Please Enter the mandatory fields.";                
                divAlert.style.visibility='visible';
                x = jQuery(all[i]).position().left + jQuery(all[i]).outerWidth();
                y = jQuery(all[i]).position().top;
                if(navigator.appName.indexOf("Microsoft")!= -1)
                {
                    window.scroll(x,y);
                    divAlert.style.posLeft=(x);
                    divAlert.style.posTop=(y);
                }
                else
                {
                    window.scroll(0,tableOffsetTop+all[i].parentNode.offsetTop);
                    divAlert.style.marginLeft=(all[i].parentNode.offsetLeft-200)+'px';
                    divAlert.style.marginTop=(y) +'px';
                }     
                return false;             
            } 
            else
            {
                switch(all[i].parentNode.previousSibling.innerHTML)
                    {
                        case "Email":
                            var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;    
                            if(all[i].value.match(emailRegEx))
                            {                 
                                txtEmail.value = all[i].value;      
                            }
                            else
                            {       
                               divAlertInner.innerHTML = 'Please enter a valid email';
                               window.scroll(0,tableOffsetTop+all[i].parentNode.offsetTop);
                                divAlert.style.visibility='visible';
                                x = jQuery(all[i]).position().left + jQuery(all[i]).outerWidth();
                                y = jQuery(all[i]).position().top;
                                if(navigator.appName.indexOf("Microsoft")!= -1)
		                        {
		                            window.scroll(x,y);
	                                divAlert.style.posLeft=(x);
	                                divAlert.style.posTop=(y);
	                            }
	                            else
	                            {
	                                window.scroll(0,tableOffsetTop+all[i].parentNode.offsetTop);
	                                divAlert.style.marginLeft=(all[i].parentNode.offsetLeft-200)+'px';
	                                divAlert.style.marginTop=(y) +'px';
	                            }        
                               return false;                         
                            }
                            break;
                        case "Contact":  
                            var txtContact=document.getElementById("ctl00_BodyContent_txtContact");
                            txtContact.value=all[i].value;
                            break;
                        case "Company name":  
                        var txtCompany=document.getElementById("ctl00_BodyContent_txtCompany");
                        txtCompany.value=all[i].value;
                            break;                                                  
                        case "Contact Phone":
                        case "Number of people for function":
                                if(isNaN(all[i].value))  
                                    {
                                        divAlertInner.innerHTML = 'Please enter a valid input: Fax, Contact, Number Of People';
                                        window.scroll(0,tableOffsetTop+all[i].parentNode.offsetTop);
                                        divAlert.style.visibility='visible';
                                        x = jQuery(all[i]).position().left + jQuery(all[i]).outerWidth();
                                        y = jQuery(all[i]).position().top;
                                        if(navigator.appName.indexOf("Microsoft")!= -1)
		                                {
		                                    window.scroll(x,y);
	                                        divAlert.style.posLeft=(x);
	                                        divAlert.style.posTop=(y);
	                                    }
	                                    else
	                                    {
	                                        window.scroll(0,tableOffsetTop+rd[i].parentNode.offsetTop);
	                                        divAlert.style.marginLeft=(all[i].parentNode.offsetLeft-200)+'px';
	                                        divAlert.style.marginTop=(y) +'px';
	                                    }    
                                        return false;    
                                    }
                                break;
                    }
            }
        } 
        
    var rd=document.getElementsByName("payment");
    for(var i = 0; i < rd.length; i++) 
        {   
            if(rd[i].checked)                
                if(rd[i].id=="Other")
                {
                    if(txtOther.value=="")
                        {
                            divAlertInner.innerHTML = "Please Enter other payment method";                            
                            divAlert.style.visibility='visible';
                            x = jQuery(all[i]).position().left + jQuery(all[i]).outerWidth();
                            y = jQuery(all[i]).position().top;
                            if(navigator.appName.indexOf("Microsoft")!= -1)
		                    {
		                        window.scroll(x,y);
	                            divAlert.style.posLeft=(x);
	                            divAlert.style.posTop=(y);
	                        }
	                        else
	                        {
	                            window.scroll(0,tableOffsetTop+rd[i].parentNode.offsetTop);
	                            divAlert.style.marginLeft=(all[i].parentNode.offsetLeft-200)+'px';
	                            divAlert.style.marginTop=(y) +'px';
	                        }     
                            
                            return false;
                        }
                }
               else
               {
                    txtOther.value="";
               }         
        }
        divAlert.style.visibility='hidden';
       getViewsource();
}

function checkRadio()
{
    var strResult="";
    var rd=document.getElementsByName("payment");
    for(var i = 0; i < rd.length; i++) 
        {
            if(rd[i].checked)
                {
//                    strResult+="<input disabled='true' checked='true' name='payment' type='radio'>";
                      strResult = rd[i].id;
//                    strResult+="</input>";

                }
//            else
//                {
//                    strResult+="<input disabled='true' name='payment' type='radio'>";
//                    strResult+=rd[i].id;
//                    strResult+="</input>";
//                }
        }
        return strResult;
}

function selectRadio()
{
     var rd=document.getElementsByName("payment");
    for(var i = 0; i < rd.length; i++) 
        {   
            if(rd[i].id=="Other")
                rd[i].checked=true;                 
        }
}

function changeDiv()
{
    var source = document.getElementById("ctl00_BodyContent_txtArea");
    var divCater=document.getElementById('ctl00_BodyContent_divCater');
    divCater.innerHTML=source.value;
    var divcaterPayment=document.getElementById('ctl00_BodyContent_divcaterPayment');
    divcaterPayment.visible=false;
    
    return false;
    
}