var slideVars = new Array("contImg", "contDownloadLink", "contTitle", "contSize");
var photoVars = new Array("contImg", "contLaunchPopup", "contLaunchPopupLink", "contStoreVisitLink", "contDownloadLink","contRetailer", "contArea","contCountry","contLocation","contDate","contStoreVisit");
var currentRow = 1;
var currentRowContent = 1;
var currentClicked = null;
var placeHolderImage = null;
function loadContent(mode, id, row, justClicked){
	saveCk("View"+mode,id+"|"+row,0.0105) // save the selection to a cookie so we can reload it if the page refreshes
	currentRow = row;
	currentClicked = justClicked.parentNode.parentNode; // TD
//	alert(currentClicked.tagName)
	if (document.getElementById("currentPlaceholder")) {
		document.getElementById("currentPlaceholder").parentNode.childNodes[0].style.display = "block";
		placeHolderImage = document.getElementById("currentPlaceholder");
		placeHolderImage.style.display = "block";
		currentClicked.parentNode.childNodes[0].style.display = "none";
		currentClicked.parentNode.appendChild(placeHolderImage);
	} else{
		currentClicked.parentNode.childNodes[0].style.display = "none";
		placeHolderImage = '<div id="currentPlaceholder"><img src="/analysis/img/empty.gif" width="150" height="113" alt style="background-color:#CCCCCC;" /></div>';
		currentClicked.parentNode.innerHTML += placeHolderImage;
	}
	if (window.contentLoader.window.location.href == "/analysis/includes/preload_"+mode+".asp?id="+id) window.contentLoader.window.location.reload();
	else window.contentLoader.window.location.href = "/analysis/includes/preload_"+mode+".asp?id="+id;
	window.location.href = "#selected"+mode;
}
function reloadCurrent(mode)
{
	var selected = readCk("View"+mode)
	
	if ((selected != null) && (selected.length > 0))
	{
		var ca=selected.split('|')
		var id = ca[0];
		var row = ca[1];
		
		if (document.getElementById(mode+id))
		{
			loadContent(mode, id, row, document.getElementById(mode+id))
		}
	}
}
function loadSlideContent(par){
	for(i=0;i<slideVars.length;i++){
//		alert(document.getElementById(slideVars[i])+" a "+window.contentLoader.window.document.getElementById(slideVars[i]));
		if (document.getElementById(slideVars[i]) && window.contentLoader.window.document.getElementById(slideVars[i])){
			if (i==0){ // if its image URL
				window.document.getElementById(slideVars[i]).src = window.contentLoader.window.document.getElementById(slideVars[i]).innerHTML;
			}else if ((i>0) & (i<=1)){ // if its anchor onclick
				window.document.getElementById(slideVars[i]).href = window.contentLoader.window.document.getElementById(slideVars[i]).innerText;
			}else{ // if its just content
				window.document.getElementById(slideVars[i]).innerHTML = window.contentLoader.window.document.getElementById(slideVars[i]).innerHTML;
			}
		} else{
//			alert("Element with id \""+slideVars[i]+"\" doesn't exist in document.");
		}
	}
//	alert(currentRowContent+" a "+currentRow +" = "+ (currentRowContent!=currentRow));
	if (currentRowContent!=currentRow){
		childLength = document.getElementById("detail"+currentRowContent).childNodes.length;
		document.getElementById("detail"+currentRow).innerHTML = "";
//		alert(document.getElementById("detail"+currentRowContent).innerHTML+" a "+childLength);
		for(a=0;a<childLength;a++){
//			alert("kokot"+" a "+childLength+" a "+a);
			movedChild = document.getElementById("detail"+currentRowContent).childNodes[0];
			if (movedChild)	{
				document.getElementById("detail"+currentRow).appendChild(movedChild);
			}
		}
	}
	currentRowContent = currentRow;
	if (document.getElementById("detail"+currentRow)) document.getElementById("detail"+currentRow).style.display = "block";
}
function loadPhotoContent(par){
	for(i=0;i<photoVars.length;i++){
//		alert(document.getElementById(photoVars[i])+" a "+window.contentLoader.window.document.getElementById(photoVars[i]));
		if (document.getElementById(photoVars[i]) && window.contentLoader.window.document.getElementById(photoVars[i])){
			if (i==0){ // if its image URL
				window.document.getElementById(photoVars[i]).src = window.contentLoader.window.document.getElementById(photoVars[i]).innerHTML;
			}else if ((i>0) && (i<=4)){ // if its anchor onclick
				window.document.getElementById(photoVars[i]).href = window.contentLoader.window.document.getElementById(photoVars[i]).innerText;
			}else if (photoVars[i]=="contStoreVisit"){ // if it the store visit, need to disable or enable
				window.document.getElementById(photoVars[i]).style.display = window.contentLoader.window.document.getElementById(photoVars[i]).innerHTML;
			}else{ // if its just content
				window.document.getElementById(photoVars[i]).innerHTML = window.contentLoader.window.document.getElementById(photoVars[i]).innerHTML;
			}
		} else{
//			alert("Element with id \""+photoVars[i]+"\" doesn't exist in document.");
		}
	}
//	alert(currentRowContent+" a "+currentRow +" = "+ (currentRowContent!=currentRow));
	if (currentRowContent!=currentRow){
		childLength = document.getElementById("detail"+currentRowContent).childNodes.length;
		document.getElementById("detail"+currentRow).innerHTML = "";
//		alert(document.getElementById("detail"+currentRowContent).innerHTML+" a "+childLength);
		for(a=0;a<childLength;a++){
//			alert("kokot"+" a "+childLength+" a "+a);
			movedChild = document.getElementById("detail"+currentRowContent).childNodes[0];
			if (movedChild)	{
				document.getElementById("detail"+currentRow).appendChild(movedChild);
			}
		}
	}
	currentRowContent = currentRow;
	if (document.getElementById("detail"+currentRow)) document.getElementById("detail"+currentRow).style.display = "block";
}
function revert(){
	if (document.getElementById("detail"+currentRow)) document.getElementById("detail"+currentRow).style.display = "none";
	if (document.getElementById("currentPlaceholder")) document.getElementById("currentPlaceholder").parentNode.childNodes[0].style.display = "block";
	if (document.getElementById("currentPlaceholder")) document.getElementById("currentPlaceholder").style.display = "none";
}

function pageSpecificInit(){
	for(i=1;document.getElementById("detail"+i);i++){
		if(document.getElementById("detail"+i).innerHTML!=""){
//			alert(document.getElementById("detail"+i).innerHTML);
			currentRowContent = i;
//			break;
		} else {
			document.getElementById("detail"+i).style.display = "none";
		}
	}
	if (document.getElementById("currentPlaceholder")) {
		document.getElementById("currentPlaceholder").parentNode.childNodes[0].style.display = "none";
		document.getElementById("currentPlaceholder").style.display = "block";
		document.getElementById("currentPlaceholder").style.position = "relative";
		document.getElementById("currentPlaceholder").style.top = "0px";
	}
}

// COOKIE FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////

// n = name of cookies,
// v = value of cookie,
// d = days till it will expire
// leaving this blank will create session cookie
// puting in a negative number will erase the cookie

// saves a value in a cookies
function saveCk(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 readCk(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 '';
}
	
function eraseCk(name)
{
	saveCk(name,"",-1);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////