function simplePost(url,callBack,params)
{
 var common_request=document.all?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
 common_request.onreadystatechange=function()
 {
  if(common_request.readyState==4)
  {
   if(common_request.status==200)
   { 	
         try{eval(callBack);}catch(e){}
   }
  /* else if(common_request.status==500)
    alert(serverError);
   else
    alert(connectionError);*/
    
  }
 }

 common_request.open("POST",url,true);
 common_request.setRequestHeader("content-type","application/x-www-form-urlencoded");
 common_request.setRequestHeader("Connection", "close"); 
 common_request.setRequestHeader("Content-length", params.length);
 common_request.send(params);
}

function favoriteLink(memberId){
	var loginStatus = SNI.Community.UR.logged_in;
	if( loginStatus || loginStatus == "true"){
		var serverURL = SNI.RZ.globalServerURL;
		//var memberId = SNI.Community.UR.ViewingMemberId;
		var url="/rzservices/rest/member/favorites";
		var params = "op=add&type=chef&id="+memberId; 
		simplePost(url,"afterfavoriteLink(common_request)",params);
	}else{
		document.location = getLoginPageURL()+"";
	}
}

function getLoginPageURL(){
	var logURL = SNI.Community.UR.globalLoginURL;
	logURL += "?DEST_URL="+ escape(document.location.href);
	return logURL;
}

function afterfavoriteLink(request)
{
	//alert(request.responseText);
	var curObjVal = "";
	var obj = "";
	var chefObj =request.responseXML.getElementsByTagName("chef");
	
	if(chefObj && chefObj.length>0){
		var obj = chefObj.item(0);
		curObjVal = obj.getAttribute("number");
		document.getElementById('favthischef').style.display="none";
		document.getElementById('addedtofav').style.display="block";
	}
}
function showMoreColl(show,hide) {	
  document.getElementById(show).style.display = 'block';
  document.getElementById(hide).style.display = 'none';
  var showref = show + 'href';
  var hideref = hide + 'href';
  document.getElementById(showref).className = 'selected';
  document.getElementById(hideref).className = ""; 
  
}
function showTop3(obj) {
	var id = obj.id + "div";
	document.getElementById(id).style.display = 'block';
}
function showCollection(obj) {	
	document.getElementById('searchshowmore').style.display = 'block';
	var morediv = obj.id + 'div';
	document.getElementById(morediv).style.display = 'none';
}

function assetStats(){
	var serverURL = SNI.RZ.globalServerURL;
	var url="/cp_asset_stats.do";
 	if( document.getElementById("globalAssetId") ){
  		var assetId = document.getElementById("globalAssetId").value;
  		var assetType = document.getElementById("globalAssetType").value;
  		var params = "aid="+escape(assetId)+"&at="+escape(assetType);
  		simplePost(url,"",params);
 	}
}

// member search page
function addToFavourite(mid){
var loginStatus = SNI.Community.UR.logged_in;	
	if(loginStatus=="true"){
		var serverURL = SNI.RZ.globalServerURL;	
		var url=serverURL+"/rzservices/rest/member/favorites";			
		var params = "op=add&type=chef&id="+mid; 		
		simplePost(url,"afteraddToFavourite(common_request,'"+mid+"')",params);
	}else{	
		document.location = getLoginPageURL()+"";
	}
}
function afteraddToFavourite(req,mid) {
        var errors=req.responseXML.getElementsByTagName('exception');
        var htmlcon = ""      
        document.getElementById("msg_"+mid).innerHTML = "";  
        if (!errors.length) {              
              htmlcon = 'Added to <a href="/members/favorites.php">Favorites</a>!';
        }
        else {
              htmlcon = 'Please <a href="'+getLoginPageURL()+'">login</a> to use this feature.';
        }
        document.getElementById("msg_"+mid).innerHTML = htmlcon;  
}
function getZMailURL(mid){
	var serverURL = SNI.RZ.globalServerURL;		
	var logURL = SNI.Community.UR.globalLoginURL;
	var zmailURL = serverURL+"/mail/compose?to="+mid;
	logURL += "?DEST_URL="+ escape(zmailURL);
	return logURL;
}
function sendZMail(mid){
var loginStatus = SNI.Community.UR.logged_in;	
	if(loginStatus=="true"){
		var serverURL = SNI.RZ.globalServerURL;		
		document.location = serverURL+"/mail/compose?to="+mid;
	}else{
		document.location = getZMailURL(mid)+"";
	}
}

function removeDivTitleOnclickEvent( divId, cObj){
    var obj = document.getElementById(divId);
	if( obj != null ){
	 	//obj.title="";
	 	//obj.onClick=null;
	 	obj.href="";
	}
	if(document.all)
		parent.location = cObj.href;
	else
		return false;
}


$(document).ready(function () {
  $("input.remember").live("click",function () {
    if( $(this).is(":checked") ) {
      $("input.remember").not( $(this) ).attr("checked","checked");      
    } else {
      $("input.remember").not( $(this) ).removeAttr("checked");
    }
  });
});