function _O(o){return document.getElementById(o);}
var _U=new function U(){}

/**** frame control ****/
function autoIframe(frame){
    var high=_O("header").style.height.split("px")[0];//get height of header
    var objToResize = (frame.style) ? frame.style : frame;
    objToResize.height=(window.innerHeight)?window.innerHeight-high:document.body.clientHeight-high;
	(frame.src.split("?")[0].split("/")[3]=='DisplayPage')?_U.lastURL=frame.src:'';
}

/************ user ratings ************/
function showStars(stars,msg,mouseout){
	var msgBox=_O('msgBox');	
	var dec=stars.split(".");
	
	//check if user is logged or not
	//mouseout is used here ot make sure no status messages appear when user moves away from ratings - we want to display the actual rating
	if(_U.isUserLogged==0 && mouseout!=1)
		msg='login to rate';
	else if(_U.alreadyRated==1 && mouseout!=1)
		msg='already rated';
	
	//pre set stars - start with full until .5 is reached then continue with empties
	var i=1;
	for(i=1;i<=dec[0];i++)
		_O('star'+i).src='work/community/images/full_star.gif';
	if(dec[1]>=5){
		_O('star'+i).src='work/community/images/half_star.gif';i++;
	}		
	for(j=i;j<=5;j++)
		_O('star'+j).src='work/community/images/empty_star.gif';
	
	msgBox.innerHTML=msg;
}
//this resets the ratings stars
function showRating(){
	showStars(_U.rating+'',_U.numRatings+' ratings',1);
}
function rateSite(stars){
	if(_U.alreadyRated!=1 && _U.isUserLogged!=0){
		_Ajax.sendRequest("RateWebsite?websiteID="+_U.websiteID+'&rating='+stars,"rateSiteSuccess(req,"+stars+")")
	}
}
function rateSiteSuccess(req,stars){
	if(req.responseText=='ratesuccess'){
		_U.rating=((_U.rating*_U.numRatings)+stars)/parseInt(_U.numRatings+1);
	    _U.numRatings++;
		_U.alreadyRated=1;
		showStars(_U.rating+'','thank you',1);
	}
}
/************ toggleMenu controls ************/
function toggleMenu(span){
	var frame=_O('container');
	var id=span.id.split("_");
	var menu=['comment','share'];
	
	_U.lastURLFlag=0;
	for(i=0;i<menu.length;i++){
		var op=_O(menu[i]+'_open');
		var cl=_O(menu[i]+'_close');
		
		if(cl.style.display==''){
			_U.lastURLFlag=1;
			op.style.display='';
			cl.style.display='none';
		}	
	}
	
	if(id[1]=='open'){
		var innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		try{if(_U.lastURLFlag!=1)_U.lastURL=innerDoc.location+'';}catch(ex){}
		span.style.display='none';
		_O(id[0]+'_close').style.display='';
	}else{
		span.style.display='none';
		_O(id[0]+'_open').style.display='';
	}
	
	if(span.id=='comment_open')frame.src='WebsiteComments?websiteID='+_U.websiteID;
	else if(span.id=='share_open')frame.src='CommunityShareWebsite?websiteID='+_U.websiteID;
	else frame.src=_U.lastURL;
	
}

/************** favorites ***************/
function addFavorite(){
	if(_U.alreadyFavorite!=1)
		_Ajax.sendRequest("AddFavoriteWebsite?websiteID="+_U.websiteID,"_O('favoriteBox').innerHTML='favorite added';_U.alreadyFavorite=1;");	
}




