// JavaScript Document
var PROMO_NEWS_PAGE_CSSID = null;

function promonews_pageload(xszCSSID, xszPAGEID)
{
    //called when the page first loads up
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, null);
}
function promonews_meta(xszCSSID, xszPAGEID)
{
    //called when the page first loads up
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&getmeta=true");
}

/* get the image path */
function getImageFullPath(phpFilePath_With_Req_PARAM, image_ctrl)
{	
	image_path = promo_httpsearchreq_for_image_path(phpFilePath_With_Req_PARAM, image_ctrl);
	//return image_path;
}
/* get image path overs */

function promonews_news_desc(xszCSSID, xszPAGEID)
{
    //called when the page first loads up
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=latest_news_desc");
}

function promonews_blogs_desc(xszCSSID, xszPAGEID)
{
    //called when the page first loads up
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=blogs_desc");
}
/*function promonews_news_desc(xszCSSID, xszPAGEID)
{
    //called when the page first loads up
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=latest_news_desc");
}*/

// left nav latest news
function promonews_left_nav_latest_news(xszCSSID, xszPAGEID)
{
    //called when the page first loads up
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=latest_news");
}

// left nav blogs
function promonews_left_nav_blogs(xszCSSID, xszPAGEID)
{
    //called when the page first loads up
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=blogs");
}
//home page latest products
function promonews_pagelatest_poular(xszCSSID, xszPAGEID)
{
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=featured1");
}

function promonews_pagelatest_poular_featured(xszCSSID, xszPAGEID)
{
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=FEATURED1_FRANCHISEE");
}

function promonews_pagelatest_poular2(xszCSSID, xszPAGEID)
{
	 PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=featured2");
}

// trade logo

function promonews_trade_logo(xszCSSID, xszPAGEID)
{
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=trade_logo");
}
//showcase items
function promonews_showcaseitem(xszCSSID, xszPAGEID)
{
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=showcaseitem");
}
//External links items
function promonews_extlinks(xszCSSID, xszPAGEID)
{
    PROMO_NEWS_PAGE_CSSID = xszCSSID;
    promo_httpsearchreq(null, xszCSSID, xszPAGEID, "&contenttype=indexextlink");
}


function promo_httpsearchreq(xoForm, xszCSSID, xszPAGEID, xEXTRAPARAM)
{
    var xmlhttp=null;
    var urlPROMONEWS = PROMO_NEWS_PAGE_URL;
    var szURLParams = "";

    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    // code for IE
    else if (window.ActiveXObject)
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (xmlhttp!=null)
    {

        xmlhttp.open("POST","httpproxy.php" , true);

        xmlhttp.onreadystatechange = function()
                                        {
                                            if (xmlhttp.readyState == 4)
                                            {
                                                if (xmlhttp.status == 200)
                                                {	
                                                    //something has been returned
													//alert(xmlhttp.responseText);
                                                    //promonews_searchhandler(xmlhttp.responseXML, xszCSSID);
													//alert(xszCSSID);
													if (xszCSSID == 'meta')
													{
														
														if (xmlhttp.responseText != "")
														{
														
															var metaContent = xmlhttp.responseText.split('|');
															
															var meta = document.createElement('meta');
															meta.name = 'title';
															meta.content = metaContent[0];
															document.getElementsByTagName('head')[0].appendChild(meta);
															var meta1 = document.createElement('meta');
															meta1.name = 'keyword';
															meta1.content = metaContent[1];
															document.getElementsByTagName('head')[0].appendChild(meta1);
															
															var meta2 = document.createElement('meta');
															meta2.name = 'description';
															meta2.content = metaContent[2];
															document.getElementsByTagName('head')[0].appendChild(meta2);
														}
													}
													else
													{
														promo_searchhandler(xmlhttp.responseText, xszCSSID);
													}
                                                }
                                                else
                                                {
                                                    //error has occurred
                                                    promo_statuserror(xmlhttp.status, xmlhttp.statusText);
                                                }
                                            }
                                        }

			
         szURLParams += "pagelabel=" + xszPAGEID;
         szURLParams += "&access_code=" + ACCESSCODE;
		 //alert(ACCESSCODE);
		if(xEXTRAPARAM != null) { szURLParams += xEXTRAPARAM; }
         var szFullURL = urlPROMONEWS+'?' + szURLParams;

         /* Send the POST request */
         xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       //  alert('PARAMS:=' + szURLParams);
         //xmlhttp.send(szURLParams);
		 //alert(szFullURL);
		 xmlhttp.send("url=" + escape(szFullURL));
    }

    return;
}

function promo_httpsearchreq_for_image_path(page_url_with_required_param, image_ctrl)
{
    var xmlhttp=null;
    //var urlPROMONEWS = PROMO_NEWS_PAGE_URL;
    var szURLParams = "";

    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    // code for IE
    else if (window.ActiveXObject)
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (xmlhttp!=null)
    {

        xmlhttp.open("POST","httpproxy.php" , true);

        xmlhttp.onreadystatechange = function()
                                        {
                                            if (xmlhttp.readyState == 4)
                                            {
                                                if (xmlhttp.status == 200)
                                                {	
                                                    //something has been returned
													//alert(xmlhttp.responseText);
                                                    //promonews_searchhandler(xmlhttp.responseXML, xszCSSID);
													//alert(xszCSSID);
													//alert(xmlhttp.responseText);
													//return xmlhttp.responseText;
													var resp_Text = xmlhttp.responseText.replace(/\n/g,"");
													resp_Text = resp_Text.replace(/\t/,"");
													//alert(resp_Text);
													//alert(image_ctrl);
													document.getElementById(image_ctrl).src = resp_Text;
                                                }
                                                else
                                                {
                                                    //error has occurred
                                                    promo_statuserror(xmlhttp.status, xmlhttp.statusText);
                                                }
                                            }
                                        }
         
         
		 //alert(ACCESSCODE);
		 //alert(page_url_with_required_param);
         var szFullURL = page_url_with_required_param;

         /* Send the POST request */
         xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
         //alert('PARAMS:=' + szURLParams);
         //xmlhttp.send(szURLParams);
		 //alert(szFullURL);
		 xmlhttp.send("url=" + escape(szFullURL));
    }

    return;
}


function promo_searchhandler(xohttp, xszCSSID)
{	
	try
	{
    	promo_cleardiv(xszCSSID);
		
		if(xszCSSID=="indexExtLink")
			xohttp=xohttp.replace(/<a /g,"<a target='_blank' ");
			
		var oElement = document.getElementById(xszCSSID);
		if(oElement != undefined || oElement != 'undefined')
			oElement.innerHTML += xohttp;
	}
	catch(err)
	{
		
	}
}

function promo_cleardiv(xszCSSID)
{
    var oElement = document.getElementById(xszCSSID);
    if(oElement)
    {
        oElement.innerHTML = "";
    }
}
function promo_statuserror(xszErrorNo, xszErrorMsg)
{
    alert('Error getting data: [' + xszErrorNo + '] - ' + xszErrorMsg);
}

////new function added 0n 18_05_2009
function promonews_quicksearch_options(categoryid, TOTAL_CHKBOX_TO_DISPLAY,xszPAGEID, xEXTRAPARAM)
{
	//alert("111");
	var xmlhttp=null;
    var urlPROMONEWS = PROMO_NEWS_PAGE_URL;
    var szURLParams = "";
		var xszPAGEID="quicksearch";
	  var xszCSSID="indexIntro"; 
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    // code for IE
    else if (window.ActiveXObject)
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (xmlhttp!=null)
    {

        xmlhttp.open("POST","httpproxy.php" , true);

        xmlhttp.onreadystatechange = function()
							{
								if (xmlhttp.readyState == 4)
								{
									if (xmlhttp.status == 200)
									{	
										//something has been returned
										//promonews_searchhandler(xmlhttp.responseXML, xszCSSID);
										//alert(xmlhttp.responseText);
										promo_searchhandler_quick(xmlhttp.responseText, xszCSSID);
									}
									else
									{
										//error has occurred
										promo_statuserror(xmlhttp.status, xmlhttp.statusText);
									}
								}
							}

			
         szURLParams += "pagelabel1=" + xszPAGEID;
         szURLParams += "&access_code=" + ACCESSCODE;
		 szURLParams += "&categoryid=" + categoryid;
		  szURLParams += "&noofoptions=" + TOTAL_CHKBOX_TO_DISPLAY;
		//if(xEXTRAPARAM != null) { szURLParams += xEXTRAPARAM; }
         var szFullURL = urlPROMONEWS+'?' + szURLParams;

         /* Send the POST request */
         xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      // alert(szFullURL);
         //xmlhttp.send(szURLParams);
		 xmlhttp.send("url=" + escape(szFullURL));
    }
}

function promonews_quicksearch_categoryoptions(categoryid, TOTAL_CHKBOX_TO_DISPLAY,xszPAGEID, xEXTRAPARAM){	

//alert("222");
//alert("categoryid!!!!"+categoryid);
//alert("total"+TOTAL_CHKBOX_TO_DISPLAY);
	var xmlhttp=null;
    var urlPROMONEWS = PROMO_NEWS_PAGE_URL;
    var szURLParams = "";
		var xszPAGEID="quicksearchcategory";
	  var xszCSSID="indexIntro"; 
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    // code for IE
    else if (window.ActiveXObject)
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (xmlhttp!=null)
    {

        xmlhttp.open("POST","httpproxy.php" , true);

        xmlhttp.onreadystatechange = function()
							{
								if (xmlhttp.readyState == 4)
								{
									if (xmlhttp.status == 200)
									{	
									
										//alert("httppage"+xmlhttp.status);
										//alert(xmlhttp.responseText);
									
										//something has been returned
										//promo_searchhandler_quick(xmlhttp.responseText, xszCSSID);
										//alert(xmlhttp.responseText);
										promo_searchhandler_quick(xmlhttp.responseText, xszCSSID);
									}
									else
									{
										//error has occurred
										promo_statuserror(xmlhttp.status, xmlhttp.statusText);
									}
								}
							}

			
         szURLParams += "pagelabel1=" + xszPAGEID;
         szURLParams += "&access_code=" + ACCESSCODE;
		 szURLParams += "&categoryid=" + categoryid;
		  szURLParams += "&noofoptions=" + TOTAL_CHKBOX_TO_DISPLAY;
		//if(xEXTRAPARAM != null) { szURLParams += xEXTRAPARAM; }
         var szFullURL = urlPROMONEWS+'?' + szURLParams;

         /* Send the POST request */
         xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      //	alert(szFullURL);
         //xmlhttp.send(szURLParams);
		 xmlhttp.send("url=" + escape(szFullURL));
    }
}


function promo_searchhandler_quick(xohttp, xszCSSID)
{	
	
    promo_cleardiv(xszCSSID);
	
	xohttp = xohttp.replace(/\n/,"");
	xohttp = xohttp.replace(/\t/,"");
	
	
	try //Internet Explorer
	  {	
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async="false";
	  xmlDoc.loadXML(xohttp);
	  }
	catch(e)
	  {
	  try //Firefox, Mozilla, Opera, etc.
	  {
	  parser=new DOMParser();
	  xmlDoc=parser.parseFromString(xohttp,"text/xml");
	  }
	  catch(e)
	  {
	  alert(e.message);
	  return;
	  }
	}
	//alert(xmlDoc.getElementsByTagName("product")[0].getAttribute("id"));
	//alert(xmlDoc.getElementsByTagName("product").length);
	strcontent="";
	cntarr=xmlDoc.getElementsByTagName("product").length;
	//alert(cntarr);
    for(i=0;i<cntarr;i++)
	{
		if(i==0)
			strcontent="<p ><input type='checkbox' class='checkbox' value='" +xmlDoc.getElementsByTagName("product")[i].getAttribute("id")+"' name='keywords[]' >&nbsp;"+xmlDoc.getElementsByTagName("product")[i].getAttribute("id")+"</p>";
		else
		{
			strcontent=strcontent+ "<p ><input type='checkbox' class='checkbox' value='" +xmlDoc.getElementsByTagName("product")[i].getAttribute("id")+"' name='keywords[]' >&nbsp;"+xmlDoc.getElementsByTagName("product")[i].getAttribute("id")+"</p>";
		}
		
	}	
	var oElement = document.getElementById(xszCSSID);	
	//alert("xszCSSID"+xszCSSID);
	//alert("oElement"+oElement);
	//alert("categoryid"+document.frmAdvancedSearch.categoryid.value);
	if(document.frmAdvancedSearch.categoryid.value){
		//alert("!!!");
		quicksearchtogglecategory('categoryid',document.frmAdvancedSearch.categoryid.value)
		
	}
		oElement.innerHTML +=strcontent;

}
