function refreshLines(){
				
	if(JSalt == null){
		clearTimeout(t);
		var t=setTimeout("refreshLines();",500);
	}
				
	else{
		altTemp = JSalt;
		JSalt = null;
		lockFunctions("ON");

		var xmlhttp;
		if (window.XMLHttpRequest)
		xmlhttp = new XMLHttpRequest();
		else if (window.ActiveXObject)
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					
		xmlhttp.open("POST","altered.php");
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", 6+(altTemp.length));
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send("JSalt="+altTemp);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				lockFunctions ("OFF");
				ajaxArray = xmlhttp.responseText.split('&|&');
				response = ajaxArray[0];
							
				if ((response == "Unlogged") || (response == "Invalid Login")){	
					clearSilentLogin();
				}
							
				else if (response == "Logged Out"){	
					clearSilentLogin();
					window.location.assign("../index.php");
				}
							
				else if (response != "No Change"){
					table = document.getElementById('favTbl');
					table.parentNode.removeChild(table);
					constructFavArr(4,9);
					displayCells(response,'Login');
				}
				JSalt = ajaxArray[1];
			}
		}
	}
				
	return;
}

var lockFlag=false;function URLEncode(clearString){var output='';var x=0;clearString=clearString.toString();var regex=/(^[a-zA-Z0-9_.]*)/;while(x<clearString.length){var match=regex.exec(clearString.substr(x));if(match!=null&&match.length>1&&match[1]!=''){output+=match[1];x+=match[1].length;}else{if(clearString[x]==' ')
output+='+';else{var charCode=clearString.charCodeAt(x);var hexVal=charCode.toString(16);output+='%'+(hexVal.length<2?'0':'')+hexVal.toUpperCase();}
x++;}}
return output;}
function URLDecode(encodedString){var output=encodedString;var binVal,thisString;var myregexp=/(%[^%]{2})/;output=output.replace(/\+/g,' ');while((match=myregexp.exec(output))!=null&&match.length>1&&match[1]!=''){binVal=parseInt(match[1].substr(1),16);thisString=String.fromCharCode(binVal);output=output.replace(match[1],thisString);}
return output;}
function lockFunctions(EState){loadingObj=document.getElementById('loadingIcon');if(EState=="ON")
{if(loadingObj)loadingObj.style.visibility='visible';lockFlag=true;}
else
{if(loadingObj)loadingObj.style.visibility='hidden';lockFlag=false;}}
function submitenter(e)
{var keycode;if(window.event)keycode=window.event.keyCode;else if(e)keycode=e.which;else return true;if(keycode==13)
{floatDiv=document.getElementById("cellDetails");addBtn=floatDiv.getElementsByTagName("input")[1];if(addBtn.parentNode.style.display=='block')addBtn.onclick();return false;}
else
return true;}
function createCookie(name,value,days){var expires;if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toGMTString();}
else expires="";document.cookie=name+"="+value+expires+"; path=/";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}
return null;}
function eraseCookie(name){createCookie(name,"",-1);}

function sendMSG(destURL,msgContent,msgType)
{
    var responseXML;
             
    // Mozilla version
    if (window.XMLHttpRequest) {
        xMSG = new XMLHttpRequest();
    }

    // IE version
    else if (window.ActiveXObject) {
        xMSG = new ActiveXObject("Microsoft.XMLHTTP");
    }
    lockFunctions ("ON");
    //essay=encodeURIComponent(essay);
	msgContent += "&JSalt="+JSalt;
    xMSG.open("POST",destURL);
    xMSG.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xMSG.setRequestHeader("Content-length", msgContent.length);
    xMSG.setRequestHeader("Connection", "close");
    xMSG.send(msgContent);
    xMSG.onreadystatechange=function() {
        if (xMSG.readyState==4) {
            lockFunctions ("OFF");
			
			//responseMSG = xMSG.responseText
			responseArray = xMSG.responseText.split('&|&');
			responseMSG = responseArray[0];
			
			if (responseMSG=='Page Altered'){
				window.location.reload();
			}
			
			if (responseMSG=='Not Logged'){
                clearSilentLogin();
                window.location.assign("../usrlogin.php");
            }
			
			if (responseArray[1] != null)
				JSalt = responseArray[1];
			
            if (msgType=='iconPath')
				displayIcon(responseMSG);
            if (msgType=='getCellInfo'){
				displayCells (responseMSG,'Login');
				JSalt = DBalt;
			}
            if (msgType=='getNLCellInfo') displayCells (responseMSG,'NewLine');
            if (msgType=='silentLogin') {
                if (responseMSG=="Invalid Login")   clearSilentLogin();
                window.location.reload(); //window.location='index.php';
            }
            if (msgType=='UserValidity') displayValidityResult (responseMSG);
			if (msgType=='UserValiditySet') displayValidityResult (responseMSG);
        //alert (responseMSG);
        }
    }
}

function setSilentLogin(username,email){createCookie('refobj01',username,365);createCookie('refobj02',email,365);}
function clearSilentLogin(){eraseCookie('refobj01');eraseCookie('refobj02');}
function displayIcon(checkResponse){statusLineObj=document.getElementById("statusLine");switch(checkResponse){case"URL_NOT_EXISTS":statusLineObj.innerHTML="The URL does not exists ";break;case"URL_NOT_VALID":statusLineObj.innerHTML="Invalid link, please revise.";AddCancelBtns.style.display="block";break;case"URL_IS_BLANK":statusLineObj.innerHTML="Please enter a URL";break;default:document.draggedObj.cellLink=urlObj.value;document.draggedObj.vacant=false;document.draggedObj.title=urlObj.value;document.draggedObj.favIcon.src=checkResponse;document.draggedObj.favIcon.style.display="block";if((checkResponse.indexOf("/favicon.ico")>0)||(checkResponse.indexOf("defaultIcon.png")>0)){document.draggedObj.style.cursor="pointer";document.draggedObj.favIcon.className="favIcon";AddCancelBtns=document.getElementById('FDAddCancelBtns');OKBtn=document.getElementById('FDOKBtn');AddCancelBtns.style.display="none";OKBtn.style.display="block";floatDiv=document.getElementById("cellDetails");urlObj=floatDiv.getElementsByTagName("Input")[0];urlObj.disabled=true;OKBtn.getElementsByTagName("input")[0].focus();statusLineObj=document.getElementById("statusLine");statusLineObj.innerHTML="The site logo will be updated soon";}
else
{floatDiv.style.display="none";document.draggedObj.className="favLogoCell";document.draggedObj.favIcon.className="DBIcon";}}}

function displayCells(msgResponse,ActionType){
	if(msgResponse=='notLogged'){
		return;
	}
	else
		if(msgResponse=="Invalid Login"){
			clearSilentLogin();
			return;
		}
		else{
			custCells=msgResponse.split('#|#');
			for(custCell=0;custCell<custCells.length;custCell++){
				CellInfo=custCells[custCell].split('*|*');
				document.costumFavLineInst.setCellInfo(CellInfo);
			}
		}
}

function ExtractNumber(value)
{var n=parseInt(value);return n==null||isNaN(n)?0:n;}
function changeOpac(currObj,opacity){if(opacity<100){currObj.style.opacity=(opacity/100);currObj.style.MozOpacity=(opacity/100);currObj.style.KhtmlOpacity=(opacity/100);currObj.style.filter="alpha(opacity="+opacity+")";}
else
{currObj.style.opacity=null;currObj.style.MozOpacity=null;currObj.style.KhtmlOpacity=null;currObj.style.filter=null;}}
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}
function floatDivWin(winAction){floatDiv=document.getElementById("cellDetails");statusLineObj=document.getElementById("statusLine");statusLineObj.innerHTML="";urlObj=floatDiv.getElementsByTagName("Input")[0];if(winAction=="open"){AddCancelBtns=document.getElementById('FDAddCancelBtns');OKBtn=document.getElementById('FDOKBtn');OKBtn.style.display="none";floatDiv.style.display="block";AddCancelBtns.style.display="block";AddCancelBtns.getElementsByTagName("input")[0].focus();urlObj.value='';urlObj.disabled=false;urlObj.focus();}else
if(winAction=="add")
{if(urlObj.value.trim()==""){statusLineObj.innerHTML="Type in a link e.g. cnn.com";return;}
statusLineObj.innerHTML="Checking URL please wait...";AddCancelBtns.style.display="none";if(urlObj.value.indexOf('://')==-1)urlObj.value="http://"+urlObj.value;sendMSG('cellServices.php','actionType=newCell&url='+URLEncode(urlObj.value)+'&rowIndx='+URLEncode(document.draggedObj.rowIndex)+'&cellIndx='+URLEncode(document.draggedObj.cellIndex),'iconPath');}else
{floatDiv.style.display="none";}}
document.favLineOffsetX=0;document.favLineOffsetY=-5;document.favCellHeight=27;document.favCellWidth=77;if(!document.all){document.favCellHeight-=2;document.favCellWidth-=2;}
function delFavLineCell(rowIndex){this.favCellObj=document.createElement("li");cellIcon=document.createElement("img");this.favCellObj.appendChild(cellIcon);cellIcon.src="gui/minusend.jpg";this.favCellObj.className="favLineDel";cellIcon.className="favLineDelIcon";this.favCellObj.style.left=document.favLineOffsetX;this.favCellObj.style.top=document.favLineOffsetY;this.favCellObj.title="Click here to delete a line";this.favCellObj.rowIndex=rowIndex;this.favCellObj.onmousedown=function(){document.onselectstart=function(){return false;};this.ondragstart=function(){return false;};return false;}
this.favCellObj.onclick=function(){if(lockFlag==true)return;trContainer=this.parentNode.parentNode.parentNode;LineCollection=trContainer.parentNode.childNodes;removedRowIndx=this.rowIndex;trContainer.parentNode.removeChild(trContainer);for(lineNum=0;lineNum<LineCollection.length;lineNum++)
{cellCollection=LineCollection[lineNum].firstChild.nextSibling.firstChild.childNodes;for(cellNum=0;cellNum<cellCollection.length;cellNum++)
{if(cellCollection[cellNum].rowIndex){if(cellCollection[cellNum].rowIndex>removedRowIndx)cellCollection[cellNum].rowIndex--;}}}
sendMSG('cellServices.php','actionType=deleteLine&rowIndx='+URLEncode(this.rowIndex),'deleteLine');}}
function recyclebinCell(){if(lockFlag==true)return;this.favCellObj=document.createElement("li");cellIcon=document.createElement("img");this.favCellObj.appendChild(cellIcon);cellIcon.src="gui/recyclebin.jpg";this.favCellObj.className="favBin";cellIcon.className="favBinIcon";this.favCellObj.style.left=document.favLineOffsetX;this.favCellObj.style.top=document.favLineOffsetY;this.favCellObj.title="Drag a cell over here to delete it";this.favCellObj.onmousedown=function(){document.onselectstart=function(){return false;};this.ondragstart=function(){return false;};return false;}}
function addFavLineCell(){this.favCellObj=document.createElement("li");cellIcon=document.createElement("img");this.favCellObj.appendChild(cellIcon);cellIcon.src="gui/plusend.jpg";this.favCellObj.className="favLineAdd";cellIcon.className="favLineAddIcon";this.favCellObj.style.left=document.favLineOffsetX;this.favCellObj.style.top=document.favLineOffsetY;this.favCellObj.title="Click here to add a fave line";this.favCellObj.onmousedown=function(){document.onselectstart=function(){return false;};this.ondragstart=function(){return false;};return false;}
this.favCellObj.onclick=function(){if(lockFlag==true)return;document.costumFavLineInst.favTblBody.addNewLine();}}
function favCell(cellLink,favIcon,rowIndex,cellIndex){this.favCellObj=document.createElement("li");this.favCellObj.moveImg=document.createElement("img");this.favCellObj.favIcon=document.createElement("img");divText=document.createElement("div");newText=document.createTextNode("");this.favCellObj.appendChild(this.favCellObj.moveImg);this.favCellObj.appendChild(divText);divText.appendChild(newText);this.favCellObj.appendChild(this.favCellObj.favIcon);this.favCellObj.rowIndex=rowIndex;this.favCellObj.cellIndex=cellIndex;if(!favIcon||favIcon=="")favIcon="gui/holder.gif";if(!cellLink||cellLink=="")
{cellLink="";this.favCellObj.vacant=true;this.favCellObj.favIcon.className="DBIcon";this.favCellObj.favIcon.style.display="none";this.favCellObj.title="Click to enter a site";}
else
{this.favCellObj.vacant=false;this.favCellObj.favIcon.className="favIcon";this.favCellObj.title=cellLink;}
this.favCellObj.cellLink=cellLink;this.favCellObj.cellText=newText;this.favCellObj.style.left=document.favLineOffsetX;this.favCellObj.style.top=document.favLineOffsetY;this.favCellObj.className="favCell";this.favCellObj.style.height=document.favCellHeight+'px';this.favCellObj.style.width=document.favCellWidth+'px';this.favCellObj.moveImg.src="gui/cellMouseOver.gif";this.favCellObj.moveImg.width="20";this.favCellObj.moveImg.height="21";this.favCellObj.favIcon.src=favIcon;this.favCellObj.favIcon.width="73";this.favCellObj.favIcon.height="23";divText.className="cellText";this.favCellObj.moveImg.className="moveImg";this.favCellObj.style.cursor="pointer";this.favCellObj.checkHit=function(curX,curY){if(document.documentElement.scrollTop)curY+=document.documentElement.scrollTop;else curY+=document.body.scrollTop;if(document.documentElement.scrollTop)curX+=document.documentElement.scrollLeft;else curX+=document.body.scrollLeft;cellCollection=this.parentNode.childNodes;for(cellIndx=0;cellIndx<cellCollection.length;cellIndx++){if((cellCollection[cellIndx]!=this)&&(curY>cellCollection[cellIndx].offsetTop)&&(curY<cellCollection[cellIndx].offsetTop+cellCollection[cellIndx].offsetHeight)&&(curX>cellCollection[cellIndx].offsetLeft)&&(curX<cellCollection[cellIndx].offsetLeft+cellCollection[cellIndx].offsetWidth))
{if((cellCollection[cellIndx].className=="favLineDel")||(cellCollection[cellIndx].className=="favLineAdd"))
return;else
if(cellCollection[cellIndx].className=="favBin")
this.deleteContent();else
this.swapContent(cellCollection[cellIndx]);}}}
this.favCellObj.deleteContent=function(){this.cellLink="";this.favIcon.src="gui/holder.gif";this.vacant=true;this.title="Click to enter a site";this.favIcon.className="DBIcon";this.className="favCell";this.favIcon.style.display="none";sendMSG('cellServices.php','actionType=delCell&rowIndx='+URLEncode(this.rowIndex)+'&cellIndx='+URLEncode(this.cellIndex),'delCell');}
this.favCellObj.swapContent=function(targetObj){tempLink=this.cellLink;tempVacant=this.vacant;tempfavIcon=this.favIcon.src;tempClass=this.className;tempIconClass=this.favIcon.className;tempTitle=this.title;this.cellLink=targetObj.cellLink;this.vacant=targetObj.vacant;this.favIcon.src=targetObj.favIcon.src;this.className=targetObj.className;this.favIcon.className=targetObj.favIcon.className;this.title=targetObj.title;targetObj.cellLink=tempLink;targetObj.vacant=tempVacant;targetObj.favIcon.src=tempfavIcon;targetObj.className=tempClass;targetObj.favIcon.className=tempIconClass;targetObj.title=tempTitle;targetObj.onmouseout();sendMSG('cellServices.php','actionType=swapCell&rowIndx='+URLEncode(this.rowIndex)+'&cellIndx='+URLEncode(this.cellIndex)+'&targetCellIndx='+URLEncode(targetObj.cellIndex),'swapCell');}
this.favCellObj.updateDB=function(){msgContent="updateType=cellInfo&rowindx="+this.rowindex+"&cellindx="+this.cellindex+"&icontype="+this.className;sendMSG('updateInfo.php',msgContent,"cellInfoUpdate");}
this.favCellObj.onmouseover=function(){if(lockFlag==true)return;if(!this.parentNode.dragMode)
{if(this.vacant)
{this.favIcon.style.display="block";}else
{moveImg=this.getElementsByTagName("img")[0];moveImg.style.visibility="visible";}}}
this.favCellObj.onmouseout=function(){if(!this.parentNode.dragMode)
{moveImg=this.getElementsByTagName("img")[0];moveImg.style.visibility="hidden";if(this.vacant)
{this.favIcon.style.display="none";}else
{this.favIcon.style.display="block";}}}
this.favCellObj.onmousedown=function(eventObj){if(eventObj==null)eventObj=window.event;if(eventObj.which){if(eventObj.which!=1)return;}
if(eventObj.button){if(eventObj.button!=1)return;}
if(lockFlag==true)return;document.draggedObj=this;document.startX=eventObj.clientX;document.startY=eventObj.clientY;document.offsetX=ExtractNumber(this.style.left);document.offsetY=ExtractNumber(this.style.top);document.oldZIndex=this.style.zIndex;document.draggedObj.clickFlag="down";this.parentNode.dragMode=true;document.onselectstart=function(){return false;};this.ondragstart=function(){return false;};document.timeoutID=setTimeout('document.draggedObj.clickFlag="drag"; document.draggedObj.startCellDrag();',200);document.onmouseup=function(eventObj){document.draggedObj.parentNode.dragMode=false;if(document.timeoutID)clearTimeout(document.timeoutID);if(document.draggedObj.clickFlag=="down")
{document.draggedObj.clickFlag="up";if(document.draggedObj.vacant)
{floatDivWin("open");}
else
{window.open(document.draggedObj.cellLink,"_blank");}}
else
{if(eventObj==null)eventObj=window.event;document.draggedObj.style.zIndex=document.oldZIndex;document.draggedObj.style.cursor="default"
document.draggedObj.style.left=(document.offsetX)+'px';document.draggedObj.style.top=(document.offsetY)+'px';document.draggedObj.checkHit(eventObj.clientX,eventObj.clientY);document.draggedObj.onmouseout();changeOpac(document.draggedObj,100);document.onmousemove=null;document.onselectstart=null;document.onmouseup=null;}}
return false;}
this.favCellObj.startCellDrag=function(){if(this.clickFlag=="drag")
{changeOpac(this,50);this.style.zIndex=10000;this.style.cursor="move";document.onmousemove=function(eventObj){if(eventObj==null)eventObj=window.event;document.draggedObj.style.left=(document.offsetX+eventObj.clientX-document.startX)+'px';document.draggedObj.style.top=(document.offsetY+eventObj.clientY-document.startY)+'px';}}}}
function favLine(rowIndex){this.favLineObj=document.createElement("ul");this.favLineObj.className="favLine";this.favLineObj.rowIndex=rowIndex;}
favLine.prototype.addCell=function(cellObj){this.favLineObj.appendChild(cellObj.favCellObj);}
favLine.prototype.addCellArr=function(linkArr,iconArr){for(cellIndx=0;cellIndx<linkArr.length;cellIndx++){favCellInst=new favCell(linkArr[cellIndx],iconArr[cellIndx],this.favLineObj.rowIndex,cellIndx);this.addCell(favCellInst);}
binInst=new recyclebinCell();this.addCell(binInst);if(this.favLineObj.rowIndex>0){delFavLineInst=new delFavLineCell(this.favLineObj.rowIndex);this.addCell(delFavLineInst);}
else
{addFavLineInst=new addFavLineCell();this.addCell(addFavLineInst);}}

function customFav(ObjWrapper,MaxLines,CellsInLine){
this.favTbl=document.createElement("table");
this.favTbl.setAttribute('id','favTbl');
this.favTblHeader=document.createElement("thead");this.favTblBody=document.createElement("tbody");this.favTbl.className="favTbl";ObjWrapper.appendChild(this.favTbl);this.favTbl.appendChild(this.favTblHeader);this.favTbl.appendChild(this.favTblBody);trObj=document.createElement("tr");thObj=document.createElement("th");this.favTblHeader.appendChild(trObj);trObj.appendChild(thObj);this.favTblBody.CellsInLine=CellsInLine;this.favTblBody.MaxLines=MaxLines;this.CellsInLine=CellsInLine;this.favTblBody.addLine=function(LinkArr,IconArr,botAddition){if(this.childNodes.length>=this.MaxLines)return;favLineInst=new favLine(this.childNodes.length);trObj=document.createElement("tr");tdObj=document.createElement("td");this.appendChild(trObj);trObj.appendChild(tdObj);tdObj.innerHTML="&nbsp;My Faves ";tdObj.className="favLineHeader";tdObj=document.createElement("td");trObj.appendChild(tdObj);tdObj.appendChild(favLineInst.favLineObj);favLineInst.addCellArr(LinkArr,IconArr);if(!botAddition)sendMSG('cellServices.php','actionType=addLine&rowIndx='+URLEncode(this.childNodes.length-1),'getNLCellInfo');}
this.favTblBody.addNewLine=function(botAddition){var LinkArr=new Array();var IconArr=new Array();for(cellIndx=0;cellIndx<this.CellsInLine;cellIndx++){LinkArr[cellIndx]="";IconArr[cellIndx]="";}
this.addLine(LinkArr,IconArr,botAddition);}
customFav.prototype.setCellInfo=function(CellInfo){if(!CellInfo)return;if(CellInfo=='')return;lineCollection=this.favTblBody.childNodes;if(lineCollection.length<=CellInfo[0]){this.favTblBody.addNewLine(true);}
if(CellInfo[1]>=this.favTblBody.CellsInLine)return;currRow=this.favTblBody.rows[CellInfo[0]];currCellWrapper=currRow.cells[1].firstChild;cellsCollection=currCellWrapper.childNodes;currCell=cellsCollection[CellInfo[1]];if(CellInfo[4]!=''){currCell.cellLink=CellInfo[3];currCell.vacant=false;currCell.title=CellInfo[3];currCell.favIcon.src=CellInfo[4];currCell.favIcon.style.display="block";if(CellInfo[2]=='favicon')
currCell.favIcon.className="favIcon";else{currCell.favIcon.className="DBIcon";currCell.favIcon.height="25";currCell.favIcon.width="75";currCell.className="favLogoCell";}}}
customFav.prototype.clearLines=function(){lineCollection=this.favTblBody.childNodes;for(custLine=0;custLine<lineCollection.length;custLine++){this.favTblBody.removeChild(lineCollection[custLine]);}}}

function constructFavArr(MaxLines,CellsInLine){
	costumFavLineInst=new customFav(document.getElementById("favLineWrapper"),MaxLines,CellsInLine);
	costumFavLineInst.favTblBody.addNewLine(true);
	coverImgObj=document.getElementById("coverImg");
	if(coverImgObj)
		coverImgObj.style.display="block";
	document.costumFavLineInst=costumFavLineInst;
}







