/******************************************************************/
/******************************************************************/
/***************************GLOBALS********************************/
/******************************************************************/
/******************************************************************/
var globalIndexNum=new Array(4);
var globalLoadingTag="<center><div><img style=\"padding:100px 0px 100px 0px;\" src=\"../images/search/loading.gif\" /></div></center>"
var publisherFileName='searchengine/display_search_results.php';
var slidebarFileName="ajax/searchengine/max_values.php?var1=1";
var navBarFileName='ajax/searchengine/nav_adspace.php';
var searchPHPqueryString = "";
var timeOutId;
var globalSortBy = 0;
var globalDirection = 0;

function disableSelection(target){
	if (typeof target.onselectstart!="undefined") //IE route
		target.onselectstart=function(){return false}
	else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
		target.style.MozUserSelect="none"
	else //All other route (ie: Opera)
		target.onmousedown=function(){return false}
	target.style.cursor = "default"
}

function isOneSelected(checkBoxName) {
	var x=document.getElementsByName(checkBoxName);
	for (var i=0; i < x.length; i++) {
		if (x[i].checked) {
			writeQueryStringTimeDelay(0, 0, 0);
			globalIndexNum[checkBoxName] = i;
			return
		}
	}
	var num = globalIndexNum[checkBoxName];
	x[num].checked=true;
	if (checkBoxName == "bannertype") {
		var divBox = document.getElementById('bannerTypeTdBox' + num);
		divBox.style.border="1px solid #cccccc";
	}
}
	
/******************************************************************/
/******************************************************************/
/***************************SEARCH.PHP*****************************/
/******************************************************************/
/******************************************************************/
function initJavascript() {
	render_slidebar();
	
	var cookiePart = document.cookie.split(';');
	var cookieContent = '';
	var pageRefresh = "0";
	var savedQueryString = "";
	for(var i=0;i < cookiePart.length;i++) {
		cookieContent = cookiePart[i].split('=');
		cookieContent[0] = cookieContent[0].replace(/ /g,'');
		if (cookieContent[0] == "query_string") {
			savedQueryString = cookieContent[1];
			pageRefresh = "1";
			if (!savedQueryString) {
				pageRefresh = "0";
				break;
			}
		}
		else if (cookieContent[0] == "search_type") {
			publisherFileName = cookieContent[1];
			if (!publisherFileName) {
				pageRefresh = "0";
				break;
			}
		}
	}
	if (publisherFileName == 'searchengine/display_search_results.php') {
		turnOnPubTab();
		turnOnAdSizeBoxes();
		turnOffClassification();
	}
	else if (publisherFileName == 'searchengine/display_ad_results.php') {
		turnOnAdTab();
		turnOnAdSizeBoxes();
		turnOffClassification();
	}
	else if (publisherFileName == 'searchengine/display_web_results.php') {
		turnOnWebTab();
		turnOffAdSizeBoxes();
		turnOnClassification();
	}
	if (pageRefresh == "0") {
		initSelectedValues();
	}
	else {
		initSavedValues(savedQueryString);
	}
	var somediv=document.getElementById('navagation_box')
	disableSelection(somediv);
	
	document.getElementById("search_nav").style.display="";
}
function initSelectedValues() {
	resetClassification();
	resetBannerType();
	resetChannelAudience();
	resetChannelGender();
	clearCategories();
	resetparameters('green');
	resetSlideType();
	clearSearchResults();
	init_currentlocation();
	
	writeQueryStringNoLoading(0, 0, 0);
}
function initSavedValues(savedQueryString) {
	var searchParameters = savedQueryString.split('&');
	
	savedChannelGender(searchParameters[1]);
	savedChannelAudience(searchParameters[2]);
	savedSlideType(searchParameters[3]);
	savedBannerType(searchParameters[4]);
	savedFormCategoryOne(searchParameters[5]);
	savedCurrentLocation(searchParameters[6]);
	savedClassification(searchParameters[7]);
	
	/***************finish the ordered way*******************/
	/*
	var page = searchParameters[7].split('##');
	var sortBy = searchParameters[8].split('##');
	var direction = searchParameters[9].split('##');
	
	writeQueryString(page[1], sortBy[1], direction[1]);
	*/
	/**************finish the quick way**********************/
	
	searchPHPqueryString = savedQueryString;
	savedQueryString = savedQueryString.replace(/##/g, "=");
	ajaxFunction(savedQueryString,'search_results',publisherFileName, 2);
	
}

/******************************************************************/
/******************************************************************/
/*********************SEARCH_PARAMETER_FUNCTIONS*******************/
/******************************************************************/
/******************************************************************/

/*************************SEARCHTAB.PHP****************************/
function turnOnPubTab() {
	document.getElementById('searchPub').className="onSearchTab";
	document.getElementById('searchPub').onclick=function(){initSelectedValues();};
	document.getElementById('searchAd').className="offSearchTab";
	document.getElementById('searchAd').onclick=function(){switchSearchAd();};
	document.getElementById('searchWeb').className="offSearchTab";
	document.getElementById('searchWeb').onclick=function(){switchSearchWeb();};
	publisherFileName='searchengine/display_search_results.php';
	slidebarFileName="ajax/searchengine/max_values.php?var1=1";	
	document.getElementById("searchResultContainer").innerHTML=globalLoadingTag;
}
function turnOnAdTab() {
	document.getElementById('searchPub').className="offSearchTab";
	document.getElementById('searchPub').onclick=function(){switchSearchPub();};
	document.getElementById('searchAd').className="onSearchTab";	
	document.getElementById('searchAd').onclick=function(){initSelectedValues();};
	document.getElementById('searchWeb').className="offSearchTab";
	document.getElementById('searchWeb').onclick=function(){switchSearchWeb();};
	publisherFileName='searchengine/display_ad_results.php';
	slidebarFileName="ajax/searchengine/max_values.php?var1=2";
	document.getElementById("searchResultContainer").innerHTML=globalLoadingTag;
}
function turnOnWebTab() {
	document.getElementById('searchPub').className="offSearchTab";
	document.getElementById('searchPub').onclick=function(){switchSearchPub();};
	document.getElementById('searchAd').className="offSearchTab";	
	document.getElementById('searchAd').onclick=function(){switchSearchAd();};
	document.getElementById('searchWeb').className="onSearchTab";
	document.getElementById('searchWeb').onclick=function(){initSelectedValues();};
	publisherFileName='searchengine/display_web_results.php';
	slidebarFileName="ajax/searchengine/max_values.php?var1=3";
	document.getElementById("searchResultContainer").innerHTML=globalLoadingTag;
}
function switchSearchPub() {
	turnOnPubTab();
	turnOnAdSizeBoxes();
	turnOffClassification();
	switchSearch();
	writeQueryStringNoLoading(0, 0, 0);
}
function switchSearchAd() {	
	turnOnAdTab();
	turnOnAdSizeBoxes();
	turnOffClassification();
	switchSearch();
	writeQueryStringNoLoading(0, 0, 0);
}
function switchSearchWeb() {
	turnOnWebTab();
	turnOffAdSizeBoxes();
	turnOnClassification();
	switchSearch();
	writeQueryStringNoLoading(0, 0, 0);	
}
function turnOffAdSizeBoxes() {
	var y=document.getElementById("adSizeBoxes");
	y.style.position="absolute";
	y.style.zIndex="-100";
	y.style.visibility="hidden";
	y.style.left="0px";
	var x=document.getElementsByName("bannertype");
	for (var i=0; i < x.length; i++) {
		x[i].style.visibility="hidden";
	}
}
function turnOnAdSizeBoxes() {
	var y=document.getElementById("adSizeBoxes");
	y.style.position="";
	y.style.zIndex="100";
	y.style.visibility="visible";
	y.style.left="0px";
	var x=document.getElementsByName("bannertype");
	for (var i=0; i < x.length; i++) {
		x[i].style.visibility="visible";
	}		
}
function turnOnClassification() {
	var y=document.getElementById("classificationWrapper");
	y.style.position="";
	y.style.zIndex="100";
	y.style.visibility="visible";
	y.style.left="0px";
	var x=document.getElementsByName("classification");
	for (var i=0; i < x.length; i++) {
		x[i].style.visibility="visible";
	}		
}
function turnOffClassification() {
	var y=document.getElementById("classificationWrapper");
	y.style.position="absolute";
	y.style.zIndex="-100";
	y.style.visibility="hidden";
	y.style.left="0px";
	var x=document.getElementsByName("classification");
	for (var i=0; i < x.length; i++) {
		x[i].style.visibility="hidden";
	}
}

/***********************SEARCH_BANNETYPE.PHP*************************/
function adSizeButtons(num) {
	var x=document.getElementsByName('bannertype');
	var divBox = document.getElementById('bannerTypeTdBox' + num);
	if (x[num].checked==true) {
		x[num].checked=false; 
		divBox.style.border="1px solid #f8f8f8";
	}
	else {
		x[num].checked=true; 
		divBox.style.border="1px solid #cccccc";
	}

	isOneSelected('bannertype');
}

/***********************SEARCH_CATEGORY.PHP**************************/	
function formCategory() {
	var selected_value = document.getElementById("form_category_one").value;
	if (selected_value != 0) {
		var query_string = "&id=" + selected_value;	
		ajaxFunction(query_string,'show_category_select','searchengine/show_category_select.php', 2);
	}
	else {
		resetSelect();
	}
	writeQueryStringUseGlobals(0, 0, 0);
}
function formCategory2() {
	writeQueryStringUseGlobals(0, 0, 0);	
}
function resetSelect() {
	clearCategories();
	writeQueryStringUseGlobals(0, 0, 0);
}
function clearCategories() {
	var x=document.getElementById("form_category_one")
	x.selectedIndex = 0;
	document.getElementById("show_category_select").innerHTML = "";	
}

/***********************SEARCH_LOCATION.PHP*************************/
//location.js
function inclusiveLocationSearch() {
	writeQueryStringUseGlobals(0, 0, 0);
}
function displayLocationUnitedStates() {
	var html;
	
	html =  '<table class="floatLeftFullWidth" cellspacing="0" cellpadding="0" border="0">';
	html += '	<tr>';
	html += '		<td colspan="2" class="valignTop">';
	html += '			<div class="padLeftFive">United States</div>';
	html += '		</td>';
	html += '		<td rowspan="2" class="valignTop">';
	html += '			&nbsp;';
	html += '		</td>';
	html += '	</tr>';
	html += '	<tr>';
	html += '		<td>';
	html += '			<input type="checkbox" checked="checked" name="inclusiveLocation" onclick="inclusiveLocationSearch();">';
	html += '		</td>';
	html += '		<td class="hundredPercent">';
	html += '			<i>(all cities and states within)</i>';
	html += '		</td>';
	html += '	</tr>';
	html += '</table>';

	document.getElementById("currentlocationstate").innerHTML = html;
}
function displayLocationCities(field1, field2) {
	var html;
	
	html =  '<table class="floatLeftFullWidth" cellspacing="0" cellpadding="0" border="0">';
	html += '	<tr>';
	html += '		<td class="valignTop">';
	html += '			<div class="padLeftFive">' + field1 + ', ' + field2 + '</div>';
	html += '		</td>';
	html += '		<td>';
	html += '			<input class="hidefrom" type="checkbox" name="inclusiveLocation"';
	html += '		</td>';
	html += '		<td class="valignTop">';
	html += '			<div class="padRightFive">';
	html += '				<a class="links" href="javascript:clear_currentlocation();">';
	html += '					clear';
	html += '				</a>';
	html += '			</div>';
	html += '		</td>';
	html += '	</tr>';
	html += '</table>';

	document.getElementById("currentlocationstate").innerHTML = html;
}
function displayLocationStates(field1, field2) {
	var html;
	
	html =  '<table class="floatLeftFullWidth" cellspacing="0" cellpadding="0" border="0">';
	html += '	<tr>';
	html += '		<td colspan="2" class="valignTop">';
	html += '			<div class="padLeftFive">' + field1 + ' (' + field2 + ')</div>';
	html += '		</td>';
	html += '		<td rowspan="2" class="valignTop">';
	html += '			<div class="padRightFive">';
	html += '				<a class="links" href="javascript:clear_currentlocation();">';
	html += '					clear';
	html += '				</a>';
	html += '			</div>';
	html += '		</td>';
	html += '	</tr>';
	html += '	<tr>';
	html += '		<td>';
	html += '			<input type="checkbox" checked="checked" name="inclusiveLocation" onclick="inclusiveLocationSearch();">';
	html += '		</td>';
	html += '		<td class="hundredPercent">';
	html += '			<i>(all cities within)</i>';
	html += '		</td>';
	html += '	</tr>';
	html += '</table>';

	document.getElementById("currentlocationstate").innerHTML = html;
}
function init_currentlocation() {
		displayLocationUnitedStates();
		var locationString = "2::0::0::United::States::";
		writeCurrentLocation.location = locationString;
}
function clear_currentlocation() {
		displayLocationUnitedStates();
		var locationString = "2::0::0::United::States::";
		writeCurrentLocation.location = locationString;
		searchLocationFunction(2, '', '');
}
function searchRefreshLocation(code, field1, field2, id1, id2) {
		if (code == 0) {
			displayLocationCities(field1, field2);
		}
		else if (code == 1) {
			displayLocationStates(field1, field2);
		}
		var locationString = code + "::" + id1 + "::" + id2 + "::" + field1 + "::" + field2 + "::";
		writeCurrentLocation.location = locationString;
		searchLocationFunction(code, field1, field2);
}
function searchLocationFunction(code, field1, field2) {
	writeQueryStringUseGlobals(0, 0, 0);
}

/***********************SEARCH_PARAMETERS.PHP*************************/
//slidebar.js
	
/***********************SEARCH_POPULOUS.PHP***************************/
//isOneSelected(checkBoxName)
	
/***********************SEARCH_AVAILABLE.PHP**************************/
//isOneSelected(checkBoxName)
	
/******************************************************************/
/******************************************************************/
/**************************SEARCH_RESULTS**************************/
/******************************************************************/
/******************************************************************/
function writeQueryStringNoLoading(page, sortby, direction) {
	//document.getElementById("searchResultContainer").innerHTML=globalLoadingTag;
	globalSortBy = sortby;
	globalDirection = direction;
	executeQuery(page, sortby, direction);
}
function writeQueryStringTimeDelay(page, sortby, direction) {
	document.getElementById("searchResultContainer").innerHTML=globalLoadingTag;
	clearTimeout(timeOutId);
	timeOutId=setTimeout("executeQuery(" + page + ", " + globalSortBy + ", " + globalDirection + ")",500);
}
function writeQueryString(page, sortby, direction) {
	document.getElementById("searchResultContainer").innerHTML=globalLoadingTag;
	globalSortBy = sortby;
	globalDirection = direction;
	executeQuery(page, sortby, direction);
}
function writeQueryStringUseGlobals(page, sortby, direction) {
	document.getElementById("searchResultContainer").innerHTML=globalLoadingTag;
	executeQuery(page, globalSortBy, globalDirection);
}
function executeQuery(page, sortby, direction) {	
	if (page == 0) {
		page = 1;
	}

	var queryString = writeChannelGender();
	queryString += writeChannelAudience();
	queryString += writeSlideType();
	queryString += writeBannerType();
	queryString += writeFormCategory();
	queryString += writeCurrentLocation();
	queryString += writeClassification();
	queryString += '&page=' + page + '&sortby=' + sortby + '&direction=' + direction;
	
	searchPHPqueryString = queryString.replace(/=/g, "##");
	ajaxFunction(queryString,'search_results',publisherFileName, 1);
}
function SortBy(page, sortby, direction) {
	var dropdownIndex = document.getElementById('sortBySelect').selectedIndex;
	var sortby = document.getElementById('sortBySelect')[dropdownIndex].value;
	writeQueryString(1, sortby, direction);
	
}
function SortByTwo(page, sortby, direction) {
	var dropdownIndex = document.getElementById('sortByHiLow').selectedIndex;
	var direction = document.getElementById('sortByHiLow')[dropdownIndex].value;
	writeQueryString(1, sortby, direction);
}

/******************************************************************/
/******************************************************************/
/**************************LEAVE_PAGE******************************/
/******************************************************************/
/******************************************************************/
function createCookie(name,value,sec) {
	if (sec) {
		var date = new Date();
		date.setTime(date.getTime()+(sec*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/; domain=adollo.com;";
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
window.onbeforeunload = function () {
   createCookie("query_string", searchPHPqueryString, 60*60);
   createCookie("search_type", publisherFileName, 60*60);
}

/******************************************************************/
/******************************************************************/
/***************************HELPING_FUNCTION***********************/
/******************************************************************/
/******************************************************************/
function resetClassification() {	
	var x=document.getElementsByName("classification");
	for (var i=0; i < x.length; i++) {
		x[i].checked = true;
	}	
}
function resetBannerType() {
	var x=document.getElementsByName("bannertype");
	for (var i=0; i < x.length; i++) {
		x[i].checked = true;
		document.getElementById('bannerTypeTdBox' + i).style.border="1px solid #cccccc";
	}	
}
function resetChannelType() {
	var x=document.getElementsByName("channeltype");
	for (var i=0; i < x.length; i++) {
		x[i].checked = true;
	}	
}
function resetChannelAudience() {
	var x=document.getElementsByName("channelaudience");
	for (var i=0; i < x.length; i++) {
		x[i].checked = true;
	}	
}
function resetChannelGender() {
	var x=document.getElementsByName("channelgender");
	for (var i=0; i < x.length; i++) {
		x[i].checked = true;
	}	
}
function resetSlideType() {
	var x=document.getElementsByName("slide_type");
	for (var i=0; i < x.length; i++) {
		if (x[i].value == 1) {
			x[i].checked = true;
		}
		else {
			x[i].checked = false;
		}
	}	
}
function savedChannelGender(subQueryString) {
	var searchType = subQueryString.split('##');
	var x=document.getElementsByName("channelgender");
	for(var i=0;i < searchType[1].length;i++) {
		if (searchType[1].charAt(i) == "1") {
			x[i].checked = true;
		}
		else {
			x[i].checked = false;
		}
	}	
}
function savedChannelAudience(subQueryString) {
	var searchType = subQueryString.split('##');
	var x=document.getElementsByName("channelaudience");
	var reverseIndex = 2;
	for(var i=0;i < searchType[1].length;i++) {
		if (searchType[1].charAt(i) == "1") {
			x[reverseIndex].checked = true;
		}
		else {
			x[reverseIndex].checked = false;
		}
		reverseIndex = reverseIndex - 1;
	}	
}
function savedSlideType(subQueryString) {
	var searchType = subQueryString.split('##');
	var slideBarValue = searchType[1].split('::');
	savedParameters(slideBarValue[0], slideBarValue[3], slideBarValue[4]);
	var x=document.getElementsByName("slide_type");
	for (var i=0; i < x.length; i++) {
		if (slideBarValue[0] == i+1) {
			x[i].checked = true;
		}
		else {
			x[i].checked = false;
		}
	}
}
function savedBannerType(subQueryString) {
	var searchType = subQueryString.split('##');
	var bannerValue = searchType[1].split('::');
	var tempNum = 0;
	var x=document.getElementsByName("bannertype");
	for (var i=0; i < x.length; i++) {
		x[i].checked = false;
		document.getElementById('bannerTypeTdBox' + i).style.border="1px solid #f8f8f8";
		for (var k=0;k < bannerValue.length;k++) {
			tempNum = parseInt(bannerValue[k]);
			if (x[i].value == tempNum) {
				x[i].checked = true;
				document.getElementById('bannerTypeTdBox' + i).style.border="1px solid #cccccc";
				break;
			}
		}
	}
}
function savedFormCategoryOne(subQueryString) {
	var searchType = subQueryString.split('##');
	var categoryValue = searchType[1].split('::');
	var x=document.getElementById("form_category_one");
	//alert(x.options.length);
	for (var i=0; i<=x.options.length; i++) {
		if (x[i].value == categoryValue[0]) {
			x.selectedIndex = i;
			var selected_value = document.getElementById("form_category_one").value;
			if (selected_value != 0) {
				var query_string = "&id=" + selected_value + "&selectedVal=" + categoryValue[1];	
				synchronousDisplayAjax(query_string,'show_category_select','ajax/searchengine/show_category_select.php', 2);
			}
			break;
		}
	}
}
function savedCurrentLocation(subQueryString) {
	var searchType = subQueryString.split('##');
	var locationValue = searchType[1].split('::');
	if (locationValue[0] == 0) {
		displayLocationCities(locationValue[3], locationValue[4]);
	}
	else if (locationValue[0] == 1) {
		displayLocationStates(locationValue[3], locationValue[4]);
	}
	else {
		displayLocationUnitedStates();		
	}

	x=document.getElementsByName("inclusiveLocation");
	if (locationValue[5] == 1) {
		x[0].checked = false;
	}
	clearSearchResults();
	writeCurrentLocation.location = locationValue[0] + "::" + locationValue[1] + "::" + locationValue[2] + "::" + locationValue[3] + "::" + locationValue[4] + "::";
}
function savedClassification(subQueryString) {
	var searchType = subQueryString.split('##');
	var x=document.getElementsByName("classification");
	for(var i=0;i < searchType[1].length;i++) {
		if (searchType[1].charAt(i) == "1") {
			x[i].checked = true;
		}
		else {
			x[i].checked = false;
		}
	}	
}
function writeChannelGender() {
	var sum = '';
	var x=document.getElementsByName("channelgender");
	var queryString = '&channelgender=';
	for (var i=0; i < x.length; i++) {
		if (x[i].checked) {
			sum = sum + '1';
		}
		else {
			sum = sum + '0';
		}
	}
	queryString += sum;
	return queryString;
}
function writeChannelAudience() {
	var sum = '';
	var x=document.getElementsByName("channelaudience");
	var queryString = '&channelaudience=';
	for (var i=x.length-1; i >= 0; i--) {
		if (x[i].checked) {
			sum = sum + '1';
		}
		else {
			sum = sum + '0';
		}
	}	
	queryString += sum;
	return queryString;
}
function writeSlideType() {
	var el = writeSlideType.target;
	var queryString = '&slidetype=';
	var x=document.getElementsByName("slide_type");
	for (var i=0; i < x.length; i++) {
		if (x[i].checked) {
			queryString += x[i].value + "::";
			break;
		}
	}
	queryString += el.leftvalue + "::";
	queryString += el.rightvalue + "::";
	queryString += el.left + "::";
	queryString += el.right;
	return queryString;
}
function writeBannerType() {
	var queryString = '&bannertype=';	
	var x=document.getElementsByName("bannertype");
	for (var i=0; i < x.length; i++) {
		if (x[i].checked) {
			queryString += x[i].value + "::";
		}
	}	
	
	queryString = queryString.substring(0, queryString.length-2); 
	return queryString;
}
function writeFormCategory() {
	var queryString = '&category=';	
	var dropdownIndex = document.getElementById('form_category_one').selectedIndex;
	var dropdownValue = document.getElementById('form_category_one')[dropdownIndex].value;
	queryString += dropdownValue + "::";
	
	if (document.getElementById('form_category_two')) {
		var dropdownIndex = document.getElementById('form_category_two').selectedIndex;	
		var dropdownValue = document.getElementById('form_category_two')[dropdownIndex].value;
		queryString += dropdownValue;
	}
	else {
		queryString += "0";
	}
	
	return queryString;
}
function writeCurrentLocation() {
	var locationString = writeCurrentLocation.location;
	var x=document.getElementsByName("inclusiveLocation");
	if (x[0].checked) {
		locationString += "0";
	}
	else {
		locationString += "1";
	}
	var queryString = '&location=' + locationString;
	return queryString;
}
function writeClassification() {
	var sum = '';
	var x=document.getElementsByName("classification");
	var queryString = '&classification=';
	for (var i=0; i < x.length; i++) {
		if (x[i].checked) {
			sum = sum + '1';
		}
		else {
			sum = sum + '0';
		}
	}	
	queryString += sum;
	return queryString;
}

/******************************************************************/
/******************************************************************/
/***************************GRAPHING_FUNCTION**********************/
/******************************************************************/
/******************************************************************/

function checkS(e){
	var posx = 0;
	var posy = 0;
	if (!e)
		e = window.event;
	if (e.pageX || e.pageY){
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	return [posx, posy];
} 


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();
}

function change_image(image, id) {
	document.getElementById(id).src=image;
}

function show_graph(e, id, table, publisherVal) {
	if (document.getElementById('dynamic_graph') != null) {
		hide_graph(id);
	}
	if (document.getElementById('dynamic_graph') == null) {
		var c = checkS(e);
		var randomnumber=Math.floor(Math.random()*9999999);
		var bottom = posBottom();
		var top = posTop();
		//if (c[1] < top) {ycoord=top+10;}
		if ((c[1]+(351/2)) > bottom) {ycoord=bottom-361;}
		else if ((c[1]-(351/2)) < top) {ycoord=top+10;}
		else {ycoord=(c[1]-(351/2));}
		
		image_url = new Array();
		image_url[1] = "images/search/loading.gif";
		image_url[2] = "images/reports/close.png";
		image_url[3] = "images/reports/close_hover.png";
		
		//656 by 351
		var divTag = document.createElement("div");
		divTag.id = "dynamic_graph";
		divTag.setAttribute("align","center");
		divTag.style.margin = "auto auto auto auto";
		divTag.style.position="absolute"; 
		divTag.style.backgroundColor="white";
		divTag.style.zIndex="999";
		divTag.style.top=ycoord + "px";
		divTag.style.left=(c[0]-696) + "px";
		divTag.style.width="676px";
		divTag.style.height="351px";
		divTag.style.border="1px solid black";
		divTag.className ="dynamic_graph";
		divTag.innerHTML = '<table style="position:relative;" width="676" height="351" cellspacing="0" cellpadding="0" border="0"><tr><td valign="middle" align="center" style="padding-left:30px;"><img id="graph" src="" /></td></tr></table><table cellspacing="0" cellpadding="0" border="0" style="position:absolute;top:0px;right:0px;padding:5px;cursor:pointer;cursor:hand;"><tr><td><img id="graph_close_button" src="" onclick="hide_graph(\'' + id + '\')" onmouseover="change_image(\'' + image_url[3] + '\', \'graph_close_button\')" onmouseout="change_image(\'' + image_url[2] + '\', \'graph_close_button\')"/></td></tr></table>';
		document.body.appendChild(divTag);
		
		document.getElementById("graph").src=image_url[1];
		document.getElementById("graph_close_button").src=image_url[2];
		image_url[0] = "ajax/reports/class_linegraph.php5?rand="+ randomnumber + "&id=" + id + "&table=" + table + "&publisher=" + publisherVal;
		//document.getElementById("graph").src=image_url[0];
		var t=setTimeout("document.getElementById('graph').src=image_url[0]",1000);
	}
}
function hide_graph(id) {
	//var link = document.getElementById('graph_links' + id);
	//link.style.textDecoration="none";
	var divTag = document.getElementById('dynamic_graph');
	document.body.removeChild(divTag);

}
function graph_hover(id) {
	var link = document.getElementById('graph_links' + id);
	link.style.textDecoration="underline";
}
