var boxHTML='';
var PopBox;
						
var calendar_offsetTop = 3;		
var calendar_offsetLeft = -130;

var alertTimerId = 0;
var hover = 0;



function OpenPopUPPortals(Box,obj,Src,RealName,ProfileLink,status,School,City,AccID,UserID)
{		
	if(status=="Parents")
	{
		status="Parent";
	}
	if(status=="Teacher&Parent"||status=="Parent&Teacher"||status=="Parents&Teacher"||status=="teacher&parent")
	{
		status="Teacher & Parent";
	}
	School=School.replace("'","");
	Box.style.backgroundColor = '#ffffff';
	PopBox=Box;
	var Userdetails="'"+obj.innerHTML+"'";
	var ProfileNewsLink = engFriends.CreateProfileNewsLink(UserID).value;
	
	/* HTML Formated div here*/
	boxHTML='<div class="minidiv" height="140px">';
	boxHTML+='<table  border="0" cellspacing="0" cellpadding="0" class="poptable"  style="width:300px;">';
	boxHTML+='<tr style="border-style: none;border-width: 0px 0px 0px 0px;height:80px;"><td width="30%" class="popimage" style="border-style: none;border-width: 0px 0px 0px 0px;"><img src="/imageresize.aspx?filename='+Src+'&width=80&height=80"></td>';
	boxHTML+='<td valign="top" style="border-style: none;border-width: 0px 0px 0px 0px;" width="65%">';
	boxHTML+='<div>';
	boxHTML+='<a class="pop-link" href="'+ProfileLink+'">'+RealName+'</a>';
	if(status.length>0)
		boxHTML+='<p class="status">'+status+(School.length>0?', '+School:'')+'</p>';
	//if(School.length>0)
		//boxHTML+='<p class="School">'+School+'</p>';
	if(City.length>0)
		boxHTML+='<p class="City">'+City.replace(',',',')+'</p>';
	//boxHTML+='<p class="location">'+Country+'</p>';
	boxHTML+='</div>';
	boxHTML+='</td style="border-style: none;border-width: 0px 0px 0px 0px;"><td valign="top" class="closetd" style="border-style: none;border-width: 0px 0px 0px 0px;padding-top:0px;" width="5%"><div width="100px" style="padding-top:8px;"><img src="/images/img_close.gif" onclick="hover=0;HidePopUp()" align="top">&nbsp;&nbsp;</div></td>';
	boxHTML+='</tr>';
	var res2=engFriends.chkIsFriend(AccID);
	var isFriend=res2.value;
	if(!isFriend)
	{
		boxHTML+='<tr class="sectionlnk" style="border-style: none;border-width: 0px 0px 0px 0px;"><td colspan="3" style="border-style: none;border-width: 0px 0px 0px 0px;"><a href="'+ProfileLink+'" title="View Profile"><img src="/images/headers/background/profile.gif" alt="View Profile"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileNewsLink+'" title="View News"><img src="/images/headers/background/news.gif" alt="View News"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=photo" title="View Photos"><img src="/images/headers/background/photos.gif" alt="View Photos"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=blog" title="View Blogs"><img src="/images/headers/background/blog.gif" alt="View Blogs"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=calendar" title="View Calendar"><img src="/images/headers/background/events.gif" alt="View Calendar"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=widget"  title="View Widgets"><img src="/images/headers/background/widget.gif" alt="View Widgets"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=friends"  title="View Friends"><img src="/images/headers/background/friends.gif" alt="View Friends"></a></td></tr>';
	}
	else
	{
		boxHTML+='<tr class="sectionlnk" style="border-style: none;border-width: 0px 0px 0px 0px;"><td colspan="3" style="border-style: none;border-width: 0px 0px 0px 0px;"><a href="'+ProfileLink+'" title="View Profile"><img src="/images/headers/background/profile.gif" alt="View Profile"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileNewsLink+'" title="View News"><img src="/images/headers/background/news.gif" alt="View News"></a>&nbsp;&nbsp;&nbsp;<a href="javascript:OpenModelDiv('+UserID+','+Userdetails+');" title="Send Message"><img src="/images/headers/background/sendmessage.gif" alt="Send Message"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=photo" title="View Photos"><img src="/images/headers/background/photos.gif" alt="View Photos"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=blog" title="View Blogs"><img src="/images/headers/background/blog.gif" alt="View Blogs"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=calendar" title="View Calendar"><img src="/images/headers/background/events.gif" alt="View Calendar"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=widget"  title="View Widgets"><img src="/images/headers/background/widget.gif" alt="View Widgets"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=friends"  title="View Friends"><img src="/images/headers/background/friends.gif" alt="View Friends"></a></td></tr>';
	}
	boxHTML+='</table>';
	boxHTML+='</div>';
	Box.style.zIndex='500';
	Box.style.position='absolute';
	
	positionPopup(obj,Box,false);
	//self.alertTimerId = setTimeout('HidePopUp()', 3000);
	hover = 1;
	addEvent(Box,"mouseout",Popmouseout);
	addEvent(Box,"mouseover",Popmouseover);
	Box.innerHTML=boxHTML;
}
var Box;
var obj;
var Src;
var RealName;
var ProfileLink;
var status;
var School;
var City;
var AccID;
var UserID;
var ProfileNewsLink;

function OpenPopUP(Box1,obj1,Src1,RealName1,ProfileLink1,status1,School1,City1,AccID1,UserID1)
{		
	Box = Box1;
	obj = obj1;
	Src = Src1;
	RealName = RealName1;
	ProfileLink = ProfileLink1;
	status = status1;
	School = School1;
	City = City1;
	AccID = AccID1;
	UserID = UserID1;
	ProfileNewsLink = engFriends.CreateProfileNewsLink(UserID).value;
	engFriends.chkIsFriend(AccID, callback_OpenPopUP);
	
}

function callback_OpenPopUP(res)
{
	if(status=="Parents")
	{
		status="Parent";
	}
	if(status=="Teacher&Parent"||status=="Parent&Teacher"||status=="Parents&Teacher"||status=="teacher&parent")
	{
		status="Teacher & Parent";
	}
	School=School.replace("'","");
	Box.style.backgroundColor = '#ffffff';
	PopBox=Box;
	var Userdetails="'"+obj.innerHTML+"'";
	
	/* HTML Formated div here*/
	boxHTML='<div class="minidiv myAccountPopup" height="140px" >';
	boxHTML+='<table  border="0" cellspacing="0" cellpadding="0" class="poptable" style="width:300px;">';
	boxHTML+='<tr style="border-style: none;border-width: 0px 0px 0px 0px;height:80px;"><td width="30%" class="popimage" style="border-style: none;border-width: 0px 0px 0px 0px;"><img src="'+Src+'"></td>';
	boxHTML+='<td valign="top" style="border-style: none;border-width: 0px 0px 0px 0px;" width="65%">';
	boxHTML+='<div>';
	boxHTML+='<a class="pop-link" href="'+ProfileLink+'">'+RealName+'</a>';
	if(status.length>0)
		boxHTML+='<p class="status">'+status+(School.length>0?', '+School:'')+'</p>';
	//if(School.length>0)
		//boxHTML+='<p class="School">'+School+'</p>';
	if(City.length>0)
		boxHTML+='<p class="City">'+City.replace(',',',')+'</p>';
	//boxHTML+='<p class="location">'+Country+'</p>';
	boxHTML+='</div>';
	boxHTML+='</td style="border-style: none;border-width: 0px 0px 0px 0px;"><td valign="top" class="closetd" style="border-style: none;border-width: 0px 0px 0px 0px;padding-top:0px;" width="5%"><div width="100px" style="padding-top:8px;"><img src="/images/img_close.gif" onclick="hover=0;HidePopUp()" align="top">&nbsp;&nbsp;</div></td>';
	boxHTML+='</tr>';
	//boxHTML+='<table style="width:400px; border-style: none;border-width: 0px 0px 0px 0px;">';
	var isFriend=res.value;
	if(!isFriend)
	{
		boxHTML+='<tr class="sectionlnk" style="border-style: none;border-width: 0px 0px 0px 0px;"><td colspan="3" style="border-style: none;border-width: 0px 0px 0px 0px;"><a href="'+ProfileLink+'" title="View Profile"><img src="/images/headers/background/profile.gif" alt="View Profile"></a>&nbsp;&nbsp;&nbsp;<a Title="View News" href="'+ProfileNewsLink+'"><img src="/images/headers/background/news.gif" alt="View News"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=photo" title="View Photos"><img src="/images/headers/background/photos.gif" alt="View Photos"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=blog" title="View Blogs"><img src="/images/headers/background/blog.gif" alt="View Blogs"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=calendar" title="View Calendar"><img src="/images/headers/background/events.gif" alt="View Calendar"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=widget"  title="View Widgets"><img src="/images/headers/background/widget.gif" alt="View Widgets"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=friends"  title="View Friends"><img src="/images/headers/background/friends.gif" alt="View Friends"></a></td></tr>';
	}
	else
	{
		boxHTML+='<tr class="sectionlnk" style="border-style: none;border-width: 0px 0px 0px 0px;"><td colspan="3" style="border-style: none;border-width: 0px 0px 0px 0px;"><a href="'+ProfileLink+'" title="View Profile"><img src="/images/headers/background/profile.gif" alt="View Profile"></a>&nbsp;&nbsp;&nbsp;<a Title="View News" href="'+ProfileNewsLink+'"><img src="/images/headers/background/news.gif" alt="View News"></a>&nbsp;&nbsp;&nbsp;<a href="javascript:OpenModelDiv('+UserID+','+Userdetails+');" title="Send Message"><img src="/images/headers/background/sendmessage.gif" alt="Send Message"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=photo" title="View Photos"><img src="/images/headers/background/photos.gif" alt="View Photos"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=blog" title="View Blogs"><img src="/images/headers/background/blog.gif" alt="View Blogs"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=calendar" title="View Calendar"><img src="/images/headers/background/events.gif" alt="View Calendar"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=widget"  title="View Widgets"><img src="/images/headers/background/widget.gif" alt="View Widgets"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=friends"  title="View Friends"><img src="/images/headers/background/friends.gif" alt="View Friends"></a></td></tr>';
	}
	//boxHTML+='</table>';
	boxHTML+='</table>';
	boxHTML+='</div>';
	Box.style.zIndex='500';
	Box.style.position='absolute';
	
	positionPopup(obj,Box,false);
	
	//self.alertTimerId = setTimeout('HidePopUp()', 3000);
	hover = 1;
	addEvent(Box,"mouseout",Popmouseout);
	addEvent(Box,"mouseover",Popmouseover);
	Box.innerHTML=boxHTML;
}

function PopBlur()
{
	alert('hi');
}
function Popmouseout()
{
    //alert('out');
	self.alertTimerId = setTimeout('HidePopUp()', 1000);
	hover = 0;
}
function Popmouseover()
{
	//this.style.display="block";
	clearTimeout(self.alertTimerId);
	hover = 1;
}



function ShowBox(Box,obj,Src,RealName,ProfileLink,status,School,City,AccID)
{		
	School=School.replace("'","");
	Box.style.backgroundColor = '#ffffff';
	PopBox=Box;
	var Userdetails="'"+obj.innerHTML+"'";
	/* HTML Formated div here*/
	boxHTML='<div class="minidiv" height="140px">';
	boxHTML+='<table  border="0" cellspacing="0" cellpadding="0" class="poptable" >';
	boxHTML+='<tr style="border-style: none;border-width: 0px 0px 0px 0px;height:80px;"><td width="30%" class="popimage" style="border-style: none;border-width: 0px 0px 0px 0px;"><img src="\imageresize.aspx?filename='+Src+'&width=80&height=80"></td>';
	boxHTML+='<td valign="top" style="border-style: none;border-width: 0px 0px 0px 0px;" width="65%">';
	boxHTML+='<div>';
	boxHTML+='<a class="pop-link" href="'+ProfileLink+'">'+RealName+'</a>';
	if(status.length>0)
		boxHTML+='<p class="status">'+status.replace("'","")+'</p>';
	if(School.length>0)
		boxHTML+='<p class="School">'+School.replace("'","")+'</p>';
	if(City.length>0)
		boxHTML+='<p class="City">'+City.replace(',',' ')+'</p>';
	//boxHTML+='<p class="location">'+Country+'</p>';
	boxHTML+='</div>';
	boxHTML+='</td style="border-style: none;border-width: 0px 0px 0px 0px;"><td valign="top" class="closetd" style="border-style: none;border-width: 0px 0px 0px 0px;padding-top:0px;" width="5%"><div width="100px" style="padding-top:8px;"><img src="../images/img_close.gif" onclick="hover=0;HidePopUp()" align="top">&nbsp;&nbsp;</div></td>';
	boxHTML+='</tr>';
	boxHTML+='<tr class="sectionlnk" style="border-style: none;border-width: 0px 0px 0px 0px;"><td colspan="3" style="border-style: none;border-width: 0px 0px 0px 0px;"><a href="'+ProfileLink+'" title="View Profile"><img src="../images/headers/background/profile.gif" alt="View Profile"></a>&nbsp;&nbsp;&nbsp;<a href="javascript:OpenModelDiv('+AccID+','+Userdetails+');" title="Send Message"><img src="../images/headers/background/sendmessage.gif" alt="Send Message"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=photo" title="View Photos"><img src="../images/headers/background/photos.gif" alt="View Photos"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=blog" title="View Blogs"><img src="../images/headers/background/blog.gif" alt="View Blogs"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=calendar" title="View Calendar"><img src="../images/headers/background/events.gif" alt="View Calendar"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=widget"  title="View Widgets"><img src="../images/headers/background/widget.gif" alt="View Widgets"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=friends"  title="View Friends"><img src="../images/headers/background/friends.gif" alt="View Friends"></a></td></tr>';
	boxHTML+='</table>';
	boxHTML+='</div>';
	Box.style.zIndex='500';
	Box.style.position='absolute';	
	//Placeit(obj,Box);	
	//self.alertTimerId = setTimeout('HidePopUp()', 3000);
	hover = 1;
	addEvent(Box,"mouseout",Popmouseout);
	addEvent(Box,"mouseover",Popmouseover);
	positionPopup(obj,Box,true);
	Box.innerHTML=boxHTML;
}

function ViewPopUp(Box,obj,Src,RealName,ProfileLink,status,School,City,AccID,Username,UserID)
{		
	School=School.replace("'","");
	Box.style.backgroundColor = '#ffffff';
	PopBox=Box;
	var Userdetails="'"+Username+"'";
	/* HTML Formated div here*/
	boxHTML='<div class="minidiv" height="140px">';
	boxHTML+='<table  border="0" cellspacing="0" cellpadding="0" class="poptable" >';
	boxHTML+='<tr style="border-style: none;border-width: 0px 0px 0px 0px;height:80px;"><td width="30%" class="popimage" style="border-style: none;border-width: 0px 0px 0px 0px;"><img src="/imageresize.aspx?filename='+Src+'&width=80&height=80"></td>';
	boxHTML+='<td valign="top" style="border-style: none;border-width: 0px 0px 0px 0px;" width="65%">';
	boxHTML+='<div>';
	boxHTML+='<a class="pop-link" href="'+ProfileLink+'">'+RealName+'</a>';
	if(status.length>0)
		boxHTML+='<p class="status">'+status.replace("'","")+'</p>';
	if(School.length>0)
		boxHTML+='<p class="School">'+School.replace("'","")+'</p>';
	if(City.length>0)
		boxHTML+='<p class="City">'+City.replace(',',' ')+'</p>';
	//boxHTML+='<p class="location">'+Country+'</p>';
	boxHTML+='</div>';
	boxHTML+='</td style="border-style: none;border-width: 0px 0px 0px 0px;"><td valign="top" class="closetd" style="border-style: none;border-width: 0px 0px 0px 0px;padding-top:0px;" width="5%"><div width="100px" style="padding-top:8px;"><img src="../images/img_close.gif" onclick="hover=0;HidePopUp()" align="top">&nbsp;&nbsp;</div></td>';
	boxHTML+='</tr>';
	boxHTML+='<tr class="sectionlnk" style="border-style: none;border-width: 0px 0px 0px 0px;"><td colspan="3" style="border-style: none;border-width: 0px 0px 0px 0px;"><a href="'+ProfileLink+'" title="View Profile"><img src="../images/headers/background/profile.gif" alt="View Profile"></a>&nbsp;&nbsp;&nbsp;<a href="javascript:OpenModelDiv('+UserID+','+Userdetails+');" title="Send Message"><img src="../images/headers/background/sendmessage.gif" alt="Send Message"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=photo" title="View Photos"><img src="../images/headers/background/photos.gif" alt="View Photos"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=blog" title="View Blogs"><img src="../images/headers/background/blog.gif" alt="View Blogs"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=calendar" title="View Calendar"><img src="../images/headers/background/events.gif" alt="View Calendar"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=widget"  title="View Widgets"><img src="../images/headers/background/widget.gif" alt="View Widgets"></a>&nbsp;&nbsp;&nbsp;<a href="'+ProfileLink+'?type=friends"  title="View Friends"><img src="../images/headers/background/friends.gif" alt="View Friends"></a></td></tr>';
	boxHTML+='</table>';
	boxHTML+='</div>';
	Box.style.zIndex='500';
	Box.style.position='absolute';	
	//Placeit(obj,Box);	
	//self.alertTimerId = setTimeout('HidePopUp()', 3000);
	hover = 1;
	addEvent(Box,"mouseout",Popmouseout);
	addEvent(Box,"mouseover",Popmouseover);
	positionPopup(obj,Box,false);
	Box.innerHTML=boxHTML;
}


//href="myMessages/index.aspx?AccId='+AccID+'&User='+obj.innerHTML+'"
//href="javascript:OpenModelDiv();"

function OpenModelDiv()
{	
	openModalWindow('sendmessage');	
	AddUsername(arguments[0],arguments[1]);
	HidePopUp();
}
function OpenModelDiv1()
{	
	openModalWindow('sendmessage');	
	AddUsername(arguments[0],arguments[1]);
}
function HidePopUp()
{
    if (hover != 1)
    {
	    PopBox.innerHTML="";
	    PopBox.style.zIndex='-1';
	}
}

function Placeit(an, box)
{
	var cleft = 0;
	var ctop = 0;
	var obj = an;
	while(obj.offsetParent)
	{
		cleft += obj.offsetLeft;
		ctop +=	obj.offsetTop;
		obj = obj.offsetParent;
	}
	
	if (document.body.currentStyle && document.body.currentStyle['marginTop'])
	{
		ctop += parseInt(document.body.currentStyle['marginTop']);
	}
	ctop=parseInt(ctop);
	cleft=parseInt(cleft);
	
	box.style.top = ctop + 'px';
	box.style.left= cleft+ 'px';
}   

function positionPopup(inputObj,parent,bNews)
{
    var cleft = 0;
    var ctop = 0;
    var obj = inputObj;
    while(obj.offsetParent) 
    {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }
    if (document.body.currentStyle && document.body.currentStyle['marginTop']) 
    {
        ctop += parseInt(document.body.currentStyle['marginTop']);
    }
	ctop=parseInt(ctop)-15;	
	if(inputObj.offsetWidth)
		cleft=parseInt(cleft) + parseInt(inputObj.offsetWidth)+3;	
	if(navigator.appName=='Microsoft Internet Explorer')
	{
		if(bNews)
		{
			ctop=parseInt(ctop)-270;
		}
		cleft=parseInt(cleft)-13;
	}
	
	parent.style.left = cleft + 'px'; 
    parent.style.top = ctop + 'px';
}

function addEvent(obj, type, fn )
{
	    if (obj.addEventListener) {
		    obj.addEventListener( type, fn, false );
	    }
	    else if (obj.attachEvent) {
		    obj["e"+type+fn] = fn;
		    obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		    obj.attachEvent( "on"+type, obj[type+fn] );
	    }
	    else {
		    obj["on"+type] = obj["e"+type+fn];
	    }
}

