if (top!=self) top.location=self.location;

// preload scroll onmouseover images
preImgSrc = new Array (
        "/images/jweekly/header_background.jpg"
)

preImgList = new Array ();

for (var x=0; x < preImgSrc.length; x++) {
	preImgList[x] = new Image();
	preImgList[x].src = preImgSrc[x];
}


sfHover = function() {
	var sfEls = document.getElementById("top_menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	
	sfEls = document.getElementById("middle_menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	
	sfEls = document.getElementById("bottom_menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function showTab(anchorId, contentId) {

	
	var anchorParent = anchorId.parentNode;
	ahrefs = anchorParent.getElementsByTagName("a");
	
	for (var i=0; i < ahrefs.length; i++) {
		ahrefs[i].firstChild.className = "tab";
	}
	anchorId.firstChild.className = "tab_active";
	
	var contentParent = document.getElementById(contentId).parentNode;
	for (var i=0; i < contentParent.childNodes.length; i++) {
		if(contentParent.childNodes[i].nodeName == "DIV") {
			contentParent.childNodes[i].style.visibility = "hidden";
		}
	}
	document.getElementById(contentId).style.visibility = "visible";
	

}

function modalGiveaway(title, image, summary) {

	//this is code to display a modal window for Giveaways

	//if(getCookie("giveaway") != "shown") {

		

		setCookie("giveaway", "shown", null);

		var pop = ''

		pop += '<div id="popup">';


		pop += '<table border="0" cellspacing="0" cellpadding="4">';
		pop += '<tr>';
		pop += '<td style="padding-right:10px;">';
		pop += image;
		pop += '</td>';
		pop += '<td style="text-align:left;">';
		pop += '<h3>' + title + '</h3><br />';
		pop += summary;
		pop += '</td>';
		pop += '</tr>';
		pop += '</table>';

		pop += '<a href="/giveaway/">Click for Details</a> | <a href="" onclick="javascript:return hideModal();">Close X</a></div>';

		document.write('<div id="cover"></div>');

		document.write(pop);



	//}
}


function hideModal() {

	document.getElementById('cover').style.visibility = "hidden";

	document.getElementById('popup').style.visibility = "hidden";
	return false;

}

function homepageBoxHeight() {

	var issueHeight = new Array();
	var issueDiv = document.getElementById("issue_content");
	
	var index = 0;
	for (var i = 0; i < issueDiv.childNodes.length; i++) {
		
		if(issueDiv.childNodes[i].nodeName == "DIV") {
			issueHeight[index] = issueDiv.childNodes[i].offsetHeight;
			index++;
		}
	
	}

	var height = 0;
	for(var i=0; i < issueHeight.length; i++) {
	
		if(issueHeight[i] > height)
			height = issueHeight[i];
		
	}
	
	
	issueDiv.style.height = height + "px";
	for (var i = 0; i < issueDiv.childNodes.length; i++) {
		
		if(issueDiv.childNodes[i].nodeName == "DIV") {
			issueDiv.childNodes[i].style.height = height + "px";
		}
		
	}
	
	
		
	///////////////////////////////////////////////////////////////////////////
	
	issueHeight = new Array();
	issueDiv = document.getElementById("extra_content");
	
	var index = 0;
	for (var i = 0; i < issueDiv.childNodes.length; i++) {
		
		if(issueDiv.childNodes[i].nodeName == "DIV") {
			issueHeight[index] = issueDiv.childNodes[i].offsetHeight;
			index++;
			
		}
	
	}

	var height = 0;
	for(var i=0; i < issueHeight.length; i++) {
	
		
		
		if(issueHeight[i] > height)
			height = issueHeight[i];
		
	}
	
	issueDiv.style.height = height + "px";
	for (var i = 0; i < issueDiv.childNodes.length; i++) {
		
		if(issueDiv.childNodes[i].nodeName == "DIV") {
			issueDiv.childNodes[i].style.height = height + "px";
		}
		
	}
	
	
}


function sidebarBlogsHeight() {

	var sidebarHeight = new Array();
	var sidebarDiv = document.getElementById("sidebar_content");
	
	var index = 0;
	for (var i = 0; i < sidebarDiv.childNodes.length; i++) {
		
		if(sidebarDiv.childNodes[i].nodeName == "DIV") {
			sidebarHeight[index] = sidebarDiv.childNodes[i].offsetHeight;
			index++;
		}
	
	}

	var height = 0;
	for(var i=0; i < sidebarHeight.length; i++) {
	
	
		if(sidebarHeight[i] > height)
			height = sidebarHeight[i];
		
	}
	
	height = height + 15;
	
	sidebarDiv.style.height = height + "px";
	for (var i = 0; i < sidebarDiv.childNodes.length; i++) {
		
		if(sidebarDiv.childNodes[i].nodeName == "DIV") {
			sidebarDiv.childNodes[i].style.height = height + "px";
			
		}
		
	}

}

function toggleBlogs(id) {
	
	var blogDiv = document.getElementById(id);
	var blogLink = document.getElementById("blogs_link");
	
	var sidebarDiv = document.getElementById("sidebar_content");
	var sidebarHeight = sidebarDiv.offsetHeight;
	
	if(blogDiv.style.display == 'none') {
		blogDiv.style.display = "block";
		blogLink.innerHTML = "hide blogs &gt;";
		
		var blogHeight = blogDiv.offsetHeight;
		
		sidebarDiv.style.height = (sidebarHeight + blogHeight - 22) + "px";
		document.getElementById("blogs_more").style.bottom = -blogHeight + "px";
		
	} else {
	
		var blogHeight = blogDiv.offsetHeight;
		
		blogDiv.style.display = "none";
		blogLink.innerHTML = "show all blogs &gt;";
		
		
		
		sidebarDiv.style.height = (sidebarHeight - blogHeight - 22) + "px";
		document.getElementById("blogs_more").style.bottom = "0";
		
	}
	
	return false;
}

function toggleFlagForm(id) {
	
	var flagForm = document.getElementById(id);
	
	if(flagForm.style.display == 'none' || flagForm.style.display == '') {
	
		flagForm.style.display = "block";
	
	} else {
		
		flagForm.style.display = "none";
		
	}
	
	return false;
}

function sidebarPopularHeight() {	
	
	var sidebarHeight = new Array();
	var sidebarDiv = document.getElementById("sidebar_popular");
	
	var index = 0;
	for (var i = 0; i < sidebarDiv.childNodes.length; i++) {
		
		if(sidebarDiv.childNodes[i].nodeName == "DIV") {
			sidebarHeight[index] = sidebarDiv.childNodes[i].offsetHeight;
			index++;
		}
	
	}

	var height = 0;
	for(var i=0; i < sidebarHeight.length; i++) {
	
		if(sidebarHeight[i] > height)
			height = sidebarHeight[i];
		
	}
	
	
	sidebarDiv.style.height = height + "px";
	for (var i = 0; i < sidebarDiv.childNodes.length; i++) {
		
		if(sidebarDiv.childNodes[i].nodeName == "DIV") {
			sidebarDiv.childNodes[i].style.height = height + "px";
			
		}
		
	}
	
}



function urlparam(name) {
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );
	if( results == null )
		return "";
	else
		return results[1];
}

function newxmlhttp() {
	
	var xml;
	xml = false;
	if(window.XMLHttpRequest && !(window.ActiveXObject)) {
		try {
			xml = new XMLHttpRequest();
		} catch(e) {
			xml = false;
		}
	} else if (window.ActiveXObject) {
		try {
			xml = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xml = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xml = false;
			}
		}
	}
	return xml;
}
	

function loadJTATicker () {
	
		
	tickerJTA = newxmlhttp();
	if(tickerJTA) {
		tickerJTA.open("GET", "/article/ticker_JTA", true);
		tickerJTA.setRequestHeader("Content-Type","text/html");
		tickerJTA.onreadystatechange = function() { 
			
			document.getElementById("jta_response").innerHTML = "Loading...";
				
			if(tickerJTA.readyState == 4) {
				// only if "OK"
				if(tickerJTA.status == 200) {
					document.getElementById("jta_response").innerHTML = tickerJTA.responseText;
				} else {
					document.getElementById("jta_response").innerHTML = "The JTA News Ticker is temporarily disabled";
				}
		}};
		tickerJTA.send(null);
	}
	
	
}

function loadYnetTicker () {
	
	tickerYnet = newxmlhttp();
	if(tickerYnet) {
		tickerYnet.open("GET", "/article/ticker_Ynet", true);
		tickerYnet.setRequestHeader("Content-Type","text/html");
		tickerYnet.onreadystatechange = function() { 
			
			document.getElementById("ynet_response").innerHTML = "Loading...";
			
			if(tickerYnet.readyState == 4) {
				// only if "OK"
				if(tickerYnet.status == 200) {
					document.getElementById("ynet_response").innerHTML = tickerYnet.responseText;
				} else {
					document.getElementById("ynet_response").innerHTML = "The Ynet News Ticker is temporarily disabled";
				}
		}};
		tickerYnet.send(null);
	}
	
	
}

function loadWordPressBlog(wpBlogName, wpFeedURL, location) {

	var wpBlog = getCookie("jweekly-" + wpBlogName);
	
	if(wpBlog == "") {
	
		wpBlog = newxmlhttp();
		if(wpBlog) {
			var wpParams = "wpBlogName=" + wpBlogName + "&wpFeedURL="+wpFeedURL;
			wpBlog.open("POST", "/includes/wordpress_blog", true);
			
			//wpBlog.setRequestHeader("Content-Type","text/html");
			wpBlog.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			//wpBlog.setRequestHeader("Content-length", wpParams.length);
			//wpBlog.setRequestHeader("Connection", "close");
			
			wpBlog.onreadystatechange = function() { 
			
				//document.getElementById(wpBlogName + "_response").innerHTML = "Loading...";
				
				if(wpBlog.readyState == 4) {
					// only if "OK"
					if(wpBlog.status == 200) {
						
						var wpResponse = wpBlog.responseText;
						var wpSeparator = wpResponse.indexOf("%separator%");
						var wpTitle = wpResponse.substring(0, wpSeparator);
						var wpDescription = wpResponse.substring(wpSeparator + 11);
						
						setCookie("jweekly-" + wpBlogName, "true", 1);
						setCookie("jweekly-" + wpBlogName + "-title", wpTitle, 1);
						setCookie("jweekly-" + wpBlogName + "-description", wpDescription, 1);
						
						if(location == "tab") {
		
							document.getElementById(wpBlogName+"-tab").innerHTML = wpTitle;
						}
							
						if(location == "home") {
							
							document.getElementById(wpBlogName+"-home").innerHTML = wpTitle;
							document.getElementById(wpBlogName+"-home").innerHTML += "<br />";
							document.getElementById(wpBlogName+"-home").innerHTML += wpDescription;
								
						}
						
					} 
				
			}};
			wpBlog.send(wpParams);
		}
	} else {
	
		if(location == "tab") {
		
			document.getElementById(wpBlogName+"-tab").innerHTML = getCookie("jweekly-"+wpBlogName+"-title");
		}
							
		if(location == "home") {
							
			document.getElementById(wpBlogName+"-home").innerHTML = getCookie("jweekly-"+wpBlogName+"-title");
			document.getElementById(wpBlogName+"-home").innerHTML += "<br />";
			document.getElementById(wpBlogName+"-home").innerHTML += getCookie("jweekly-"+wpBlogName+"-description");
								
		}
	}
	
}


function setCookie(c_name,value,expiredays) {

	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
	  	if (c_start!=-1) { 
	    		c_start=c_start + c_name.length+1; 
	    		c_end=document.cookie.indexOf(";",c_start);
	    		if (c_end==-1) 
	    			c_end=document.cookie.length;
	    		return unescape(document.cookie.substring(c_start,c_end));
	    	} 
	}
	return "";
}