// JavaScript Document

// equal height
function equalHeight(group) {
   tallest = 0;
   group.each(function() {
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
         tallest = thisHeight;
      }
   });
   group.height(tallest);
}
$(document).ready(function() {
   equalHeight($(".equalheight"));
});

/*$(document).ready(function() {
	equalHeight($(".blog #column-left .border"));
	equalHeight($(".blog #column-right .border"));
});*/

// equal height 2
function equalHeight2(group) {
   tallest = 0;
   group.each(function() {
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
         tallest = thisHeight;
      }
   });
   group.height(tallest);
}
$(document).ready(function() {
   equalHeight2($(".equalheight2"));
});

/*$(document).ready(function() {
	equalHeight2($(".blog #archive-left .border"));
	equalHeight2($(".blog #archive-right .border"));
});*/

// equal height 3
function equalHeight3(group) {
   tallest = 0;
   group.each(function() {
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
         tallest = thisHeight;
      }
   });
   group.height(tallest);
}
$(document).ready(function() {
   equalHeight3($(".equalheight3"));
});

sfHover = function() {
	var sfEls = document.getElementById("primary-navigation").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//Below function use to give add to favorite & remove favorite functionality 
function addFavorite(detailId, action)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}

var url=action+"&detailId="+detailId;

xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if(xmlhttp.readyState==4)
{
	var strResp  = xmlhttp.responseText.split("#");
	var detailid = strResp[0];
	var total    = strResp[1];  
	
	var save_favorite = "saveFavorite_"+detailid;
	var remove_favorite = "removeFavorite_"+detailid;
	
//show popup
document.getElementById('addpopup').style.display = "block";
document.getElementById(save_favorite).style.display = "none";
document.getElementById(remove_favorite).style.display = "block";
document.getElementById('totalFav').innerHTML  = "("+total+")";

setTimeout("closeDiv('addpopup')",2000);
}
}

//close the popup div
function closeDiv(divname)
{
	document.getElementById(divname).style.display = "none";
}

//function use to remove favorite from the list 
function removeFavorite(detailId, action)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}

var url=action+"&detailId="+detailId;

xmlhttp.onreadystatechange=stateRemove;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateRemove()
{
if(xmlhttp.readyState==4)
{
	var strResp  = xmlhttp.responseText.split("#");
	var detailid = strResp[0];
	var total    = strResp[1];  

	var save_favorite = "saveFavorite_"+detailid;
	var remove_favorite = "removeFavorite_"+detailid;
	
//show popup
document.getElementById('removepopup').style.display = "block";
document.getElementById(remove_favorite).style.display = "none";
document.getElementById(save_favorite).style.display = "block";
document.getElementById('totalFav').innerHTML  = "("+total+")";

setTimeout("closeDiv('removepopup')",2000);
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
