function addtoMain(d){    //Adds Dog to Main section, building HTML

   dogcnt = dogcnt + 1;
    
   if (dogcnt == 1){ //first Dog - start row
     mainstr += "<tr>";
   }
   
   if (dogcnt == 2 ) {//Second Dog
   //mainstr += "</td>";
   }
   
   if (dogcnt == 3){
   //mainstr += "</td>";
   }

	//str += "MAIN DOG= " + d.Key + "<BR>";
    //mainstr += "<hr>";
    mainstr +="<a name=" + d.Key + "></a>";
    //mainstr += "<table border=0 style='border-style: hidden' cellpadding=4>"; //main table
    
    //Show Picture(s)    
    //CELL
    mainstr += "<td width=210 bgcolor=white valign=top>";
    //INNER TABLE
    mainstr += "<table cellpadding=2 cellspacing=2 border=0 style='border-style: hidden' bgcolor=white width='100%'><tr><td bgcolor=white>";
    mainstr += "<img border=0 src=2007Dogs/" + d.Key +".jpg width=220 onerror=\"this.onerror=null;this.src='./2007Dogs/NoPictureYet.jpg';\">";
    mainstr += "</td></tr>";
    mainstr += "<tr><td align=center class='style10' bgcolor=white><b><font color=black>";
    
    if (d.NewName > "") {
		mainstr += d.NewName + " <br><font size=2><i>formerly known as " + d.Name + "</i></font>";
		}	
    else
		{
		mainstr += d.Name ;
		}
    
    //Description Column
    //mainstr += "<td cellpadding=0 cellspacing=0 style='background-color: #FFEEDD; border-style: hidden'>";
    //mainstr += "<table style='border-style:hidden;border-color:black' border=0 width=640 height='100%'>";
    //mainstr += "<td cellpadding=0 cellspacing=0 valign=top style='background-color: #336699;color: #F3EE8f;border-color:black'>";
    //mainstr += "<font size=4><b>" + showDogAge(d.WDOB, d.WRange, d.WOverride);
    mainstr += "<br><font size=2>";
    mainstr += d.Gender + " "; 
    
    mainstr += d.Breed;
    if (d.Breed == "Golden") {  mainstr += "&nbsp;Retriever&nbsp;";     }
    if (d.Breed == "Lab") {     mainstr += "rador&nbsp;Retriever&nbsp;";  }
    if (d.Mix == "Yes"){  	    mainstr += "Mix";    }
    //document.write("&nbsp;/&nbsp;Color:&nbsp;"+d.Color+"&nbsp;");

	if (d.Age != ""){
	mainstr += "<br>Rescued @ Age of " + d.Age;
	}

	//AVAILABLE SOON LABEL
    if (d.State =="1. Not Available")
    {
		mainstr += "<br><span style='background-color: #FFFF00; font-style:italic'><font size='3' color=black>";
		mainstr += "***Available Soon***</font></span>";
    }

    //ADOPTION PENDING LABEL
    if (d.State =="99. Spoken For")
    {
		mainstr += "<br><span style='background-color: #FFFF00; font-style:italic'><font size='3' color=black>";
		mainstr += "***Adoption Pending***</font></span>";
    }

	//CLOSE INNER TABLE
	mainstr += "</font></b></td></tr></table>";
    //mainstr += "</td>";
    
    //mainstr += "</b></font></td>";
    //mainstr += "<td valign=top align=right style='background-color: #336699;color: #F3EE8f;'>";
      
    //mainstr += "<a href=\"mailto:?subject=About&nbsp;GRRA&nbsp;Adoptee&nbsp;" + d.Name;
    //mainstr += "&body=I%20thought%20you%20might%20be%20interested";
    //mainstr += "%20in%20this%20dog%20I%20saw%20on%20the%20Golden%20Retriever%20Rescue%20of%20Atlanta's%20Website!";
    //mainstr += "%0A%0AClick%20the%20following%20link%20to%20visit%20the%20GRRA%20Available%20Dogs%20page%20and%20see%20" + d.Name + "%20for%20yourself.";
    //mainstr += "%0A%0Ahttp:\\\\www.grra.com\\AvailDogs.html\%23" + d.Key;
    //mainstr += "\" title='Click to Send An Email About This Dog'><font color=yellow><b>E-mail A Friend</b></font></a>";
    
    //mainstr += "&nbsp;&nbsp;|&nbsp;&nbsp;<a name='btnHide' style='cursor:hand' title='Click to Hide this Dog at the Yard on the bottom of the page' onclick='return btnHide_onclick(\"" + d.Key + "\")'><font color=yellow><b><u>Hide Dog</u></b></a></font>&nbsp;&nbsp;";
    
    //mainstr += "</td>";


    //mainstr += "<td style='background-color: #FFEEDD;' colspan=2>"+d.Bio;
    //mainstr += " <a href=mailto:adoption@GRRA.com?subject=About&nbsp;Adoptee&nbsp;" + d.Name + "&" + " title='Click to E-mail about this dog'>adoption@GRRA.com</a></span>";
    //mainstr += "    <font size=1>(Contribute&nbsp;to&nbsp;GRRA&nbsp;<a href=Donate.htm><img border=1 align=absmiddle src=./images/MakeADonation.jpg title='Click to Donate'></a>)</font>";
        
    //mainstr += "</td></tr></table>";
    //mainstr += "</td></tr></table>";//outer table
   

   if (dogcnt == 3){ //End Row
	mainstr += "</td></tr><tr><td colspan=3><hr></td></tr>";
	dogcnt = 0;
   }
   else
   { //End Cell
   mainstr += "</td>";
   }
   
    
}


function showAllDogs(dog){
 str = "";
 var dogcnt = 0;
 for(i=0;i<dog.length;i++) //loop all dogs
   {
   addtoMain(dog[i]);
   }
    //Render page with main and yard sections
    mainstr = "<table>" + mainstr + "</table>";
    document.getElementById("Dogs").innerHTML = mainstr;
    mainstr = "";
}
  
  
  
function sortByBreed(a, b) {
    var x = a.Breed.toLowerCase()+a.Name.toLowerCase();
    var y = b.Breed.toLowerCase()+b.Name.toLowerCase();
   if (document.getElementById("btnBreed").value == "Sort by Breed +")
    {    
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    else
    {
    return ((x > y) ? -1 : ((x < y) ? 1 : 0));
    }
}

function sortByName(a, b) {
    var x = a.Name.toLowerCase();
    var y = b.Name.toLowerCase();
    if (document.getElementById("btnName").value == "Sort by Name +")
    {
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
    else
    {
    return ((x > y) ? -1 : ((x < y) ? 1 : 0));
    }
}

function sortByAdopted(a, b) {
	if (a.Closed==undefined || a.Closed.indexOf("/") < 1){
    x = 0;
   }
   else
   {
   x = new Date(a.Closed).getTime();
   }
   if (b.Closed==undefined || b.Closed.indexOf("/") < 1){
    y = 0;
   }
   else
   {
   y = new Date(b.Closed).getTime();
   }
   
   if (document.getElementById("btnAdopted").value == "Sort by Adopted Date +")
   {   
	return ((x > y) ? -1 : ((x < y) ? 1 : 0));
	}
	else
   {
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
   }
}


function stripHTML(oldString) {

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
   
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              inTag = false;
              i++;
        }
   
        if(!inTag) newString += oldString.charAt(i);

   }

   return newString;
}

function randOrd(){
return (Math.round(Math.random())-0.5); 
} 