function login(obj){
	var div=document.getElementById('div_login');
	if(div == null)
	    return;
	div.style.left=(findPosX(obj)) + 'px';
	div.style.top=(findPosY(obj)) + 'px';
	div.style.display='';
	//location.hash = 'sign_in';
	document.getElementById('ctl00_txtLoginEmail').focus();
}
function show_msg_li(v){
	for(var i=0; i<3; i++)
		document.getElementById('li_' + i).style.display=(v==i)?'':'none';
}
function ajax(){
	var xmlhttp=null;
	try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	catch(e){
	try{xmlhttp=new ActiveXobject("Msxml2.XMLHTTP");}
	catch(e){xmlhttp=new XMLHttpRequest();}}
	return xmlhttp;
}

function forgot_pass(){
	document.getElementById('msg_login').innerHTML='Type Nickname for recover';
	document.getElementById('login_bt').value='send';
	document.getElementById('if_forgot').value='forgot';
	document.getElementById('hide_pass').style.display='none';
}

function frm_type_fun(v){
	document.getElementById('frm_type').value=v;
	document.getElementById('upload_frm').submit();
}

function finish_upload(v){
	var frm=document.getElementById('upload_frm');
	
	frm.removeAttribute('enctype');
	frm.removeAttribute('onsubmit');
	frm.removeAttribute('action');
	frm.setAttribute('action', 'set_category.asp?frm_type=' + v);
	
	frm.submit();
}


var timer;
var msgFlagID

function check_url(link_url, msg_id){
    if(trim(link_url) == '') return;
    msgFlagID = document.getElementById(msg_id);
	window.clearTimeout(timer);
	timer=window.setTimeout('do_it(\'' + link_url + '\')', 1000);
}
function check_now(link_url, msg_id){
    msgFlagID = document.getElementById(msg_id);
	do_it(link_url);
}

function do_it(link_url){

	var xmlhttp=ajax(xmlhttp);
	msgFlagID.innerHTML='<img src="images/loading.gif" width="20" height="20">';
	xmlhttp.open('GET', 'http://www.sutree.com/checkurl.ashx?link_url=' + link_url + '&r=' + Math.random()*1000000, true);
	
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			msgFlagID.innerHTML = xmlhttp.responseText;
			delete xmlhttp;
			xmlhttp=null;
		}
	}
	xmlhttp.send(null);
}

function findPosX(obj){
	var curleft = 0;
	
	if(obj.offsetParent)
	{
		while(1) 
		{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
	}
	else if(obj.x)
	{
		curleft += obj.x;
	}	
	return curleft;
}

function rate_link(id, type){
	
	var rating_str;
	
	if(type==1){
		switch(id){
			case 1:
				rating_str='Poor';
				break;
			case 2:
				rating_str='Mediocre';
				break;
			case 3:
				rating_str='O.K';
				break;
			case 4:
				rating_str='Good';
				break;
			case 5:
				rating_str='Excellent';
				break;
		}
		
		document.getElementById('rating_str').innerHTML=rating_str;
	}else
		document.getElementById('rating_str').innerHTML='Rate It:';
	
	
	for(var i=1; i<=5; i++)
		document.getElementById('ctl00_cphLeft_star_' + i).src='http://www.sutree.com/images/star' + ((id>=i)?'':'_bg') + '.gif';			
}

function bad_link(s_bad){
	document.getElementById('s_bad').value=s_bad;
	document.getElementById('frm_bad_link').submit();
}

function set_rate(r, s){
	
	var xmlhttp=ajax();
	var loading_rate=document.getElementById('loading_rate');
	
	loading_rate.innerHTML='sending rating...';
	
	for(var i=1; i<=5; i++){
		var star=document.getElementById('ctl00_cphLeft_star_' + i);
		
		if(star){
			star.onmouseover=null;
			star.onclick=null;
			star.style.cursor='';
			star.onmouseout=null;
		}
	}
	var url = 'http://www.sutree.com/RateVideo.aspx?p=' + Math.random()*1000000 + '&r=' + r + '&s=' + s;
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			loading_rate.innerHTML=xmlhttp.responseText;
		}
		
	}
	xmlhttp.send(null);

}

function comment_it(id){
	
	var arr=['send_to_friend','comment_link'];
	
	for(var i=0; i<arr.length; i++)
		if(document.getElementById(arr[i]))
			document.getElementById(arr[i]).style.display='none';
	
	if(document.getElementById(id))
		document.getElementById(id).style.display='';
	if(id == arr[1])
	{
	    document.getElementById('ctl00_cphLeft_txtComment').focus();
    }
}
function showComment()
{
    $('writeCmnt').setStyle('display', 'block');
    $('ctl00_cphLeft_txtComment').focus();
}
function hideComment()
{
    $('writeCmnt').setStyle('display', 'none');
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
		
	return curtop;
}

function on_img_status(id, type){
	document.getElementById(id).className='img_list_' + type;
}
function bb_focus(bb)
{
    var board = document.getElementById(bb);
    board.focus();
    if(board.value == '')
        board.style.fontStyle = 'normal';
}
/*
function trim(s)
{
	return rtrim(ltrim(s));
}

function ltrim(s)
{
	var l=0;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	return s.substring(l, s.length);
}

function rtrim(s)
{
	var r=s.length -1;
	while(r > 0 && s[r] == ' ')
	{	r-=1;	}
	return s.substring(0, r+1);
}
*/
function showTags(spnID, lnk)
{
    document.getElementById(spnID).style.display = 'inline';
    lnk.style.display = 'none';
}
function hideTags(spnID, lnkID)
{
    document.getElementById(spnID).style.display = 'none';
    document.getElementById(lnkID).style.display = 'inline';
}

/* adds sutree search to browser's bar */
function addSearch()
{
    var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
    var url_prefix;
    if(is_ie)
        url_prefix = '';
    else
        url_prefix = 'http://www.sutree.com/';
    
    try
    {
	    if (is_ie) 
	    {        
		    window.external.AddSearchProvider(url_prefix + 'sutree_search.xml');     
	    }  
        else
        {
	        if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function"))  
	        {      
		        window.sidebar.addSearchEngine(          
			        'http://www.sutree.com/sutree.src',           		
			        'http://www.sutree.com/sutree.gif',          
			        'SuTree.com',                            
			        'Web');                          
	        }
	    } 
	}
	catch(e)
	{
	    alert('It seems like your browser does not support our search plugin. SuTree search plugin requires Internet Explorer 7+ or Firefox 2+.');
	}
}

var infoTimer;
var timerCount = 0;
var infoDiv;
function setInfoFlash(divId)
{
    infoDiv = document.getElementById(divId);
    infoTimer = setTimeout("flashInfo()", 250);
}
function flashInfo()
{
    if(timerCount > 5)
    {
        clearTimeout(infoTimer);
        return;
    }
    if(infoDiv.style.backgroundColor == '')
        infoDiv.style.backgroundColor = '#FF6600';
    else
        infoDiv.style.backgroundColor = '';
    infoTimer = setTimeout("flashInfo()", 250);
    timerCount++;
}
function trim(str)
{
    return str.replace(/^\s+|\s+$/g, '');
}

var userImg;
var imgTimer;
var hideBigFlag = false;
function showBig(img, url)
{
    if(document.getElementById(url).value == '')
        return;
    hideBigFlag = false;
    if(!userImg)
        loadBig(url);
    var bigImg = document.getElementById('divBigImg');
    bigImg.style.left=(findPosX(img) + 70) + 'px';
    bigImg.style.top=(findPosY(img) + 40) + 'px';
    bigImg.style.display = 'block';
}
function loadBig(url)
{
    var wait = document.getElementById('bigLoading');
    wait.style.display = 'inline';
    userImg = new Image();
    userImg.src = document.getElementById(url).value;
    document.getElementById('divBig').appendChild(userImg);    
    wait.style.display = 'none';
}
function hideBig()
{
    hideBigFlag = true;
    imgTimer = setTimeout('hideBigImg()', 500);
}
function hideBigImg()
{
    if(hideBigFlag)
    {
        document.getElementById('divBigImg').style.display = 'none';
        clearTimeout(imgTimer);
    }
}

var tmr;
function ShowTeaser()
{
    tmr = setTimeout("DisplayPopMsg()", 4000);
}
function DisplayPopMsg()
{
    window.scroll(0,0);
    var divChild = document.getElementById('popup');
    var divParent = document.getElementById('popup').parentElement;
    if(divChild && divParent)
    {
        divParent.removeChild(divChild);
        document.body.appendChild(divChild);
    }
    document.getElementById('popup').style.display = 'block';
    document.getElementById('popupContent').style.display = 'block';
    document.body.style.height = '100%';
    document.body.style.width = '100%';
    document.body.style.margin = '0';
    document.body.style.overflow = 'hidden';
    document.documentElement.style.overflow = 'hidden';
    
    clearTimeout(tmr); 
}
function ClosePop()
{
    document.getElementById('popup').style.display = 'none';
    document.getElementById('popupContent').style.display = 'none';
    document.body.style.height = 'auto';
    document.body.style.width = 'auto';
    document.body.style.margin = 'auto';
    document.body.style.overflow = 'auto';
    document.documentElement.style.overflow = 'auto';
}
function openWindow(url, w, h)
{
    window.open(url, "mywindow","menubar=0,resizable=1,width=" + w + ",height=" + h + ",left=100,top=100,scrollbars=yes");
}

var sendBoxes = new Array();
var wrapBoxes = new Array();
var favoBoxes = new Array();
var crseBoxes = new Array();

function ShowHide(id, lesson)
{
    for(i=0; i<10; i++)
    {
        if(i != id)
        {
            if(sendBoxes[i] != null)
                sendBoxes[i].hide();
            if(favoBoxes[i] != null)
                favoBoxes[i].hide();
            if(crseBoxes[i] != null)
                crseBoxes[i].hide();
        }
    }
    
    if(wrapBoxes[id] != null)
        wrapBoxes[id].slideOut();
    if(favoBoxes[id] != null)
        favoBoxes[id].slideOut();
    if(crseBoxes[id] != null)
        crseBoxes[id].slideOut();
        
    hiddenLessonID.value = lesson;
    
    var fldsDiv = document.getElementById('sendFields');
    var myDiv = document.getElementById('toggle' + id);
    if(fldsDiv && myDiv)
        myDiv.innerHTML = fldsDiv.innerHTML;
    if(sendBoxes[id] == null)
    {
        myDiv.style.display = 'block';
        sendBoxes[id] = new Fx.Slide('toggle' + id, {duration: 500});
        sendBoxes[id].hide();
    }
    sendBoxes[id].toggle();
}
function ShowHideWrap(id)
{
    for(i=0; i<10; i++)
    {
        if(i != id)
        {
            if(wrapBoxes[i] != null)
                wrapBoxes[i].hide();
            if(favoBoxes[i] != null)
                favoBoxes[i].hide();
            if(crseBoxes[i] != null)
                crseBoxes[i].hide();
        }
    }

    if(sendBoxes[id] != null)
        sendBoxes[id].slideOut();
    if(favoBoxes[id] != null)
        favoBoxes[id].slideOut();
    if(crseBoxes[id] != null)
        crseBoxes[id].slideOut();
        
    var fldsDiv = document.getElementById('wrapInfo');
    var myDiv = document.getElementById('wrapDiv' + id);
    if(fldsDiv && myDiv)
        myDiv.innerHTML = fldsDiv.innerHTML;
    if(wrapBoxes[id] == null)
    {
        myDiv.style.display = 'block';
        wrapBoxes[id] = new Fx.Slide('wrapDiv' + id, {duration: 500});
        wrapBoxes[id].hide();
    }
    wrapBoxes[id].toggle();
}
function ShowHideFavo(id)
{
    for(i=0; i<10; i++)
    {
        if(i != id)
        {
            if(wrapBoxes[i] != null)
                wrapBoxes[i].hide();
            if(sendBoxes[i] != null)
                sendBoxes[i].hide();
            if(crseBoxes[i] != null)
                crseBoxes[i].hide();
        }
    }

    if(sendBoxes[id] != null)
        sendBoxes[id].slideOut();
    if(wrapBoxes[id] != null)
        wrapBoxes[id].slideOut();
    if(crseBoxes[id] != null)
        crseBoxes[id].slideOut();
        
    var fldsDiv = document.getElementById('favoInfo');
    var myDiv = document.getElementById('favoDiv' + id);
    if(fldsDiv && myDiv)
        myDiv.innerHTML = fldsDiv.innerHTML;
    if(favoBoxes[id] == null)
    {
        myDiv.style.display = 'block';
        favoBoxes[id] = new Fx.Slide('favoDiv' + id, {duration: 500});
        favoBoxes[id].hide();
    }
    favoBoxes[id].toggle();
}
function ShowHideCourse(id)
{
    for(i=0; i<10; i++)
    {
        if(i != id)
        {
            if(wrapBoxes[i] != null)
                wrapBoxes[i].hide();
            if(sendBoxes[i] != null)
                sendBoxes[i].hide();
            if(favoBoxes[i] != null)
                favoBoxes[i].hide();
        }
    }

    if(sendBoxes[id] != null)
        sendBoxes[id].slideOut();
    if(wrapBoxes[id] != null)
        wrapBoxes[id].slideOut();
    if(favoBoxes[id] != null)
        favoBoxes[id].slideOut();
        
    var fldsDiv = document.getElementById('crseInfo');
    var myDiv = document.getElementById('crseDiv' + id);
    if(fldsDiv && myDiv)
        myDiv.innerHTML = fldsDiv.innerHTML;
    if(crseBoxes[id] == null)
    {
        myDiv.style.display = 'block';
        crseBoxes[id] = new Fx.Slide('crseDiv' + id, {duration: 500});
        crseBoxes[id].hide();
    }
    crseBoxes[id].toggle();
}
function hideBox(type)
{
    var arr = eval(type + 'Boxes');
    for(i=0; i<10; i++)
    {
        if(arr[i] != null)
            arr[i].slideOut();
    }
}
function scrollToInfo()
{
    var winScroller = new Fx.Scroll(window);
    /*
    winScroller.toElement('infoToggle'); */
}
function setVid(link)
{
    link.setAttribute('href', 'https://www.sutree.com/findfriends.aspx?vid=' + hiddenLessonID.value, 0);
}
var catClicked = false;
var catShown = false;
function showCat()
{
    if(catShown)
    {
        hideCat();
        return;
    }
    catClicked = true;
    catShown = true;
    $('catMenu').setStyle('display', 'block');
    $('cHead').setStyle('color', '#FFFFFF');
    $('cHead').setStyle('background-color', '#CE0000');
    catMouseOver();
}
function catMouseOver()
{
    $('catDn').setProperty('src', 'http://www.sutree.com/images/arrow-wht-dn2.gif');
}
function catMouseOut()
{
    if(!catShown)
        $('catDn').setProperty('src', 'http://www.sutree.com/images/arrow-blk-dn2.gif');
}
function hideCat()
{
    setTimeout("hideCategories()", 250);
}
function hideCategories()
{
    if(!catClicked)
    {
        $('catMenu').setStyle('display', 'none');
        $('cHead').setStyle('color', '');
        $('cHead').setStyle('background-color', '');
        catShown = false;
        catMouseOut();
    }
    catClicked = false;
}

function changeOpacity(obj, val) {
    //$(obj).setOpacity(val);
    $(obj).style.filter = 'alpha(opacity=' + (val * 100) + ')';
    $(obj).style.opacity = val;
    $(obj).style.MozOpacity = val;
}
function showhero(sel_div)
{
    for(i=0;i<arr.length;i++)
    {
        if(arr[i].toString()!=sel_div)
        {
            document.getElementById('div_'+arr[i]).style.display='none';   
            document.getElementById('img_'+arr[i]).style.border='none';
        }
    }
    document.getElementById('div_def').style.display='none';
    document.getElementById('img_'+sel_div).style.border='Double';
    document.getElementById('div_'+sel_div).style.display='block';
}
