//var uri = "/Default.aspx";
var uri = "/DefaultProxy3.aspx";
var graffitiServerURL = "http://graffiti.skrbl.com/";

var cX = 0; var cY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) 
{
    d.style.left = (cX-100) + "px";
    d.style.top = (cY-10) + "px";
 
}

function HideContent() 
{
if(d.length < 1) { return; }
//document.getElementById("setPwdActionsDiv").style.display = "none";
document.getElementById("setPwdActionsDiv").style.visibility = "hidden";
}

function ShowContent(imgObj) 
{
    //alert(imgObj.name + " - " +imgObj.id);
    if(imgObj.name == "")
    {
        //hide the remove pwd button
        d('RemoveP_btn').style.display = 'none';
    }
    else
    {
        d('RemoveP_btn').style.display = '';
    }

    d('setPPText').value = imgObj.name;
    d('SetP_btn').name = imgObj.id    
    d('RemoveP_btn').name = imgObj.id;
    //alert(d('SetP_btn').name);
    //alert(d('RemoveP_btn').name);
    var dd = document.getElementById("main_pp");
    AssignPosition(dd);
    dd.style.display = '';    
}



function RemovePP()
{   
	var data = "a=setWbPwd&p=" + "" + "&s=" + d('RemoveP_btn').name.substring(7);	
	//alert(data);	
	d(d('RemoveP_btn').name).name = "";
	SendData(data);
	s('ppLogging').display = '';
}

function PasswordProtect()
{	
	if(d('setPPText').value == "")
	{
	    alert("Please enter a password");
	    return;
	}
	
	var pp = d('setPPText').value;
	if (pp != "")
	{
		var data = "a=setWbPwd&p=" + pp + "&s=" + d('SetP_btn').name.substring(7);		
		d(d('SetP_btn').name).name = pp;
		//alert(data);
		SendData(data);
	}
	s('ppLogging').display = '';
}

var httpreq = null;
var httpreqGet = null;

function ClearCookies()
{
    var expireStr = 'expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
    try{document.cookie = 'AppUsername=;'+ expireStr;}catch(e){}
    try{document.cookie = 'tokenHostGuid=;'+ expireStr;}catch(e){}
}

function signOut(sessionId, hostGuid)
{   
    try
    {
        document.location.href = '/index.aspx?logout=1';
    }
    catch(e){}
	
}

function BackToSession()
{
    try
    {
        history.go(-1);
        /*
        if(getCookieValue("currentSID"))
        {
            document.location.href = '/' + getCookieValue("currentSID");
        }
        */
    }
    catch(e)
    {
        //alert(e.description);
        //throw e;
    }
}

function OpenNewSession()
{
    var appuserid = "";
    if(getCookieValue('AppUsername'))
    {
        appuserid = getCookieValue('AppUsername');
    }
    var appid = "";
    if(getCookieValue('AppID'))
    {
        appid = getCookieValue('AppID');
    }
    
    var expireStr = 'expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
    try
    {
        winOpener.isAlive();
        winOpener.document.cookie = 'tokenHostGuid=;'+ expireStr;
    }
    catch(e) {}
    
    try
    {
        document.cookie = 'tokenHostGuid=;'+ expireStr;
    }
    catch(e) {}
    
    var x = null;
    try
    {
        winOpener.isAlive();
        x = window.confirm("Starting a new session will close your current session. Proceed?");
        
        if(x)
        {
            winOpener.document.location.href='/start?appid='+appid+"&appuserid="+appuserid;
        }
    }
    catch(e)
    {
        document.location.href='/start?appid='+appid+"&appuserid="+appuserid;
    }
}

function start()
{
	httpreq = new getHTTPObject();
	if (httpreq == null)
	{
		alert("Sorry your browser does not support XMLHTTPObject");
		document.location = "about:blank";
	}
	else
	{
	}
}

function getHTTPObject()
{
	var xmlhttp = null;
	var ie5 = document.all && document.getElementById;
	var ns6 = document.getElementById && !document.all;
	if(ns6)
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch(e)
		{
			xmlhttp = null;
		}
	}
	else
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			xmlhttp = null;
		}
	}
	return xmlhttp;
}

function SendData(params, toGraffiti)
{
    try
    {
        if (httpreq.readyState === 4 || httpreq.readyState === 0) 
        {               
            var lRand = Math.random();
            if(toGraffiti)
            {                
                httpreq.open("POST", "/DefaultProxy3G.aspx?r=" + lRand, true);
            }
            else
            {
                httpreq.open("POST", uri + "?r=" + lRand, true);
            }
            httpreq.onreadystatechange = ReadyHandler;
            httpreq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
            httpreq.send(params);            
        }
    }
    catch(e)
    {
        //throw e;
    }
}

function ReadyHandler()
{
	if (httpreq.readyState == 4)
	{
		if (httpreq.status == 200) 
		{			
			str = httpreq.responseText;
			str = str.replace(/\</g, "&lt;");
			str = str.replace(/\>/g, "&gt;");
			try
			{
			    eval(httpreq.responseText);
			}
			catch (e)
			{
				//throw e;
			}
		}
		else
		{
		}		
	}
	return;
}



function showloginarea()
		{
			var login = document.getElementById('login')
			var forgotpwd = document.getElementById('forgotpwd')
			var signup = document.getElementById('signup')
			login.style.display="block";
			forgotpwd.style.display="none";
			signup.style.display="none";
		}


	function showsignuparea()
		{
			var login = document.getElementById('login')
			var forgotpwd = document.getElementById('forgotpwd')
			var signup = document.getElementById('signup')
			login.style.display="none";
			forgotpwd.style.display="none";
			signup.style.display="block";
		}


	function showforgotpwdarea()
		{
			var login = document.getElementById('login')
			var forgotpwd = document.getElementById('forgotpwd')
			var signup = document.getElementById('signup')
			login.style.display="none";
			forgotpwd.style.display="block";
			signup.style.display="none";
		}

	function d(tag_id)
    {
	    return document.getElementById(tag_id);
    }		
    
    function s(tag_id)
    {
	    return document.getElementById(tag_id).style;
    }


function ShowSetPwdDiv(btnObj)
{
    
}
function fileitem(fn, sz, updt)
{
    var tbl = d('my_files_table');
	var newRow = tbl.insertRow(tbl.rows.length);	
	newRow.style.cursor = "pointer";
	newRow.id = "row_" + fn;
	
	if (window.addEventListener) 
	{
	    newRow.onmouseover = function () { newRow.style.backgroundColor='#D3FC8C'; };
	    newRow.onmouseout = function () { newRow.style.backgroundColor='#FFF'; };
    } 
    else if (window.attachEvent) 
    {
        newRow.attachEvent('onmouseover',function () { newRow.style.backgroundColor='#D3FC8C'; });//EAFEC8
        newRow.attachEvent('onmouseout',function () { newRow.style.backgroundColor='#FFF'; });
    }
	var nc;
	
	nc = newRow.insertCell(0);
	nc.setAttribute("align", "left");
	nc.innerHTML = fn;
	
	nc = newRow.insertCell(1);
	nc.setAttribute("align", "left");
	nc.innerHTML = sz;
	
	nc = newRow.insertCell(2);
	nc.setAttribute("align", "left");
	nc.innerHTML = updt;
	
	nc = newRow.insertCell(3);
	nc.setAttribute("align", "left");
	nc.innerHTML = "<img id='"+fn+"' height='16' width='16' src='skrbl-images/deleteico.gif' onclick='DeleteFile(this);' alt='Delete File' />";
}

function picfileitem(fn, sz, updt)
{    
    var tbl = d('my_pictures_table');
	var newRow = tbl.insertRow(tbl.rows.length);	
	newRow.style.cursor = "pointer";
	newRow.id = "row_" + fn;
	
	if (window.addEventListener) 
	{
	    newRow.onmouseover = function () { newRow.style.backgroundColor='#D3FC8C'; };
	    newRow.onmouseout = function () { newRow.style.backgroundColor='#FFF'; };
    } 
    else if (window.attachEvent) 
    {
        newRow.attachEvent('onmouseover',function () { newRow.style.backgroundColor='#D3FC8C'; });//EAFEC8
        newRow.attachEvent('onmouseout',function () { newRow.style.backgroundColor='#FFF'; });
    }
	var nc;
	
	nc = newRow.insertCell(0);
	nc.setAttribute("align", "left");
	nc.innerHTML = fn;
	
	nc = newRow.insertCell(1);
	nc.setAttribute("align", "left");
	nc.innerHTML = sz;
	
	nc = newRow.insertCell(2);
	nc.setAttribute("align", "left");
	nc.innerHTML = updt;
	
	nc = newRow.insertCell(3);
	nc.setAttribute("align", "left");
	nc.innerHTML = "<img id='"+fn+"' height='16' width='16' src='skrbl-images/deleteico.gif' onclick='DeletePic(this);' alt='Delete Picture' />";
}

function padDateString(dt)
{
    var dateTokens = dt.split("/");
    var month = dateTokens[0];
    var day = dateTokens[1];
    var year = dateTokens[2];
    if(month.length == "1")
    {
        month = "0" + month;
    }
    if(day.length == "1")
    {
        day = "0" + day;
    }
    
    return month + "/" + day + "/" + year;
}

function newArchiveItem_my(a_sessionId, hostGuid, pw, sessionTitle, createdDt, isPrivate)
{
    var tbl = d('archived_sessions_table');
	var newRow = tbl.insertRow(tbl.rows.length);
	newRow.id = "sessionrow_" + a_sessionId;
	//newRow.attachEvent('onmouseover',function () { newRow.style.backgroundColor='#EAFEB8'; });//EAFEC8
	//newRow.attachEvent('onmouseout',function () { newRow.style.backgroundColor='#FFF'; });
	
	/*
	if (window.addEventListener) {
    butt.addEventListener('click', doSomething, false);
    } else if (window.attachEvent) {
        butt.attachEvent('onclick', doSomething);
    }
	
	*/
	if (window.addEventListener) 
	{
	    newRow.onmouseover = function () { newRow.style.backgroundColor='#D3FC8C'; };
	    newRow.onmouseout = function () { newRow.style.backgroundColor='#FFF'; };
    } 
    else if (window.attachEvent) 
    {
        newRow.attachEvent('onmouseover',function () { newRow.style.backgroundColor='#D3FC8C'; });//EAFEC8
        newRow.attachEvent('onmouseout',function () { newRow.style.backgroundColor='#FFF'; });
    }
	var nc;
	
	nc = newRow.insertCell(0);
	nc.setAttribute("align", "center");
	var checkedStr = "";
	if(isPrivate != "False")
	{
	    checkedStr = " checked ";
	}
	nc.innerHTML = '<input onclick="MkPubPvt(this);" '+ checkedStr + 'id="'+a_sessionId+'" type="checkbox" />';
	
	var sessionInfo = a_sessionId + "|" +  hostGuid;
	
	nc = newRow.insertCell(1);
	nc.style.cursor = 'pointer';
	nc.setAttribute("align", "left");
	nc.innerHTML = '<a style="color: #336655;text-decoration:none;" href="#" id="'+sessionInfo+'" onclick="gotoWB(this);return false;">' + a_sessionId + '</a>';//a_sessionId;
	nc.name = a_sessionId;
	
	nc = newRow.insertCell(2);
	nc.setAttribute("align", "left");
	nc.style.cursor = 'pointer';	
	nc.innerHTML = '<a style="color: #336655;text-decoration:underline;" href="#" id="'+sessionInfo+'" onclick="gotoWB(this);return false;">' + sessionTitle + '</a>';
	
	nc = newRow.insertCell(3);
	nc.setAttribute("align", "left");
	nc.style.cursor = 'pointer';
	nc.innerHTML = padDateString(createdDt);
	
	nc = newRow.insertCell(4);
	nc.setAttribute("align", "left");
	nc.style.cursor = 'pointer';	
	var er_img_sid = "er_img_" + a_sessionId;
	nc.innerHTML = '<img style="width:16px;height:16px;" src="skrbl-images/eraserico.gif" id="'+er_img_sid+'" onclick="Erasewb(this);"/>';
	
	nc = newRow.insertCell(5);
	nc.setAttribute("align", "left");
	nc.style.cursor = 'pointer';	
	var del_img_sid = "del_img_" + a_sessionId;
	nc.innerHTML = '<img style="width:16px;height:16px;" src="skrbl-images/deleteico.gif" id="'+del_img_sid+'" onclick="DeleteWB(this);"/>';
	
	nc = newRow.insertCell(6);
	nc.setAttribute("align", "left");
	nc.style.cursor = 'pointer';
	var img_sid = "pw_img_" + a_sessionId;
	nc.innerHTML = '<img src="skrbl-images/lockflag.gif" id="'+img_sid+'" onclick="ShowContent(this);return true;" name="'+pw+'" />';	
		
}

function addSpecialRow()
{
    var tbl = d('archived_sessions_table');
	var newRow = tbl.insertRow(tbl.rows.length);	
	
	newRow.setAttribute("border-left", "none");	newRow.setAttribute("border-right", "none");	newRow.setAttribute("border-bottom", "none");	newRow.setAttribute("border-top", "none");
	
	var nc = newRow.insertCell(0);
	nc.setAttribute("align", "left");
	
	var nc = newRow.insertCell(1);
	nc.setAttribute("align", "left");
	
	nc = newRow.insertCell(2);
	nc.innerHTML = '<a style="font: bold 14px Tahoma;color: #336655;" href="#" onclick="OpenNewSession();return false;">Start a new skrbl session</a>';
	nc.setAttribute("align", "left");
}


function DeleteWB(imgObj)
{    
    var result = confirm("This whiteboard and its content will be deleted. Are you sure?");
	if (result == true)
	{
        s('LoadingStatus').display = '';
        var sid = imgObj.id.substring(imgObj.id.lastIndexOf('_')+1);
        var data = "a=deletewb&tc=1&s=" + sid + "&token=" + getCookieValue("token");
        SendData(data);
    }
}

function EraseGft(imgObj)
{    
    var result = confirm("This Graffiti board will be erased. Are you sure?");
	if (result == true)
	{
        s('LoadingStatus').display = '';
        var sid = imgObj.id.substring(imgObj.id.lastIndexOf('_')+1);
        var data = "a=erasegftwb&myappid=Graffiti&tc=1&s=" + sid;
        SendData(data, true);
    }
}

function Erasewb(imgObj)
{    
    var result = confirm("All contents of this whiteboard will be erased. Are you sure?");
	if (result == true)
	{
        s('LoadingStatus').display = '';
        var sid = imgObj.id.substring(imgObj.id.lastIndexOf('_')+1);
        var data = "a=erasewb&tc=1&s=" + sid + "&token=" + getCookieValue("token");
        SendData(data);
    }
}

function MkPubPvt(cb)
{
    
    if(cb.checked)
    {
        //mpvt
        var data = "a=mpvt&tc=1&s=" + cb.id;
	    SendData(data);
    }
    else
    {
        //mpub
        var data = "a=mpub&tc=1&s=" + cb.id;
	    SendData(data);
    }
}
function gotoWB(anchor)
{
    var sessionInfo = anchor.id.split('|');
    document.cookie='sessionId=' + sessionInfo[0] + ';path=/';
    document.cookie='tokenHostGuid=' + sessionInfo[1] + ';path=/';
    document.cookie= sessionInfo[0] + "=1;path=/";
    try
    {
        winOpener.isAlive();
        winOpener.document.location.href='/' + sessionInfo[0];
    }
    catch(e)
    {
        document.location.href='/' + sessionInfo[0];
    }
}

function GetArchivedSessions()
{
    s('LoadingStatus').display = '';
    var data = "a=archives_my&tc=1&u=" + getCookieValue('AppUsername');
	SendData(data);
}

function Login_my()
{	
    d('ml_error').innerHTML = 'Logging in';
    s('ml_error').display = '';
	var data = "a=login_my&tc=1&u=" + d('ml_username').value + "&p=" + d('ml_password').value + "&currentHostGuid=" + getCookieValue('token');	
	SendData(data);
}

function ChangePwd_my()
{    
	if (d('newPwd1').value != d('newPwd2').value)
	{
		alert('Passwords do not match.');
		return;
	}
	else if (d('newPwd1').value == "" || d('newPwd2').value == "")
	{
		alert('Password cannot be blank');
		return;
	}	
	
	d('ChangePwdError').innerHTML = 'Working...';
    s('ChangePwdError').display = '';
	var data = "a=changepwd_my&tc=1&newpwd=" + d('newPwd1').value + "&u=" + getCookieValue('AppUsername');
	SendData(data);
}


function RegisterValidate_my()
{
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var re = /^\w+$/;
    if (d('txtUsername').value == "")
	{
		alert('Username cannot be empty');
		return;
	}	
	else if (!re.test(d('txtUsername').value))
	{
	    alert("Username can contain only letters, numbers and underscores.");
	    return;
	}
	else if (!filter.test(d('txtEmail').value))
	{
		alert('Please enter a valid email address.');
		return;
	}
    else if (d('txtPassword').value == "")
	{
		alert('Password cannot be empty');
		return;
	}	
	else if (d('txtPassword').value != d('txtConfirmPassword').value)
	{
		alert('Passwords do not match.');
		return;
	}	
		
	d('lblError').innerHTML = 'Registering...';
    s('lblError').display = '';
	var data = "a=register_my&tc=1&u=" + d('txtUsername').value + "&p=" + d('txtPassword').value + "&e=" + d('txtEmail').value;	
	SendData(data);
}

var winOpener = null;
var userLoggedIn = "";

function InitSortableColumns()
{
    var firstRow = d('archived_sessions_table').rows[0];    
    firstRow.cells[0].setAttribute("allowSort", "0"); //private flag checkbox
    firstRow.cells[1].setAttribute("allowSort", "1"); //session id
    firstRow.cells[2].setAttribute("allowSort", "1"); //title
    firstRow.cells[3].setAttribute("allowSort", "1"); //date created
    firstRow.cells[4].setAttribute("allowSort", "0"); //erase 
    firstRow.cells[5].setAttribute("allowSort", "0"); //pwd    
    
    //firstRow = d('').rows[0];
}

function InitMy()
{
    //initialize sortable columns
    InitSortableColumns();
    sortables_init();
    /*check if logged in
    - if logged in, show archive table, hide divs
    - if not logged in hide archive table, show login div*/
    var loggedIn = false;
    try
    {
        winOpener = window.opener ;
    }
    catch(e){}
    /*
    if(window.opener != null)
    {
        winOpener = window.opener ;
        //alert('coming from wb');
        loggedIn = window.opener.getCookieValue('AppUsername');
    }
    else
    {
        //alert('coming from homepage');
        loggedIn = getCookieValue('AppUsername');
    }
    */
    try
    {
        loggedIn = window.opener.getCookieValue('AppUsername');
    }
    catch(e)
    {
        loggedIn = getCookieValue('AppUsername');
    }
    //alert('loggedIn - ' + loggedIn);
    
    try
    {
        if(getCookieValue('prevSessionFlag') == "1")
        {
            document.cookie='prevSessionFlag=0;path=/';
            s('returnToSessionLink').display = '';
        }
    }
    catch(e)
    {
        document.cookie='prevSessionFlag=0;path=/';
        s('prevSessionFlag').display = '';
    }
    
    if(loggedIn)
    {
        userLoggedIn = getCookieValue('AppUsername');
        s('forgotpwd').display = 'none';
        s('login').display = 'none';
        s('signup').display = 'none';
        s('archived_sessions_table').display = '';
        s('ChangePwdTable').display = '';
        s('mySessionsLabel').display = '';
        s('loggedInSummary').display = '';
        GetArchivedSessions();
    }
    else
    {
        s('forgotpwd').display = 'none';
        s('signup').display = 'none';
        s('archived_sessions_table').display = 'none';
        s('ChangePwdTable').display = 'none';
        s('login').display = '';
        s('mySessionsLabel').display = 'none';
        s('loggedInSummary').display = 'none';
    }
}


/*==============================================================================
http://www.braemoor.co.uk/software/cookies.shtml
Routine to get the current value of a cookie
    Parameters:
        cookieName        Cookie name    
    Return value:
        false             Failed - no such cookie
        value             Value of the retrieved cookie

   e.g. if (!getCookieValue("pans") then  {
           cookieValue = getCoookieValue ("pans2);
        }
*/

function getCookieValue (cookieName) 
{
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

function DeletePic(col)
{    
    var result = confirm("This picture will be deleted. Are you sure?");
	if (result == true)
	{
        s('LoadingStatus').display = '';
        var data = "a=delfile&tc=1&u=" + getCookieValue('AppUsername') + "&fn=" + col.id;	
	    SendData(data);
	}
}

function RemoveSessionRow(sid)
{
    var delRowId = "sessionrow_"+sid;
    s(delRowId).display = 'none';
}

function DeleteFile(col)
{    
    var result = confirm("This file will be deleted. Are you sure?");
	if (result == true)
	{
        s('LoadingStatus').display = '';
        var data = "a=delfile&tc=1&u=" + getCookieValue('AppUsername') + "&fn=" + col.id;	
	    SendData(data);
	}
}

function RemoveFileRow(fn)
{    
    var delRowId = "row_"+fn;
    s(delRowId).display = 'none';
}

function DeleteAllRows(tab)
{
    var tbl = null;
    if(tab == "MySessions")
    { 
        tbl = d('archived_sessions_table');
    }
    if(tab == "MyPictures")
    {
        tbl = d('my_pictures_table');
    }
    if(tab == "MyFiles")
    {
        tbl = d('my_files_table');
    }
    if(tab == "MyGraffiti")
    {
        tbl = d('my_gft_table');
    }
        
    for(i=tbl.rows.length-1; i > 0; i--)
	{		
		tbl.deleteRow(i);
	}
}

function ShowTab(tab)
{    
    s('newGftLinkTable').display = 'none';
    s('newsessionLink').display = '';
    s('LoadingStatus').display = '';
    DeleteAllRows(tab);
    if(tab == "MySessions")
    {       
        s('mySessionsLabel').color = '#737373';
        s('mySessionsLabel').textDecoration = 'none';        
        
        s('myPicsLabel').textDecoration = 'underline';        
        s('myPicsLabel').color = '#336655';
        
        s('myFilesLabel').textDecoration = 'underline';        
        s('myFilesLabel').color = '#336655';
        
        s('myGraffitiLabel').color = '#336655';
        s('myGraffitiLabel').textDecoration = 'underline';
        
        s('my_pictures_table').display = 'none';
        s('my_files_table').display = 'none';
        s('my_gft_table').display = 'none';
        s('icon_legend_table').display = '';
        
        s('archived_sessions_table').display = '';            
        GetArchivedSessions();
    }
    
    if(tab == "MyPictures")
    {   
        s('myPicsLabel').color = '#737373';
        s('myPicsLabel').textDecoration = 'none';     
        
        s('mySessionsLabel').textDecoration = 'underline';        
        s('mySessionsLabel').color = '#336655';
        
        s('myFilesLabel').textDecoration = 'underline';        
        s('myFilesLabel').color = '#336655';
        
        s('myGraffitiLabel').color = '#336655';
        s('myGraffitiLabel').textDecoration = 'underline';
        
        s('icon_legend_table').display = 'none';
        s('archived_sessions_table').display = 'none';
        s('my_files_table').display = 'none';
        s('my_gft_table').display = 'none';
        
        s('my_pictures_table').display = '';        
        GetPics();
    }
    
    if(tab == "MyFiles")
    {
        s('myFilesLabel').color = '#737373';
        s('myFilesLabel').textDecoration = 'none';
        
        s('mySessionsLabel').textDecoration = 'underline';        
        s('mySessionsLabel').color = '#336655';
        
        s('myPicsLabel').textDecoration = 'underline';        
        s('myPicsLabel').color = '#336655';
        
        s('myGraffitiLabel').color = '#336655';
        s('myGraffitiLabel').textDecoration = 'underline';
        
        s('icon_legend_table').display = 'none';
        s('archived_sessions_table').display = 'none';
        s('my_pictures_table').display = 'none';
        s('my_gft_table').display = 'none';
        
        s('my_files_table').display = '';        
        GetFiles();
    }
    
    if(tab == "MyGraffiti")
    {
        s('myGraffitiLabel').color = '#737373';
        s('myGraffitiLabel').textDecoration = 'none';
        
        s('mySessionsLabel').textDecoration = 'underline';        
        s('mySessionsLabel').color = '#336655';
        
        s('myFilesLabel').textDecoration = 'underline';        
        s('myFilesLabel').color = '#336655';        
        
        s('myPicsLabel').textDecoration = 'underline';        
        s('myPicsLabel').color = '#336655';
        
        s('icon_legend_table').display = 'none';
        s('archived_sessions_table').display = 'none';
        s('my_pictures_table').display = 'none';
        s('my_files_table').display = 'none';
        s('newsessionLink').display = 'none';
        s('newGftLinkTable').display = '';        
        s('my_gft_table').display = '';        
        GetGFTList();        
    }
}

function GetGFTList()
{
    s('LoadingStatus').display = '';
    var data = "a=Graffiti_my&tc=1&u=" + getCookieValue('AppUsername');
	SendData(data, true);
}

function GftTitleChanged(gft_id, gft_new_title)
{
    s('LoadingStatus').display = '';
    var data = "a=gft_title_change&tc=1&myappid=Graffiti&gft_id=" +gft_id + "&newtitle=" + gft_new_title;
	SendData(data, true);
}

function addRowOverHandlers(newRow)
{
    if (window.addEventListener) 
    {
        newRow.onmouseover = function () { newRow.style.backgroundColor='#D3FC8C'; };
        newRow.onmouseout = function () { newRow.style.backgroundColor='#FFF'; };
    } 
    else if (window.attachEvent) 
    {
        newRow.attachEvent('onmouseover',function () { newRow.style.backgroundColor='#D3FC8C'; });//EAFEC8
        newRow.attachEvent('onmouseout',function () { newRow.style.backgroundColor='#FFF'; });
    }
}

function AddNewGftRow(gf_id, title, dt, isNew)
{   
    var tbl = d('my_gft_table');    
    for(var i=1; i<tbl.rows.length; i++)
    {
        tbl.rows[i].style.backgroundColor = '#FFF';
    }
    
    var newRow;
    if(isNew)
    {                
        newRow = tbl.insertRow(1);	
        newRow.style.backgroundColor = "#D3FC8C";
    }
    else
    {
        newRow = tbl.insertRow(tbl.rows.length);	
    }    
	
	newRow.id = "row_" + gf_id;		
	if(isNew)
	{
	}
	else
	{
	    addRowOverHandlers(newRow);
    }
	
	var nc;	
	var er_img_sid = "er_img_" + gf_id;	
	
	nc = newRow.insertCell(0);
	nc.setAttribute("align", "left");
	nc.innerHTML = '<input class="input2" id="'+gf_id+'" style="font:bold 14px Tahoma;" onkeyup="title_KeyDown(event, this);" onblur="GftTitleChanged(this.id, this.value);" value="' + title + '"/>';
	
	nc = newRow.insertCell(1);
	nc.setAttribute("align", "left");
	nc.innerHTML = dt;
	
	nc = newRow.insertCell(2);
	nc.setAttribute("align", "left");
	nc.innerHTML = '<img alt="Erase" style="cursor:pointer;width:16px;height:16px;" src="skrbl-images/eraserico.gif" id="'+er_img_sid+'" onclick="EraseGft(this);"/>'
	
	nc = newRow.insertCell(3);
	nc.setAttribute("align", "left");
	nc.innerHTML =  '<table><tr><td><span style="font: bold 12px Tahoma;color:black;">URL: </span></td>' + 
	                "<td><input class='input2' readonly style='width:250px;' type='text' value='" 
	                + graffitiServerURL+gf_id + "'/></td></tr>" 	                
	                + '<tr><td><span style="font: bold 12px Tahoma;color:black;">Embed: </span></td>' 
	                + "<td><input readonly class='input2' style='width:250px;' type='text' value='" 
	                + '<iframe id="skrblFrame" src="'+ graffitiServerURL+gf_id +'" scrolling="auto" frameborder="0" style="width:510px;height:400px;border:1px solid black;"></iframe>' 
	                + "' /></td></tr></table>";
}

function title_KeyDown(event, obj)
{
	var wt = obj;
	if (window.event.keyCode == 13)
	{
		wt.blur();	
	}
}

function OpenNewGft()
{      
    var data = "a=WBGetNewGF_ID&app_id=Graffiti&user_id=" + getCookieValue('AppUsername');
    SendData(data, true);
    s('LoadingStatus').display = '';
}

function positionSNS()
{
	var obj = d('archived_sessions_table');
    
	if (obj.currentstyle)
	{ 
	    //alert('1');
		var curVal=obj.currentStyle.height; 
		//eval('obj.currentstyle.'+cAttribute) 
		//alert(curVal);
		s('snsessionlink').top = curVal;
	}
	else
	{ 
		//if Mozilla/FF 
		var curVal= document.defaultView.getComputedStyle(obj, null).height; 						//eval('document.defaultView.getComputedStyle(obj, null).'+cAttribute) 
		//alert(curVal);
		s('snsessionlink').top = curVal;
	} 
}

function GetFiles()
{
    s('LoadingStatus').display = '';    
    var data = "a=files_my&tc=1&u=" + getCookieValue('AppUsername');
	SendData(data);
}

function GetGFT()
{
    s('LoadingStatus').display = '';    
    var data = "a=gft_my&tc=1&u=" + getCookieValue('AppUsername');
	SendData(data, true);
}

function GetPics()
{
    s('LoadingStatus').display = '';    
    var data = "a=pictures_my&tc=1&u=" + getCookieValue('AppUsername');
	SendData(data);
}