//***********************************
// feeds.js
// 12.10.07
// 
//
//************************************




// get window size and subtract 200 from width and 100 from height
	
	function greySize() {
		  var myWidth = 0, myHeight = 0;
		  
		  if( typeof( window.innerWidth ) == 'number' ) {

		  //Non-IE
		    myWidth = window.innerWidth;
		    myHeight = window.innerHeight;

		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

		  //IE 6+ in 'standards compliant mode'
		    myWidth = document.documentElement.clientWidth;
		    myHeight = document.documentElement.clientHeight;

		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

		  //IE 4 compatible
		    myWidth = document.body.clientWidth;
		    myHeight = document.body.clientHeight;
		  }
		    gbWidth = myWidth - 200
		    gbHeight = myHeight - 100
		    
		   // alert(gbWidth + " h " + gbHeight)
	  
	  }
 

 
 
	function showGrey() {
		var url = 'http://www.linkcity.org/rss/rss_admin.asp?a='+encodeURIComponent(document.frm_clickSort.a.value)
		
		
			// get window sizes		

			greySize();
			return GB_showCenter("", url,gbHeight,gbWidth);
	}
	
	function changeTheme() {
		var url = 'http://www.linkcity.org/rss/rss_theme.asp?a=choose'	

			// get window sizes		
			
			greySize();
			return GB_showCenter("", url,gbHeight,gbWidth);
	}
	
	
	
	
	
	
	//***************************
	
	
	
	
	// DOM Functions
	// *******************
	
	
			function addLI(){
				var Parent = document.getElementById("sortable_list");
				var NewLI = document.createElement("LI");
				var newName = document.getElementById("newFeedURL").value;

					NewLI.innerHTML = newName;
					NewLI.className = "admin_list_item_new";
					NewLI.setAttribute("id", newName);
				//	NewLI.setAttribute("f", newName);

				Parent.insertBefore(NewLI, Parent.firstChild);
				
				showMessage('Feed Added');
				
				document.frm_clickSort.newFeedURL.value = "";
				
				

			Sortable.create("sortable_list",{dropOnEmpty:false,containment:["sortable_list","sortable_trash"],constraint:false});
			Sortable.create("sortable_trash",{dropOnEmpty:false,containment:["sortable_list","sortable_trash"],constraint:false});
				
			}
			
			
			
			
			
			
			function addLI_inline(uri){
				var Parent = document.getElementById("sortable_list");
				var NewLI = document.createElement("LI");
				var newName = uri;

					NewLI.innerHTML = newName;
					NewLI.className = "admin_list_item_new";
					NewLI.setAttribute("id", newName);
				//	NewLI.setAttribute("f", newName);

				Parent.insertBefore(NewLI, Parent.firstChild);
				
				 showMessage_lower('Feed added to your queue, close this window when you are done adding feeds.');
				
				// document.frm_clickSort.newFeedURL.value = "";
				
				
				
				

			Sortable.create("sortable_list",{dropOnEmpty:false,containment:["sortable_list","sortable_trash"],constraint:false});
			Sortable.create("sortable_trash",{dropOnEmpty:false,containment:["sortable_list","sortable_trash"],constraint:false});
				
			}			
			
			
			

			function dropLI(){
				var Parent = document.getElementById("sortable_list");

			//	Parent.removeChild(document.getElementById("+todel+"));

			// this works inline on the image	this.parentNode.removeChild(this)


			 Sortable.create("sortable_list",{dropOnEmpty:false,containment:["sortable_list","sortable_trash"],constraint:false});
			 Sortable.create("sortable_trash",{dropOnEmpty:false,containment:["sortable_list","sortable_trash"],constraint:false});
			}
	
	
	
	
		// Cookie Functions
		// ********************
		// http://www.quirksmode.org/js/cookies.html
	
	
	
			function createCookie(name,value,days) {
				if (days) {
					var date = new Date();
					date.setTime(date.getTime()+(days*24*60*60*1000));
					var expires = "; expires="+date.toGMTString();
				}
				else var 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);
			}
	
		// end cookie functions
		//
		// ************************
	
	
	
	
	
	
	
		// Get order of resorted feeds write cookie, close greybox
		// and refresh parent
		// ************************
	
	
			function openLoadingScreen(){
				// Effect.toggle('loading_screen','APPEAR');
				Effect.Appear('loading_screen', { duration: 1.0,from: 0.0, to: 1.0 } );
			}
			
			
			
			function showMessage(txt){
				
				Effect.Appear('conf_msg_box', { duration: 3.0 });
				
				document.getElementById("conf_msg_box").innerHTML = txt
				setTimeout("killMessage()",4000);
				
			}
			
			
			
				function killMessage(){
					Effect.Appear('conf_msg_box', { duration: 2.0,from: 1.0, to: 0.0} );
				}
			
			
			function showMessage_lower(txt){
							
				Effect.Appear('conf_msg_box-lower', { duration: 1.0 });
							
				document.getElementById("conf_msg_box-lower").innerHTML = txt
				setTimeout("killMessage_lower()",4000);
							
			}
			
				function killMessage_lower(){
					Effect.Appear('conf_msg_box-lower', { duration: 1.0,from: 1.0, to: 0.0} );
					
				}
			
			

			function getOrder() {
			
				openLoadingScreen();
				var orderList = '';
				orderedNodes = document.getElementById("sortable_list").getElementsByTagName("li");

					for (var i=0;i < orderedNodes.length;i++) {
						orderList += orderedNodes[i].getAttribute('id') + ', ';
					}

				document.getElementById('reFeedList').value = orderList;

				createCookie('liNKCity_feeds',orderList,365);

			//	 alert(orderList);

				//	var x = readCookie('liNKCity_feeds')
				//	 if (x) {
				//	 	alert("cookie has value " + orderList);
				//	 }
				

				window.top.location.reload();


					 

					// document.getElementById('frm_feedList').submit();
					// alert(document.getElementById('reFeedList').value);
			
			}
			
			// rss_admin.asp open loading screen 
			
			function getOrderClose(){
				var orderList = '';
				orderedNodes = document.getElementById("sortable_list").getElementsByTagName("li");

					for (var i=0;i < orderedNodes.length;i++) {
						orderList += orderedNodes[i].getAttribute('id') + ', ';
					}

				document.getElementById('reFeedList').value = orderList;

				createCookie('liNKCity_feeds',orderList,365);
				
			//	alert(orderList + "getOrderClose");							
				
				window.top.location.reload();
			}
			
			
			function ieLoadingScreenSave(){
				Effect.Appear('loading_screen', { duration: 1,from:0.0-1.0, afterFinish: function() { getOrderClose() }});
				
			}
			
				function getOrderHideAdd() {
					var orderList = '';
					orderedNodes = document.getElementById("sortable_list").getElementsByTagName("li");

						for (var i=0;i < orderedNodes.length;i++) {
							orderList += orderedNodes[i].getAttribute('id') + ', ';
						}

					document.getElementById('reFeedList').value = orderList;

					createCookie('liNKCity_feeds',orderList,365);
					
			//		alert(orderList + "getOrderHideAdd");	

					Effect.toggle('add_stuff_div','APPEAR');


						
			}
			
			
			
			function setTheme(theme){
			
				createCookie('liNKCity_feeds_theme',theme,365);
				
				openLoadingScreen();
				
				window.top.location.reload();
				
			}
	
	
	
	
	
	   