
function WritePostsGrid(WriteToTable, sKeyWords, ClientTypeStr, 
	DateOneString, DateTwoString,
	SpecialCategoryID, SpecialTypeID, AreaID, FoodTypeID,
	ClientID, DateRange, Zip_Range, Zip_Range_Miles, bTextOnly,
	SpecialsPerPage, PageNumID, PageTotalID, SpecialsTotalID,
	Paging, IsClientEditPage, NoResultsFunction, OnCompleteFunction,
	SpecID, ShowDateColumn, ShowLogo){
    
    WritePostsGridPassURL(getRef("ProjectURL").value, WriteToTable, sKeyWords, ClientTypeStr,
	    DateOneString, DateTwoString,
	    SpecialCategoryID, SpecialTypeID, AreaID, FoodTypeID,
	    ClientID, DateRange, Zip_Range, Zip_Range_Miles, bTextOnly,
	    SpecialsPerPage, PageNumID, PageTotalID, SpecialsTotalID,
	    Paging, IsClientEditPage, NoResultsFunction, OnCompleteFunction,
	    SpecID, ShowDateColumn, ShowLogo)

}

function WritePostsGridPassURL(pURL, WriteToTable, sKeyWords, ClientTypeStr,  
	DateOneString, DateTwoString,
	SpecialCategoryID, SpecialTypeID, AreaID, FoodTypeID,
	ClientID, DateRange, Zip_Range, Zip_Range_Miles, bTextOnly,
	SpecialsPerPage, PageNumID, PageTotalID, SpecialsTotalID,
	Paging, IsClientEditPage, NoResultsFunction, OnCompleteFunction,
	SpecID, ShowDateColumn, ShowLogo){
	
	if (sKeyWords == "What are you looking for?") { sKeyWords = ""; }
	if (String(DateRange) == "0") { DateRange="False"; } else if (String(DateRange) == "1") { DateRange="True"; }
	if (String(bTextOnly) == "0") { bTextOnly="False"; } else if (String(bTextOnly) == "1") { DateRange="True"; }
	if (String(Paging) == "0") { Paging="False"; } else if (String(Paging) == "1") { DateRange="True"; }
	if (String(IsClientEditPage) == "0") { Paging="False"; } 
	
	var iPageNum = 0;
	if (Paging){
	    if (typeof ClearSpecialsPageRow == "function") { ClearSpecialsPageRow(); }
		if (typeof PageNumID != "undefined"){
			if (PageNumID != ""){ iPageNum = getRef(PageNumID).value; }
		}
	}
	
	var XmlDoc = zXmlDom.createDocument();
	var XmlHttp = zXmlHttp.createRequest();
	
	var ShowLogoCol = true;
	if (typeof ShowLogo == 'boolean'){ if (!ShowLogo){ ShowLogoCol = false; } }

	XmlHttpReady = function(){
		//try{
			if ((XmlHttp.readystate == 4) || (BrowserDetect.browser != "Explorer")){	
				//alert(XmlHttp.responseText.substring(3400));
				//alert(XmlHttp.responseText);
				XmlDoc.loadXML(XmlHttp.responseText);
				var doc = XmlDoc.documentElement;
				var SpecialIDs = doc.getElementsByTagName("SpecialID");
				var ClientNames = doc.getElementsByTagName("ClientName");
				var Types = doc.getElementsByTagName("Type");
				var Dates = doc.getElementsByTagName("Date");
				var Teasers = doc.getElementsByTagName("Teaser");
				var Actives = doc.getElementsByTagName("Active");
				var Address_Shorts = doc.getElementsByTagName("Address_Short");
				var TotalPages = Number(doc.getElementsByTagName("TotalPages")[0].text);
				var TotalResults = Number(doc.getElementsByTagName("TotalResults")[0].text);				
				//alert(TotalPages);
				//alert(TotalResults);
				if (Paging){
					if (typeof PageTotalID != "undefined"){
						if (PageTotalID != ""){
							getRef(PageTotalID).value = TotalPages;
						}
					}
				}
				if (typeof SpecialsTotalID != "undefined"){
					if (SpecialsTotalID != ""){
						getRef(SpecialsTotalID).value = TotalResults;
					}
				}
				
				var DebugMsg = doc.getElementsByTagName("DebugMsg")[0].text;
				//alert(DebugMsg);
								
				var	SpecialID	= ""; var ClientName = ""; var Type = ""; var Teaser = ""; var Address_Short = "";
				var SpecialsLength = SpecialIDs.length;
				
				if (Number(SpecialsLength) == 0){ //getRef(WriteToTable).innerHTML = "";					
					if (NoResultsFunction != ""){ NoResultsFunction(); }  return;
				}
				
				var s = '<table class="PostTable" cellpadding="3" cellspacing="0">';															
				var colclass = 'PostTableCol_Green';
				var count = 0;				
				var AddGoogleRow = false;
				for	(var i=0; i	< SpecialsLength; i++) {
					count =	count +	1;
					SpecialID = SpecialIDs[i].text;
					ClientName = ClientNames[i].text;
					Type = Types[i].text;
					DateDisplay = Dates[i].text;
					Teaser = Teasers[i].text;
					Address_Short = Address_Shorts[i].text;
					//if (i < 1) { alert(Address_Short); } // DEBUG
										
					s += '<tr>';
					if (colclass == 'PostTableCol_Green') { colclass = 'PostTableCol_Gray';; } else { colclass = 'PostTableCol_Green'; }
					if (IsClientEditPage){ if (Actives[i].text != "True"){colclass = 'PostTableCol_Red'; } }
					
					if (ShowLogoCol){ s += '<td width="190" align="center" class="' + colclass + '">' + ClientName + '</td>'; } // col 1
				
					s += '<td class="SpecialDescription ' + colclass + '" style="width:100px;font-weight:bold;">'; // col 2 // padding-top:10px;padding-bottom:10px;
//					if (!ShowDateColumn){s += ' width="140">';}
//					else{s += ' width="95">';}
                    
                    // every specialtypeid passed to this function needs to be the specialtypeid of the site
                    // or change the webservice to return complete html for this td....
                    if (SpecialTypeID == 0){ s += '<div style="padding-bottom:5px;">' + Type + '</div>'; }
					if (ShowDateColumn){s += '<div class="General" style="padding-bottom:5px;">' + DateDisplay + '</div>';}
					if (Address_Short != ""){ s+= '<div style="padding-bottom:5px;">' + Address_Short + '</div>';}
					s += '</td>'; // end col 2
//					if (ShowDateColumn){s += '<td class="General" style="width:95px;padding-left:25px;">' + DateDisplay + '</td>'; }
					
					s += '<td class="SpecialHorizontalDesc ' + colclass + '">' + Teaser + '</td>'; // col3
					s += '</tr>';
					
					if ((i == 4) || (i == 9)) { // add google row
					    try {
					        s += '<tr><td colspan="3" class="SpecialDescription_GoogleRow">' + PostsGrid_GetGoogleIFrame(sKeyWords) + '</td></tr>';
					    }catch (GoogleAd_exc) {}					
					}
				}
				
				if (Paging){ if (TotalResults > SpecialsPerPage){AddSpecialsPageRow();} else{ClearSpecialsPageRow();} }
			
				getRef(WriteToTable).innerHTML = s;
				
				if (OnCompleteFunction != ""){ OnCompleteFunction(); }				
			}
		/* }catch (exception){alert(exception);} */	
	}
	
	if(BrowserDetect.browser != "Explorer"){XmlHttp.onload = XmlHttpReady;}
	else{XmlHttp.onreadystatechange = XmlHttpReady;}
	
	var url= pURL + "Specials/SpecialsService.asmx/GetGridDataSet?";
	var qs = "KW=" + sKeyWords;
	qs += "&CTS=" + ClientTypeStr;
	qs += "&D1=" + DateOneString;
	qs += "&D2=" + DateTwoString;
	qs += "&SCID=" + SpecialCategoryID;
	qs += "&STID=" + SpecialTypeID;
	qs += "&AID=" + AreaID;
	qs += "&FTID=" + FoodTypeID;
	qs += "&CID=" + ClientID;
	qs += "&DR=" + DateRange;
	if (Zip_Range.length != 5) { Zip_Range = ""; }
	if (Zip_Range == "-ZIP-") { Zip_Range = ""; }
	qs += "&ZR=" + Zip_Range;
	qs += "&ZRM=" + String(Zip_Range_Miles); 	
	qs += "&TextOnly=" + bTextOnly;
	if (IsClientEditPage){ qs += "&ICEP=True"; }
	else{ qs += "&ICEP=False"; }
	qs += "&SID=" + SpecID;
	if (Paging){qs += "&P=True";}
	else{qs += "&P=False";}
	qs += "&SPP=" + SpecialsPerPage;	
	qs += "&PN=" + iPageNum;
	url += qs;
	//alert(qs);
	//alert(url);
	
	XmlHttp.open("GET", url, true);
	XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	XmlHttp.send(qs);
}

function PostsGrid_GetGoogleIFrame(sKeyWords) {
    var gframe = "<iframe src=\"" + document.getElementById("ProjectURL").value + "include/HomeControls/GoogleAZRow.aspx";
    try {if(String(typeof sKeyWords)=="string"){if(sKeyWords != ""){gframe+="?s="+String(sKeyWords).replace("?", "").replace("@", "");}}}catch(KeyWordAdd_exc) {}
    gframe += "\" frameborder=\"0\" scrolling=\"no\" class=\"SpecialDescription_GoogleRow_IFrame\"></iframe>"
    return gframe;
}

