var http_request = false;
var globe_url;
var globe_parameters;

function stopWait()
{
	document.getElementById("waitdiv").style.display='none';
}
function startWait()
{
	document.getElementById("waitdiv").style.display='block';
}
function callFavorites(where,stat)
{
        myDate = new Date ();
        myDate.setFullYear(2999,01,01);
        document.cookie ='mylinksStat='+stat+';expires='+ myDate.toGMTString() + '; path=/';

	$("#mylinks").load("mylinks/mylinks.php", { 'stat': stat, 'myid': where });
}

function get(obj,stat) {
	//startWait();
	var poststr = "stat=" + encodeURI(stat) + "&myid=" + encodeURI(obj);
	//makePOSTRequest('mylinks/mylinks.php', poststr);
	$("#mylinks").load("mylinks/mylinks.php", { 'stat': stat, 'myid': obj });
	//setCategories();
	//stopWait();
}
function getChmail(obj,ext,addr) {
	startWait();
	var mymail ='';var email='';
	if ( ext == 0 )
	{
		mymail = encodeURI( addr );
		email="mymail";
	}
	if ( ext == 1 )
	{
		//mymail = encodeURI( document.getElementById("email").value );
		mymail = document.getElementById("email").value ;
		email="email";
	}
	if ( ext == 3 )
	{
		mymail = encodeURI( addr );
		email ="remind";
	}
	//var poststr = "myid=chmail&sent="+encodeURI(ext)+"&"+email+"=" + encodeURI( mymail) ;
	//makePOSTRequest('mylinks/mylinks.php', poststr);
	$("#mylinks").load("mylinks/mylinks.php", { 'myid': 'chmail','sent':ext,email:mymail });
	stopWait();
}
function getRegistration(obj,extra) {
	//startWait();
	var takan ="off";
	if (document.getElementById('takan').checked==true )
	{
		takan = "on";
	}
	var poststr = "myid:registration,sent:1,fname:" + encodeURI( document.getElementById("fname").value ) +
			",lname:" + encodeURI( document.getElementById("lname").value ) +
			",email:" + encodeURI( document.getElementById("email").value ) +
			",pass:" + encodeURI( document.getElementById("pass").value ) +
			",takan:" + takan  +
			",seccode:" + encodeURI( document.getElementById("seccode").value ) +
			",pass2:" + encodeURI( document.getElementById("pass2").value ) ;
	if ( extra != "" )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'registration','sent':'1','fname':document.getElementById("fname").value,'lname':document.getElementById("lname").value,'email':document.getElementById("email").value,'pass':document.getElementById("pass").value,'takan':takan,'seccode': document.getElementById("seccode").value,'pass2':document.getElementById("pass2").value,'extra':extra });
	}
	else
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'registration','sent':'1','fname':document.getElementById("fname").value,'lname':document.getElementById("lname").value,'email':document.getElementById("email").value,'pass':document.getElementById("pass").value,'takan':takan,'seccode': document.getElementById("seccode").value,'pass2':document.getElementById("pass2").value });
	}
	stopWait();
}

function getSeccode() {
	var img = 'http://www.link4u.co.il/mylinks/randomImage.php?1='+Math.random();
	document.getElementById('secimg').src=img
}

function getLogin(obj,extra) {

	var remember ="off";
	if (document.getElementById('remember').checked==true )
	{
		remember = "on";
	}
	if ( remember != "" )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'login','sent':'1','email':document.getElementById("email").value,'pass': document.getElementById("pass").value,'remember':remember });
	}
	else
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'login','sent':'1','email':document.getElementById("email").value,'pass': document.getElementById("pass").value });
	}
}
function getReminder(obj,extra) {
	//startWait();
	var poststr = "myid:reminder"   ;
	if ( extra == "1" )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'reminder','sent':'1','email':document.getElementById("email").value });
	}
	else
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'reminder' });
	}
}
function logOut() {
	$("#mylinks").load("mylinks/mylinks.php", { 'myid':'mylinks','logout':'1' });
	OpenFav("");
}
// JavaScript Document
function OpenFav(stt){
	//alert('dddd' + stt);
	if ( stt == "open" ){
		var block ="none";
	}
	else
	{
		var block = "block";
	}
	document.getElementById('sel1').style.display=block;
	document.getElementById('sel2').style.display=block;
	document.getElementById('sel3').style.display=block;
}

function FavTitleOpen(titleId,islink){	
	document.getElementById(titleId).style.cursor="pointer";
	document.getElementById(titleId).style.backgroundColor = "#F4FAFF";	
	document.getElementById('fmenu-'+titleId).style.display='block';
	if ( islink == "1" )
		document.getElementById(titleId+"-txt").style.color = "#AB2F00";
	var browser = new Array();
	browser = getBrowser();	
	if( browser[0] == "IE" && browser[1] =="6")	
	document.getElementById("openlinks").style.marginRight = "1px";
}

function FavTitleClose(titleId,islink){	
	document.getElementById(titleId).style.cursor="pointer";
	document.getElementById(titleId).style.backgroundColor = "#FFFFFF";
	document.getElementById('fmenu-'+titleId).style.display='none';
	if ( islink == "1" )
		document.getElementById(titleId+"-txt").style.color = "#0A61A8";
	var browser = new Array();
	browser = getBrowser();	
	if( browser[0] == "IE" && browser[1] =="6")	
	document.getElementById("openlinks").style.marginRight = "1px";
}
function CommentOpen(iconId,itemId){
	var theBrowser = navigator.appName;
	document.getElementById(iconId+'-'+itemId).src='./mylinks/img/'+iconId+'-over.gif';
	document.getElementById('wincomment-'+itemId).style.display='block'
	document.getElementById(iconId+'-'+itemId+"-txt").style.display='block';	
	if(iconId=='icon-edit'){
		if(theBrowser=='Netscape'){
			document.getElementById('wincomment-'+itemId).style.margin='-50px -15px 0px 0px';
		}else{	
			document.getElementById('wincomment-'+itemId).style.margin='-50px -105px 0px 0px';
		}
	}else if(iconId=='icon-add'){
		if(theBrowser=='Netscape'){
			document.getElementById('wincomment-'+itemId).style.margin='-50px -30px 0px 0px';
		}else{	
			document.getElementById('wincomment-'+itemId).style.margin='-50px -120px 0px 0px';
		}
	}else if(iconId=='icon-delete'){
		if(theBrowser=='Netscape'){
			document.getElementById('wincomment-'+itemId).style.margin='-50px 0px 0px 0px';
		}else{	
			document.getElementById('wincomment-'+itemId).style.margin='-50px -90px 0px 0px';
		}
	}else if(iconId=='icon-up'){
		if(theBrowser=='Netscape'){
			document.getElementById('wincomment-'+itemId).style.margin='-50px 15px 0px 0px';
		}else{	
			document.getElementById('wincomment-'+itemId).style.margin='-50px -75px 0px 0px';
		}
	}else {
		if(theBrowser=='Netscape'){
			document.getElementById('wincomment-'+itemId).style.margin='-50px 30px 0px 0px';
		}else{	
			document.getElementById('wincomment-'+itemId).style.margin='-50px -60px 0px 0px';
		}
	}
	
}
function CommentClose(iconId,itemId){
	document.getElementById(iconId+'-'+itemId).src='./mylinks/img/'+iconId+'.gif';
	document.getElementById('wincomment-'+itemId).style.display='none';
	document.getElementById(iconId+'-'+itemId+"-txt").style.display='none';	
}

function setCategories()
{
	//startWait();
	window.onload = init();
	function init() {
		alert('0');
		junkdrawer.restoreListOrder("cat1");
		alert('1');
		dragsort.makeListSortable(document.getElementById("cat1"), verticalOnly, saveOrder);
		alert('2');
	}
	function verticalOnly(item) {
		item.toolManDragGroup.verticalOnly()
	}
	function speak(id, what) {
		var element = document.getElementById(id);
		element.innerHTML = 'Clicked ' + what;
	}
	function saveOrder(item) {
		var group = item.toolManDragGroup;
		var list = group.element.parentNode;
		var id = list.getAttribute("id");
		if (id == null) return
			group.register('dragend', function() { ToolMan.cookies().set("list-" + id, junkdrawer.serializeList(list), 365) })
	}
	//stopWait();
}
function getCategory(obj,extra) {
	var poststr = "myid:category,do:"+obj   ;
	if ( obj =="edit" )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'category','do':obj,'sent':'1','uid':extra });
	}else if ( extra == "1" )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'category','do':obj,'sent':'1','name':document.getElementById("name").value });
	}
	else
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'category','do':obj });
	}
}
function editCategory(obj,uid,extra) {
	if ( uid != "" && extra != "" )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'category','do':obj,'sent':'1','uid':uid,'name':document.getElementById("name").value });
	}
	else if ( extra != "" )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'category','do':obj,'sent':'1','name':document.getElementById("name").value });
	}
	else if ( uid != ""  )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'category','do':obj,'sent':'1','uid':uid });
	}
	else
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'category','do':obj });
	}
}
function getLink(obj,extra) {
	//startWait();
	if ( obj =="edit" )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'link','do':obj,'sent':'0','uid':extra });
	}else if ( extra == "1" )
	{
		//poststr = poststr + ",sent:1,name:" + encodeURI( document.getElementById("name").value );
		//poststr = poststr + ",url:" + encodeURIComponent( document.getElementById("url").value );
		//poststr = poststr + ",cat:" + encodeURI( document.getElementById("mycat").value );
		//poststr = poststr + ",newcat:" + encodeURI( document.getElementById("newcat").value );
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'link','do':obj,'sent':'1','name':document.getElementById("name").value,'url':document.getElementById("url").value,'cat': document.getElementById("mycat").value,'newcat':document.getElementById("newcat").value });
	}
	else
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'link','do':obj });
	}
}
function editLink(obj,uid,extra) {
	//startWait();
	var poststr = "myid:link,do:"+obj   ;
	if ( extra != "" && uid != "")
	{
		//poststr = poststr + ",sent:1,uid:" + uid;
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'link','do':obj,'sent':'1','uid':uid,'name':document.getElementById("name").value,'url':document.getElementById("url").value,'cat':document.getElementById("mycat").value,'newcat':document.getElementById("newcat").value });
	}
	else if ( extra != "" )
	{ 
		//poststr = poststr + ",sent:1,name:" + encodeURI( document.getElementById("name").value); 
		//poststr = poststr + ",url:" + encodeURIComponent( document.getElementById("url").value );
		//poststr = poststr + ",cat:" + encodeURI( document.getElementById("mycat").value );
		//poststr = poststr + ",newcat:" + encodeURI( document.getElementById("newcat").value );
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'link','do':obj,'sent':'1','name':document.getElementById("name").value,'url':document.getElementById("url").value,'cat':document.getElementById("mycat").value,'newcat':document.getElementById("newcat").value });
	}
	else if ( uid != "" )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'link','do':obj,'sent':'1','uid':uid });
	}
	else
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':'link','do':obj });
	}
}
function getDelete(obj,extra) {
	if ( extra != "" )
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':obj,'do':'del','uid':extra });
	}
	else
	{
		$("#mylinks").load("mylinks/mylinks.php", { 'myid':obj,'do':'del' });
	}
}

function getReorder(obj,to,uid) 
{
	$("#mylinks").load("mylinks/mylinks.php", { 'myid':obj,'do':'reorder','move':to,'uid':uid });
}

function keyup(what,maxlen,whereto) 
{
	var str = new String(what.value);
	var len = str.length;
	var showstr = maxlen-len;
	txtshow( showstr,whereto );
}
function txtshow( txt2show,where ) {
	var IE = (document.all) ? 1 : 0;
	var DOM = 0; 
	if (parseInt(navigator.appVersion) >=5) {DOM=1};

	// Detect Browser
	if (DOM) {
		var viewer = document.getElementById(where);
		viewer.innerHTML=txt2show;
	}
	else if(IE) {
		document.all[where].innerHTML=txt2show;
	}
}
/**
* Confirmation message
*/
function confirmLink(theQuery)
{
	var is_confirmed = confirm(theQuery);
	return is_confirmed;
} // end of the 'confirmLink()' function

function getBrowser()
{
	var nVer = navigator.appVersion;
	var nAgt = navigator.userAgent;
	var browserName  = '';
	var fullVersion  = 0; 
	var majorVersion = 0;

	// In Internet Explorer, the true version is after "MSIE" in userAgent
	if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
		 browserName  = "IE";
		 fullVersion  = parseFloat(nAgt.substring(verOffset+5));
		 majorVersion = parseInt(''+fullVersion);
	}
	// In Opera, the true version is after "Opera" 
	else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
		 browserName  = "Opera";
		 fullVersion  = parseFloat(nAgt.substring(verOffset+6));
		 majorVersion = parseInt(''+fullVersion);
	}
	// In Firefox, the true version is after "Firefox" 
	else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
		 browserName  = "Firefox";
		 fullVersion  = parseFloat(nAgt.substring(verOffset+8));
		 majorVersion = parseInt(''+fullVersion);
	}
	// In most other browsers, "name/version" is at the end of userAgent 
	else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
	{
		 browserName  = nAgt.substring(nameOffset,verOffset);
		 fullVersion  = parseFloat(nAgt.substring(verOffset+1));
		 if (!isNaN(fullVersion)) majorVersion = parseInt(''+fullVersion);
		 else {fullVersion  = 0; majorVersion = 0;}
	}
	// Finally, if no name and/or no version detected from userAgent...
	if (browserName.toLowerCase() == browserName.toUpperCase() || fullVersion==0 || majorVersion == 0 )
	{
		 browserName  = navigator.appName;
		 fullVersion  = parseFloat(nVer);
		 majorVersion = parseInt(nVer);
	}
	var ret = new Array();
	ret[0] = browserName;
	ret[1] = fullVersion;
	ret[2] = majorVersion;
	ret[3] = navigator.appName;
	ret[4] = navigator.userAgent;
	return ret;
}
function openCat(itemid,arr){
	var cattbl = 'cat'+itemid;
	var catimg = 'cat-img'+itemid;
	if ( document.getElementById(cattbl).style.display == 'block')
	{
		closeCat(arr);
		document.getElementById(cattbl).style.display = 'none';
		document.getElementById(catimg).src = './mylinks/img/folder-green.gif';
		Set_Cookie( 'mylinksOpenCat', '', '100', '', '', '' );
	}else{
		closeCat(arr);
		document.getElementById(cattbl).style.display = 'block';
		document.getElementById(catimg).src = './mylinks/img/folder-red.gif';
		Set_Cookie( 'mylinksOpenCat', itemid, '100', '', '', '' );
	}
}
function closeCat(item){
        var itemid = item.split('~');
        for (var i=0; i<itemid.length; i++)
        {

        var cattbl = 'cat'+itemid[i];
        var catimg = 'cat-img'+itemid[i];
                document.getElementById(cattbl).style.display = 'none';
                document.getElementById(catimg).src = './mylinks/img/folder-green.gif';
        }
}
function reorderList(category,items)
{
	//var poststr = "myid:reorder,cat:"+category   ;
	//poststr = poststr + ",items:" + encodeURI(items);
	$("#mylinks").load("mylinks/mylinks.php", { 'myid':'reorder','cat':category,'items':encodeURI(items) });

}

function Set_Cookie( name, value, expires, path, domain, secure )
{
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );

        /*
        if the expires variable is set, make the correct 
        expires time, the current script below will set 
        it for x number of days, to make it for hours, 
        delete * 24, for minutes, delete * 60 * 24
        */
        if ( expires )
        {
                expires = expires  * 60 * 60 * 24;
        }
        var expires_date = new Date( today.getTime() + (expires) );

        document.cookie = name + "=" +escape( value ) +
                ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
                ( ( path ) ? ";path=" + path : "" ) +
                ( ( domain ) ? ";domain=" + domain : "" ) +
                ( ( secure ) ? ";secure" : "" );
}

