var SIZE=1;
var loading="STATIC";
var rss_xmlHttp;
var ad_xmlHttp=new Array(SIZE);
var ad_position=new Array(SIZE);
var popup_blocked=false;
//var popup_checked=false;


function content_init()
{
	rss_xmlHttp=null;
	for ( i=0; i<SIZE;i++)
	{
		ad_xmlHttp[i]=null;
	}
	
	//ad_position[0]="content_row_ad2";
	ad_position[0]="column3_ad";
	ad_position[1]="content_row_ad2";
	//ad_position[2]="content_row_ad1";

}

 function addToFavorites() 
 { 
	 var urlAddress = "http://www.slimabs.com"; 
	 var pageName = "SlimAbs";
	if (window.external) 
	{ 
		window.external.AddFavorite(urlAddress,pageName);
	} 
	else if (window.sidebar) 
	{
		 // Mozilla Firefox Bookmark		
		window.sidebar.addPanel(pageName , urlAddress,"");	
	} else if(window.opera && window.print) { 
		// Opera Hotlist		
		return true; 
	}
	else 
	{ 
		alert("Sorry! Your browser doesn't support this function."); 
	} 
} 

function GetXmlHttpObject(handler)
{ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}
// This function loads AD content in a particular div container identified by index of the ad_position array

function loadAdContent( keyword, index)
{
	ad_xmlHttp[index]=GetXmlHttpObject();
	if (ad_xmlHttp[index]==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="adserve.php";
	url=url+"?ad_keyword="+escape(keyword) +"&ad_pos="+escape(ad_position[index]);
	//alert(url);
	ad_xmlHttp[index].onreadystatechange=stateChanged ;
	ad_xmlHttp[index].open("GET",url,true);
	ad_xmlHttp[index].send(null);
}

// This function loads RSS content in a particular div container
function loadRSSContent( keyword)
{
	rss_xmlHttp=GetXmlHttpObject();
	if (rss_xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="articles.php";
	url=url+"?rss_url="+ escape(keyword);
	rss_xmlHttp.onreadystatechange=stateChanged ;
	rss_xmlHttp.open("GET",url,true);
	rss_xmlHttp.send(null);
}
//this function loads Ads based on a keyword in all the locations. locations are defined by index to the ad_positions

function loadAds ( keyword )
{
	for (j=0; j<SIZE; j++)
	{
		loadAdContent(keyword, j);
	}
}

//this function loads a static web page
function loadPage( keyword)
{
	if ( keyword == "Health Food" )
	{
		window.open("nutrition.php","_self");
	}
	else if ( keyword == "Workout and Fitness" )
	{
		window.open("slimabs.php","_self");

	}
	else if ( keyword == "Weight Loss" )
	{
		window.open("weight_loss.php","_self");

	}
	else if ( keyword == "Yoga" )
	{
		window.open("yoga.php","_self");

	}
	else if ( keyword == "Meditation" )
	{
		window.open("meditation.php","_self");

	}
	else if ( keyword == "Exercise Machines" )
	{
		window.open("exercise_machines.php","_self");

	}
	else if ( keyword == "Hot Dates" )
	{
		window.open("hot_dates.php","_self");

	}
	else if ( keyword == "Beauty" )
	{
		window.open("beauty.php","_self");

	}
	else if ( keyword == "Hair Loss" )
	{
		window.open("hair_loss.php","_self");

	}
	else if ( keyword == "Anti Aging" )
	{
		window.open("anti_aging.php","_self");

	}
	else if ( keyword == "Eye care" )
	{
		window.open("eye_care.php","_self");

	}
	else if ( keyword == "Supplements" )
	{
		window.open("supplements.php","_self");

	}
}
//This function loads the RSS content and the ads for the particular keyword and is called from clicking on references.
function loadAll(keyword)
{
	if ( loading == "DYNAMIC")
	{
		content_init();
		loadRSSContent(keyword);
		//loadAds(keyword);
	}
	else
	{
		loadPage (keyword);
	}
}
//This function loads the RSS content and the ads for the particular keyword and is called on body_loading
function loadAllBody(keyword)
{
	//checkPopup();
	content_init();
	loadRSSContent(keyword);
	//loadAds(keyword);
}

function stateChanged() 
{ 
	if ((rss_xmlHttp!=null) && (rss_xmlHttp.readyState==4 || rss_xmlHttp.readyState=="complete"))
	{ 
		document.getElementById("content_row_article").innerHTML=rss_xmlHttp.responseText; 
	} 

	for (k=0; k< SIZE;k++)
	{
		if ((ad_xmlHttp[k]!=null) && (ad_xmlHttp[k].readyState==4 || ad_xmlHttp[k].readyState=="complete"))
		{ 
			document.getElementById(ad_position[k]).innerHTML=ad_xmlHttp[k].responseText; 
		} 
	}

} 
/*
function pageWidth() 
{
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 
function pageHeight() 
{
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 
function posLeft() 
{
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 
function posTop() 
{
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 
function posRight() 
{
	return posLeft()+pageWidth();
} 
function posBottom() 
{
	return posTop()+pageHeight();
}
*/                    
// Opens a link in a new window 
function openArticle (href)
{
	if ( ! popup_blocked)
	{
		var article_win = window.open(href, "article_window", "width=800,height=700,scrollbars=yes,resizable=yes,dependent=yes");
		if ( article_win == null )
			popup_blocked=ture;
		else
			article_win.focus();
	}
	else
	{
		window.open(href,"_self");
	}
}
/*
function checkPopup()
{
	if ( !popup_checked )
	{
		//var newWin = window.open("popup.html","popped", "width=10, height=10, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");
		var newWin = window.open("","", "width=1, height=1, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");

		if (newWin != null){
			popup_blocked=false;
			//alert("popup not blocked");
			newWin.close();
		}
		else
			popup_blocked=true;
		popup_checked=true;
	}
}
*/

