function place(thisdog)
{
 var show = "main"; //ASSUME MAIN

 //YARD - If thisdog.Key is in your cookie
   var list = "";
   var index = list.indexOf(thisdog.Key);
   if (index >= 0){//found in array, show in yard
	show = "yard";
   }
   
 //If dog should not be shown at all (because of dates)
   if (thisdog.WStart ==0) { show = ""; }

 //or if set to show in future, or if listing has expired past enddate
   todayDate = new Date(); 
   startDate = new Date(thisdog.WStart);
   endDate = new Date(thisdog.WEnd);

     if (todayDate.getTime() < startDate.getTime()){ show = ""; }	
     if (todayDate.getTime() > endDate.getTime())  { show = ""; }	
     if (thisdog.HWStatus !="HW+"){show="";}
	
 //if (show == "yard") { addtoYard(thisdog);  }
 if (show == "main") { addtoMain(thisdog);  }

}


function addtoMain(d){    //Adds Dog to Main section, building HTML

	//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)    
    mainstr += "<tr><td width=160 bgcolor=white>";
    mainstr += "<table  cellpadding=0 border=0 style='border-style: hidden' bgcolor=white width='100%'><tr><td bgcolor=white>";
    mainstr += "<img border=0 src=2007Dogs/" + d.Key +".jpg width=180 onerror=\"this.onerror=null;this.src='./2007Dogs/NoPictureYet.jpg';\">";
    mainstr += "</td></tr>";
    mainstr += "<tr><td align=center class='style10' bgcolor=white><b>";
    mainstr += d.Name + "</b></td></tr></table>";
    mainstr += "</td>";
    
    //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 += "&nbsp;";
    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;");

	//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 += "***Not Available***</font></span>";
		//mainstr += "***Expected Availability - " + d.AvailDate + "***</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>";
    }

    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></tr>";


    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>";
    if (d.HWStatus =="HW+"){
       mainstr += "    <font size=1>&nbsp;<a href=DonateFromAvailablePage.htm"
       mainstr += "?" + d.Name + "%20(" + d.Key + ")>"
       mainstr += "<img border=0 align=absmiddle src=./images/BrokenHeart.gif title='Make a Donation to Mend a Heart'><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
    
}



function showAllDogs(dog){
 str = "";
 var yardcnt = 0;
 for(i=0;i<dog.length;i++) //loop all dogs
   {
    place(dog[i]); //Place into main, yard or nowhere variables
   }
    //Render page with main and yard sections
    document.getElementById("MainDog").innerHTML = mainstr;
    if (yardstr == "") {
    		yardstr = "<font color=white>There are currently no dogs in the yard.</font><br><br>";
	}
	else
	{
	
	  yardstr += "</table>";  
	  yardstr += "<br><font color=white size=3><b>Click any dog's picture to release that dog from the yard.</font></b>"
	  yardstr += "<br><br><font size=3 color=white><b>Or click <b><a name=releaseall onclick=\"return btnRelease_onclick()\" style='cursor:hand'><font color=white size=4>HERE</font></a></b> to Release All Dogs From Yard</font></b>";
	}
    //document.getElementById("YardDog").innerHTML = yardstr;
    mainstr = "";
    yardstr = "";
}
  
  
  
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 sortByAge(a, b) {
	if (a.WDOB==undefined || a.WDOB.indexOf("/") < 1){
    x = 0;
   }
   else
   {
   x = new Date(a.WDOB).getTime();
   }
   if (b.WDOB==undefined || b.WDOB.indexOf("/") < 1){
    y = 0;
   }
   else
   {
   y = new Date(b.WDOB).getTime();
   }
   
   if (document.getElementById("btnAge").value == "Sort by Age +")
   {   
	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); 
} 