// JavaScript Document
var XMLresponse;
var doc;
var httpcuisine;

/*Create ajax request object*/
function createRequestObject() {
 // This function is used to create HTTP request object  
    var ObjReq;
    var browser = navigator.appName;
	
    if(browser == "Microsoft Internet Explorer"){
        ObjReq = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ObjReq = new XMLHttpRequest();
    }
    return ObjReq;
}
/*This function will send ajax request for beautytip in website*/
function sndCuisinetipReq(tipnum) {
   // This function sends HHTP request
  
	
    httpcuisine = createRequestObject();
    httpcuisine.open('get', 'balhomepage.php?iscuisinetipreq=1&tipnum='+tipnum+'');
    httpcuisine.onreadystatechange = handleCusinetipResponse;
    httpcuisine.send(null);
	
	
}

/*This will handle the response*/
function handleCusinetipResponse() {
   //This functions handle HTTP response
   XMLresponse="";
  
  
   if(httpcuisine.readyState == 4){
       
         XMLresponse=httpcuisine.responseText;
		
		 if(XMLresponse==0)
		 {
			  alert("No Records Fetch.");
		 }else
		 { 
			 ReadCuisineXML(XMLresponse);
		 }
			
    }
   
}

/*This will read the xml for the server */
function ReadCuisineXML(xmlresponse)
{
	
           if (window.ActiveXObject)
			{
		    doc=new ActiveXObject("Msxml2.DOMDocument.3.0");
			doc.async = false;
            doc.resolveExternals = false;
            doc.validateOnParse = false;
			doc.loadXML(xmlresponse);
			
			
			}
			// code for Mozilla, Firefox, Opera, etc.
			else
			{
			var parser=new DOMParser();
		    doc=parser.parseFromString(xmlresponse,"text/xml");
			}	
			
			sndCuisineImgReq(doc.getElementsByTagName("cuisinetipid")[0].childNodes[0].nodeValue);
			
			document.getElementById("divcuisinetipkeyword").firstChild.data=doc.getElementsByTagName("keyword")[0].childNodes[0].nodeValue;
			
			document.getElementById("divcuisinetipdesc").firstChild.data=doc.getElementsByTagName("description")[0].childNodes[0].nodeValue;
			
	
}
/*This function will send ajax request for beautytip in website*/
function sndCuisineImgReq(tipid) {
   // This function sends HHTP request
    httpcuisine=null;
    httpcuisine = createRequestObject();
    httpcuisine.open('get', 'balhomepage.php?iscuisinetipimgreq=1&cuisinetipid='+tipid+'');
    httpcuisine.onreadystatechange = handleCuisinetipImgResponse;
    httpcuisine.send(null);
	
}

/*This will handle the response*/
function handleCuisinetipImgResponse() {
   //This functions handle HTTP response
   XMLresponse="";
   if(httpcuisine.readyState == 4){
        
         XMLresponse=httpcuisine.responseText;
		
		 if(XMLresponse==0)
		 {
			  alert("No Records Fetch.");
		 }else
		 {
			 
			 document.getElementById("divcuisinetipimg").innerHTML=(XMLresponse);
		 }
			
    }
   
}

/*Will check which button is called*/
function sendReqCuisineTip(buttoncalled)
{
   if(buttoncalled==1)
   {
	   /*Next buuton is clicked*/
	   var next=document.getElementById("txtnextcuisinetip");
	   var prev=document.getElementById("txtprevcuisinetip");
	   next.value=parseInt(next.value)+1;;
	   prev.value=parseInt(prev.value)+1;
	   if(next.value<=5){
		  
	   sndCuisinetipReq(next.value);
	   }
   }else
   {
	   /*Prev buuton is clicked*/
	   var prev=document.getElementById("txtprevcuisinetip");
	   var next=document.getElementById("txtnextcuisinetip");
	   prev.value=parseInt(prev.value)-1;
	   next.value=parseInt(next.value)-1;
	   if(prev.value!=0){
		  
	   sndCuisinetipReq(prev.value);
	   }
   }
  
  
}//eof
