//This is a Safari cache fix
var iframe_base = 'pop_iframe';
var iframe_id = iframe_base;
var _artist = 'Infected Mushroom';

//loading div precache
var snakeLoader = new Image();
snakeLoader.src = 'images/snakeLoading.gif';
var snakeLoaderBlack = new Image();
snakeLoaderBlack.src = 'images/snakeLoadingBlack.gif';


function iframeHolder(_id, _width, _height)
{
	this.id = _id;
	this.width = _width;
	this.height = _height;
}

var iframeData = null;

//get window dimension - code from: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function getWindowSize()
{
  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;
  }

  return Array(myWidth, myHeight);
}

function placeElements()
{
	var windowSize = getWindowSize();
	var height = windowSize[1];
	var width = windowSize[0];

	var boxHeight = 600;		//imagenary box with height, assuming in the middle of the screen
	var boxWidth = 960;
	var playerWidth = 300;
	var headerId = 'header';
	var footerId = 'footer';
	var flashId = 'flashContainer';
	var headerObj = headerObj || document.getElementById(headerId);
	var footerObj = footerObj || document.getElementById(footerId);
	var flashObj = flashObj || document.getElementById(flashId);

	var dy = (height - boxHeight) / 2;		//is the "empty" space between the virtual box
	if (dy < 0)		//it is possible the screen size smaller then boxHeight, if so, align from top
		dy = 0;

	if (!headerObj) {
		var headerHeight = 50;
		var playerObj = document.getElementById('wimpyTarget');
		if(width - boxWidth <= 0)
			playerLeft = boxWidth - playerWidth;
		else
			playerLeft = (width - boxWidth)/2 + boxWidth - playerWidth;

		playerObj.style.left = playerLeft + 'px';
		playerObj.style.top = (dy + 20) + 'px';
		playerObj.style.display = 'block';
		playerObj.style.position = 'absolute';

	}
	else {
		headerObj.style.display = 'block';
		var headerHeight = headerObj.offsetHeight;
		headerObj.style.top = (dy) + 'px';
	}

	if (flashObj) {		//will not terminate for HTML version
		flashObj.style.top = (dy) + 'px';
		flashObj.style.display = 'block';
		//flashObj.style.position = 'absolute';
		//flashObj.style.zIndex = 1;
	}

	if (!footerObj)
		return;

	footerObj.style.top = (dy + boxHeight - 35) + 'px';
	footerObj.style.display = 'block';

	//this code will place iFrame if it's open on window resize
	if (iframeData) {
		var obj = document.getElementById(iframeData.id);
		if (!obj) {
			iframeData = null;
			return;
		}

		var dy = (height - iframeData.height)/2;
		var dx = (width - iframeData.width)/2;
		//extreme cases
		if (dy < 0)
			dy = 0;
		if (dy < headerHeight) {
			dy = headerHeight;
			//footerObj.style.top = (dy + boxHeight + headerHeight) + 'px';
		}
		if (dx < 0)
			dx = 0;
		obj.style.top = dy + 'px';
		obj.style.left = dx + 'px';
	}
}




//getAbsoluteTop base code from:
//quirkmodes.com
function ShowHistory()
{
	console.log("History Dump");
	if (console && iFrame_history) {
		for (i=0; i<iFrame_history.length; i++) {
			console.log("[0]: " + iFrame_history[i][0] + "  [1]:" + iFrame_history[i][1]);
		}
		console.log('needle At: ' + iFrame_needle);
	}
}


function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}

function findPos(obj)
{
    var curleft = curtop = 0;

    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);

        return [curleft,curtop];
    }
}

//History stuff
function addHistoryItem(src)
{
	var obj = parent.document.getElementById(iframe_id);
	if(obj.contentDocument && obj.contentDocument.location.href)
		url = obj.contentDocument.location.href;
	else {
		eval('url = '+iframe_id+'.location.href;');
	}
	parent.iFrameAddHistory(url);
	parent.iFrameEnableHistory();
}


var iFrame_history = new Array();
var iFrame_needle = -1;
var iFrame_length = 0;
var iFrame_enable_history = false;
var nav_used = false;

function iFrameEnableHistory()
{
	iFrame_enable_history = true;
}

function iFrameDisableHistory()
{
	iFrame_enable_history = false;
}

function iFrameHistoryEnabled()
{
	return iFrame_enable_history;
}


function iFrameAddHistory(url)
{
	//CHANGE: Changed behaviour, now working without onload
/*	for (var i=iFrame_needle; i<iFrame_history.length; i++) {
		if (iFrame_history[i] == url)
			return;
	}*/
	if (nav_used == true) {
		nav_used = false;
		return;
	}

	iFrame_history[++iFrame_needle] = new Array();
	iFrame_history[iFrame_needle][0] = url;
	iFrame_length = iFrame_needle + 1;
	var obj = document.getElementById('frame_title');
	if (!obj) {
		iFrame_history[iFrame_needle][1] = '';
	} else {
		iFrame_history[iFrame_needle][1] = obj.innerHTML;
	}

}

function iFrameClearHistory()
{
	iFrame_history = new Array();
	iFrame_needle = -1;
	iFrame_length = 0;
}

function iFrameNavTo(idx)
{
	//pop_iframe.location.href
	if (iFrame_needle + idx < 0 || iFrame_needle + idx >= iFrame_length)
		return false;

	iFrame_needle += idx;


	var obj = document.getElementById(iframe_id);
	if(obj.contentDocument && obj.contentDocument.location.href)
		obj.contentDocument.location.href = iFrame_history[iFrame_needle][0];
	else {
		//eval(iframe_id+'.location.href = ' + iFrame_history[iFrame_needle][0]);
		var frame = document.getElementById(iframe_id);
		//alert(frames);
		frame.src = iFrame_history[iFrame_needle][0];
	}

	//set the title
	var obj = document.getElementById('frame_title');
	if (obj) {
		obj.innerHTML = iFrame_history[iFrame_needle][1];
	}


	nav_used = true;
	return true;
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
		window.onload = func;
	else
	{
		window.onload = function()
		{
			if (oldonload) oldonload();
			func();
		}
	}
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain )
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// this function gets the cookie, if it exists
function Get_Cookie( name )
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function checkEmail(str) {
///// function for validating email address
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){
		    return false
		} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		} else  if (str.indexOf(at,(lat+1))!=-1){
		    return false
		} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		} else  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		} else if (str.indexOf(" ")!=-1){
		     return false
		} else {
 		 	return true
 		}
}

function getFlashMovieObject(movieName)
{
	if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName];
	if (window.document[movieName])
		return window.document[movieName];
	if (navigator.appName.indexOf("Microsoft Internet")==1)
		return document.getElementById(movieName);
}

function checkMultipleEmail(emails, split_char)
{
	emails_array = emails.split(split_char);
	checkStatus = true;
	for (e in emails_array)
	{
		if (trim(emails_array[e]) != "" && !checkEmail(trim(emails_array[e])))
			checkStatus =false;
	}
	return checkStatus;
}


function getHTTPObject()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
 }

 function PostXML(url,params)
{
	xmlHttp = false;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest && !(window.ActiveXObject))
	{
		try {
			xmlHttp = new XMLHttpRequest();
		} catch(e) {
			xmlHttp = false;
		}
		// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject)
	{
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xmlHttp = false;
			}
		}
	}

	if (xmlHttp)
	{
		xmlHttp.open( "POST", url, false );
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		return xmlHttp.responseXML.documentElement;
	}
}

function LoadHTML(url)
{

	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;

	}
	xmlHttp.send(null);
	return xmlHttp.responseText;
}

function LoadXML(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}


/*
function LoadHTML(url)
{
	var htmlHttp = getHTTPObject();
	htmlHttp.open("GET",url, false);
	htmlHttp.onreadystatechange = function()
	{
		   if (htmlHttp.readyState != 4)  { return; }
		   var serverResponse = htmlHttp.responseText;
	};
	htmlHttp.send(null);
	return htmlHttp.responseText;
}
*/

// bulid string with the form values, fobj the form object, valFunc is validate function
function getFormValues(fobj)
{
   var str = "";
   var valueArr = null;
   var val = "";
   var cmd = "";

   for(var i = 0;i < fobj.elements.length;i++)
   {
       switch(fobj.elements[i].type)
       {
      	case "text":
           case "hidden":
           case "textarea":
           	str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
           break;

           case "radio":
           case "checkbox":
               if(fobj.elements[i].checked)
               		str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
           break;

           case "select-one":
                str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
           break;
       }
   }

   str = str.substr(0,(str.length - 1));
   return str;
}

// validate is got the validate function, if false then skip the validation
function submitAjaxForm(f,url)
{
   var str = getFormValues(f);
   xmlReq = postAjaxForm(url ,str);

 }

 function postAjaxForm(url,str)
{
   var doc = null
   if (typeof window.ActiveXObject != 'undefined' )
   {
       doc = new ActiveXObject("Microsoft.XMLHTTP");

   }
   else
   {
       doc = new XMLHttpRequest();
       doc.onload = displayState;
   }

   doc.open( "POST", url, true );
   doc.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   doc.send(str);
   return doc.responseXML.documentElement;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.-, ";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
 }

function trim(strText) {
/// TRIM STRING FUNCTION
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);
    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}

function escapeString(sString)
{
// DETECT WHAT TO PUT STRING IN FOR HTML FORM ( ' OR " ) DEPANDING ON STRING CONTENTS
	if (sString.indexOf("'") == -1)
		valSep = "'";
	else
		valSep = '"';
	return valSep+sString+valSep;
}

function replaceSubstring(inputString, fromString, toString) {
 // GOES THROUGH THE INPUTSTRING AND REPLACES EVERY OCCURRENCE OF FROMSTRING WITH TOSTRING
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
}


function switchElementDisplay(elementID){
// SWITCH SELECTED ELEMENT DISPLAY: NONE/INLINE
	if (document.getElementById(elementID).style.display=="none")
		document.getElementById(elementID).style.display="inline";
	else
		document.getElementById(elementID).style.display="none";
}

function body_removeChild(cName)
{
//REMOVE  INSTANCE OF ELEMENT FROM BODY
	if (document.getElementById("popIframe_"+cName))
	{
		document.body.removeChild(document.getElementById("popIframe_"+cName));
		popUp = "";
	}
	if (underLayer && document.getElementById("under_layer"))
	{
		document.getElementById("under_layer").style.display="none";
		underLayer = false;
	}
}

var popUp = "";
var popUp_curName = "";
function framePopup(fName, fWidth,fHeight, fSrc, fSrcVars)
{
	iframe_id = iframe_base + '_' + Math.random();
	iframeData = new iframeHolder("popIframe_"+fName, fWidth, fHeight);
	if (!fSrcVars)
		fSrcVars = '';
	body_removeChild(popUp_curName);
	// popup_underLayer();

	var windowSize = getWindowSize();
	winH = windowSize[1];
	winW = windowSize[0];

	//topVar = ((winH/2)-(fHeight/2)+document.body.scrollTop);
	topVar = (winH - fHeight) / 2 + document.body.scrollTop;
	leftVar = (winW - fWidth) / 2;

	oFrame = document.createElement("DIV");
	oFrame.setAttribute("id","popIframe_"+fName);
	oFrame.setAttribute("name","popIframe_"+fName);
	oFrame.setAttribute("class","popDiv");
	document.body.appendChild(oFrame);
	//Not needed for firefox
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		oFrame.style.width = fWidth;
		oFrame.style.height = fHeight;
		oFrame.style.padding = "2px";
	}
	oFrame.style.position="absolute";

	oFrame.style.backgroundColor=(fName == "m_info_press" || fName == "m_media_video" || fName == "m_media_pictures" || fName == "m_media_art") ?  "black" : "white";

	//oFrame.style.backgroundPosition = "50% 50%";
	//oFrame.style.backgroundRepeat = "no-repeat";
	//oFrame.style.backgroundimage = (fName == "m_media_video" || fName == "m_media_pictures" || fName == "m_media_art") ? "url(images/ajax-loader-white.gif)" : "url(images/ajax-loader-black.gif)";
	var bgImage = (fName == "m_info_press" || fName == "m_media_video" || fName == "m_media_pictures" || fName == "m_media_art") ? "images/ajax-loader-white.gif" : "images/ajax-loader-black.gif";
	oFrame.style.border="1px solid #CCCCCC";
	oFrame.style.top= topVar + "px";
	oFrame.style.left= leftVar + "px";
	oFrame.style.zIndex = 100;



	var url = "ajax_functions.php?action=popupInfo&menu_id="+fName;
	var xml = LoadXML(url);
	if(xml != null)
	{
		if (xml.getElementsByTagName('fParent')[0] && xml.getElementsByTagName('fParent')[0].firstChild && xml.getElementsByTagName('fParent')[0].firstChild.data)
		{
			fParent = xml.getElementsByTagName('fParent')[0].firstChild.data;
		}
		else
		{
			fParent = "m_info";
		}
		if (xml.getElementsByTagName('fTitle')[0] && xml.getElementsByTagName('fTitle')[0].firstChild && xml.getElementsByTagName('fTitle')[0].firstChild.data)
		{
			fTitle = xml.getElementsByTagName('fTitle')[0].firstChild.data;
		}
		else
		{
			fTitle = "";
		}
	}

	oFrameHTML = "	<div id=\"pop_header\" style=\"background-image:url("+img_pop_header+");\">"+
								"<h1 id=\"frame_title\">"+fTitle+"</h1>"+
								"<a href=\"javascript:void(0);\" onClick='iFrameClearHistory();parent.body_removeChild(\""+fName+"\");' style=\"background-image:url("+img_pop_close+");margin-"+_align_mir+":5px;\" title='"+_close+"'></a>"+
								"<a href=\"javascript:void(0);\" onClick=\"frame_nav('"+iframe_id+"', 'forward');\" style=\"background-image:url("+img_pop_next+");\" title='"+_next+"'></a>"+
								"<a href=\"javascript:void(0);\" onClick=\"frame_nav('"+iframe_id+"', 'back');\" style=\"background-image:url("+img_pop_back+");\" title='"+_back+"'></a>";

	if (fName == "m_comm_forum" || fName == "m_shop_merch" || fName == "m_shop_tickets" || fName == "m_shop_music" || fName == "m_shop_ringtones")
	{
		oFrameHTML += "<a href=\""+fSrc+"\" target=\"_blank\" style=\"background-image:url("+img_pop_fs+");\" title='"+_fs+"'></a>";
	}
	oFrameHTML +=	"</div>"+
							"<div id=\"iframeLoading\" style='background-repeat: no-repeat;background-position: 50% 50%; background-image:url(" + bgImage + ");'></div>"+
							"<iframe onload=\"javascript:iframeOnLoad(this);\" class=\"pop_iframe\" id='"+iframe_id+"' name='"+iframe_id+"' src='"+fSrc+"' frameborder=\"0\" vspace=\"0\" hspace=\"0\" marginheight=\"0\" marginwidth=\"0\" scrolling=\"yes\"></iframe>"+
							"<div id=\"pop_footer\" style=\"background-image:url("+img_pop_footer+");\"></div>";

	oFrame.innerHTML = oFrameHTML;
	popUp = "popIframe_"+fName;
	popUp_curName = fName;
	placeElements();
}

function setScrollbarAt(wdw, id)
{
	if (!wdw || !id)
		return;

	obj = wdw.document.getElementById(id);
	if (!obj)
		return;

	//set the scrollbar on event window
	if (document.getElementById('popIframe_m_info_events')) {
		var objCoords = findPos(obj);
		wdw.document.body.scrollTop = objCoords[1];
		if (wdw.document.documentElement.scrollTop != 'undefined')
			wdw.document.documentElement.scrollTop = objCoords[1];
	}

}

function iframeOnLoad(obj)
{
	parent.iFrameEnableHistory();
	//set the event for unloading the page
	//parent.window.frames[0].window.onbeforeunload = iframeOnUnload;

	var loadingDiv = document.getElementById('iframeLoading');
	if (loadingDiv) {
		loadingDiv.style.display = 'none';
		loadingDiv.parentNode.removeChild(loadingDiv);
	}
	obj.style.display = 'block';

	setScrollbarAt(obj.contentWindow, 'first_event');

}

function iframeOnUnload()
{
	var iframeObj = parent.document.getElementById(iframe_id);
	if (iframeObj)
		iframeObj.style.display = 'none';
	var loadObj = parent.document.getElementById('iframeLoading');
	if (loadObj)
		loadObj.style.display = 'block';
}

function open_frame (menu_id, target_page)
{
	//iFrameClearHistory();
	framePopup(menu_id, 945, 480, target_page);
}



function frame_nav (fName, navTo)
{
	if (!iFrameHistoryEnabled())
		return;
	iFrame = document.getElementById(fName);
	if (navTo == 'back') {		//check whether it's in the same domain or not
		if(!iFrameNavTo(-1)) {
			iFrameDisableHistory();
			//remove the iframe
			var childN = iFrame.parentNode;
			if (!childN)
				return;
			var parentN = childN.parentNode;
			if (!parentN)
				return;
			parentN.removeChild(childN);
			//clear history
			iFrameClearHistory();
		}
		return;
	}
	iFrameNavTo(1);

	//eval (fName+".history."+navTo+"();");
}

var underLayer = false;

function popup_underLayer()
{
	oLayer = document.getElementById("under_layer");
	oLayer.setAttribute("class", "page_under_layer");

	oLayer.style.display="block";

	underLayer = true;
	move_popup();
}

function move_popup()
{
	if (underLayer && document.getElementById("under_layer"))
	{
		document.getElementById("under_layer").style.top = 0+document.body.scrollTop;
	}
	if (popUp != "" && document.getElementById(popUp))
	{
		winH = 0;
		if (parseInt(navigator.appVersion)>3)
		{
			if (navigator.appName=="Netscape") winH = window.innerHeight;
			else if (navigator.appName.indexOf("Microsoft")!=-1) winH = document.body.offsetHeight;
		}
		topVar = (winH/2)-(document.getElementById(popUp).offsetHeight/2)+document.body.scrollTop;
		document.getElementById(popUp).style.top = topVar;
	}
}

function popupWin(popUrl, width, height)
{
	if (!navigator.appName.indexOf("Microsoft")) width+=20;
	height+=5;
	topVar=((screen.height / 2)-(height/2));
	leftVar=((screen.width / 2)-(width/2));

	window.open(popUrl, "PopUp", "height="+height+", width="+width+", top="+topVar+", left="+leftVar+", scrollbars=yes, status=no, location=no, resize=yes, menubar=no, titlebar=no, toolbar=no");
}

function printIframe(iframeID)
{
	window.opener.document.frames(iframeID).print();
}

function LightboxDelegate(url,caption) {
	if (parent.document)
	{
	  var objLink = parent.document.createElement('a');
	}
	else
	{
	   var objLink = document.createElement('a');
	}
   objLink.setAttribute('href',url);
   objLink.setAttribute('rel','lightbox');
   objLink.setAttribute('title',caption);
   Lightbox.prototype.start(objLink);
   return false;
}

function ie6_fixFlags()
{
	flags = document.getElementsByTagName("IMG");
	for (a in flags)
	{
		if (flags[a].className == "event_flag" && flags[a].parentNode.parentNode.parentNode.className != "past")
		{
			flag_src = flags[a].src;
			flags[a].className = "event_flag_hide";
			if (flags[a].parentNode)
			{
				flags[a].parentNode.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='"+flag_src+"')";
			}
		}
	}
}

function open_tbForm(f_link)
{
	tbf = document.getElementById("tb_form");
	if (tbf.style.display == "none")
	{
		tbf.style.display = "block";
		f_link.innerHTML = _close;
		f_link.className = "minus";
		//window.location.hash="tb_form_top";		//removed for new display method
	}
	else
	{
		tbf.style.display = "none";
		f_link.innerHTML = _add_tb;
		f_link.className = "plus";
	}
}

function reloadCaptcha(cScheme)
{
	var captcha = document.getElementById("captcha_image");
	captcha.innerHTML = "<img src=\"CaptchaSecurityImages.php?cScheme="+cScheme+"&width=70&height=25&characters=5\" align=\"absmiddle\">";
}

function submit_tb(f)
{
	tb_sub = document.getElementById("tb_submit");
	tb_sub.disabled = true;

	if (trim(f.tb_name.value) == "")
	{
		alert (_tb_name);
		f.tb_name.focus();
		tb_sub.disabled = false;
		return false;
	}
	if (trim(f.tb_email.value) != "" && !checkEmail(f.tb_email.value))
	{
		alert (_tb_email_invalid);
		f.tb_email.focus();
		tb_sub.disabled = false;
		return false;
	}
	if (trim(f.tb_body.value) == "")
	{
		alert (_tb_body);
		f.tb_body.focus();
		tb_sub.disabled = false;
		return false;
	}
	if (trim(f.security_code.value) == "")
	{
		alert (_tb_security);
		f.security_code.focus();
		tb_sub.disabled = false;
		return false;
	}

	var url = "ajax_functions.php?action=get_session&session_name=security_code";
	var xml = LoadXML(url);
	if(xml != null)
	{
		if (xml.getElementsByTagName('session_var')[0] && xml.getElementsByTagName('session_var')[0].firstChild && xml.getElementsByTagName('session_var')[0].firstChild.data)
		{
			security_code = xml.getElementsByTagName('session_var')[0].firstChild.data;
		}
		else
		{
			security_code = "";
		}
	}
	if (f.security_code.value != security_code)
	{
		alert (_tb_security_mismatch);
		f.security_code.focus();
		tb_sub.disabled = false;
		return false;
	}
	if (confirm (_tb_confirm))
	{
		params = "action=tb_submit";
		for (a=0; a < f.length; a++)
		{
			params +="&"+ f[a].name+"="+f[a].value;
		}
		var url = "ajax_functions.php";
		xml = PostXML(url,params)
		if(xml != null)
		{
			submit_stat = xml.getElementsByTagName('rsp_stat')[0].firstChild.data;
			submit_message = xml.getElementsByTagName('rsp')[0].firstChild.data;
			alert (submit_message);
			if (submit_stat == "Y")
			{
				f.reset();
				tb_add_link = document.getElementById("open_tb_link");
				open_tbForm(tb_add_link);
				tb_id =  xml.getElementsByTagName('tb_id')[0].firstChild.data;
				tb_doc_id = f.tb_docID.value;
				get_tb(tb_doc_id, tb_id);
			}
		}
	}
	tb_sub.disabled = false;
	return false;
}

function get_tb(event_id, tb_id)
{
	tb_list_obj = document.getElementById("tb_list");
	list_class = "tb_list_0";
	for (i=0; i<tb_list_obj.childNodes.length; i++)
	{
		if (tb_list_obj.childNodes[i].nodeType === 1)
		{
			list_class = (tb_list_obj.childNodes[i].className == "tb_list_0") ? "tb_list_1" : "tb_list_0";
			break;
		}
	}
	var url = "ajax_functions.php?action=tb_get&event_id="+event_id+"&tb_id="+tb_id+"&list_class="+list_class;
	var htmlResponse = LoadHTML(url);
	if(htmlResponse != null)
	{
		cHtml = tb_list_obj.innerHTML;
		 tb_list_obj.innerHTML = htmlResponse+cHtml;
	}
	tb_count_text = document.getElementById("tb_count");
	newCount = parseFloat(tb_count_text.innerHTML)+1;
	tb_count_text.innerHTML = newCount;

}


function beginFlashSite()
{
	Set_Cookie('site_version','flash','30');
	location.href = "main.php";
}


function openLightBox(url, ttl)
{
	//parent.Lightbox.prototype.newImageList();
	var objLink = parent.document.createElement('a');
	objLink.setAttribute('href', url);
	objLink.setAttribute('rel', 'lightbox');
	objLink.setAttribute('title', ttl);
	parent.Lightbox.prototype.start(objLink);

	return false;		//don't open the url
}



youtube_id = 'youtube_player';
var plyr_bg_color = 'white';
//will return false anyway...
function openYouTubePlayer(vId, bgcolor)
{
	var pop_frame = document.getElementById('pop_body');
	if (!pop_frame)
		return false;

	pop_frame.style.display = "none";

	var html = '';
	html =  '<object type="application/x-shockwave-flash" style="width: 425px; height: 350px; background-color: black;" data="http://www.youtube.com/v/' + vId + '&rel=0">';
	html += '<param name="movie" value="http://www.youtube.com/v/' + vId + '&rel=0" />';
	html += '</object>';

	var obj = document.createElement('div');

	obj.id = youtube_id;
	obj.className = 'pop_body_class';
	obj.innerHTML = '<div class="news_title"><span class="picnav_arrow"></span><a class="picnav_href"href="javascript:void(0);" onclick="javascript:closeYouTubePlayer();">'+_back_page+'</a></div>';
	obj.innerHTML += '<div class="video_thumbs_wrapper">&nbsp;</div>';
	obj.innerHTML += '<div class="video_area">' + html + '</div>';




	var elm = document.getElementsByTagName('body');
	var body = elm[0];

	body.appendChild(obj);
	plyr_bg_color = bgcolor;

	body.style.backgroundColor = 'black';
	return false;
}



function closeYouTubePlayer()
{
	var pop_frame = document.getElementById('pop_body');
	if (!pop_frame)
		return false;

	var plyr = document.getElementById(youtube_id);
	if (!plyr)
		return;

	var elm = document.getElementsByTagName('body');
	var body = elm[0];
	body.removeChild(plyr);

	body.style.backgroundColor = plyr_bg_color;
	pop_frame.style.display = "block";
}

function createRequest()
{
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	return xmlHttp;
}

function doneTrans()
{
	if (!globalTransDiv)
		return;
	globalTransDiv.setAttribute('style', 'float: left; width: 100%;');
	globalTransDiv.setAttribute('className', 'docAlign');
	globalTransDiv = null;
}

var globalTransDiv = null;
var lastTrCreated = null;
function OpenEventDiv(obj, id)
{
	if (!obj || !id || globalTransDiv)		//allow one transition at a time
		return;
	//is it already open?
	if (obj.nextSibling && obj.nextSibling.childNodes.length == 1) {
		var parentObj = obj.parentNode;
		parentObj.removeChild(obj.nextSibling);
		//obj.parentNode.removeChild(obj.nextSibling.childNodes[0]);
		lastTrCreated = null;

		return;
	}

	if (lastTrCreated) {
		var parObj = lastTrCreated.parentNode;
		parObj.removeChild(lastTrCreated);
		lastTrCreated = null;
	}

	var parentObj = obj.parentNode;
	var trObj = document.createElement("tr");
	lastTrCreated = trObj;
	trObj.className = "expanded";
	var tdObj = document.createElement("td");
	tdObj.setAttribute('colSpan', '5');

	tdObj.innerHTML = '<div class="loaderTop"></div><div class="loaderBottom"><div class="snakeLoading"></div></div>';

	trObj.appendChild(tdObj);
	parentObj.insertBefore(trObj, obj.nextSibling);

	var transDiv = document.createElement("div");
	var dataDiv = document.createElement("div");
	globalTransDiv = transDiv;

	transDiv.setAttribute('style', 'float: left; width: 100%;overflow: hidden; height: 50px;');
	transDiv.setAttribute('className', 'docAlignOverflow');
	dataDiv.setAttribute('style', 'float: left; width: 100%;');
	dataDiv.setAttribute('className', 'docAlign');


	//set scrollbar
	var objCoords = findPos(obj);

	document.body.scrollTop = objCoords[1];
	if (document.documentElement.scrollTop != 'undefined')
		document.documentElement.scrollTop = objCoords[1];

	var req;
	req = createRequest();
	req.onreadystatechange=function()
	{
		if(req.readyState==4) {
			tdObj.innerHTML = '';		//clear the loading
			dataDiv.innerHTML = req.responseText;
			transDiv.appendChild(dataDiv);
			tdObj.appendChild(transDiv);

			new Effect.Morph(transDiv, {
			  style: 'background:#fff; width: 100%; height: '+dataDiv.offsetHeight+'px',
			  duration: 0.8,
			  afterFinish: doneTrans
		});

		}
	}


	req.open("GET", 'event_ajax.php?id='+id, true);
	req.send(null);



/*
//	dataDiv.innerHTML = LoadHTML('event_ajax.php?id='+id);
	transDiv.appendChild(dataDiv);
	//tdObj.innerHTML = '';
	tdObj.appendChild(transDiv);


	new Effect.Morph(transDiv, {
	  style: 'background:#fff; width: 100%; height: '+dataDiv.offsetHeight+'px',
	  duration: 0.8,
	  afterFinish: doneTrans
});
*/
}


//----------------------------------------------------------------------
//infected HTML gallery - Liran Oz
//----------------------------------------------------------------------
ImageObj.prototype.img;
ImageObj.prototype.unhide;

function ImageObj(_targetId, _thumbUrl, _fullSizeUrl)
{
	var targetId = _targetId;
	var fullSizeUrl = _fullSizeUrl;
	var thumbUrl = _thumbUrl;
	var loaded = false;
	this.preloaded = false;
	this.img = new Image();

	this.unhide = function() {
		loaded = true;
		//update the div's background, if exist (it is possible a page was switched for example)
		var obj = document.getElementById(targetId);
		if (!obj)
			return;
		obj.setAttribute('style', 'background-image: url(' + thumbUrl + ')');
		//IE
		obj.style.backgroundImage = 'url(' + thumbUrl + ')';
	};

	this.preLoad = function()
	{
		this.img.onload = this.unhide;
		this.img.src = thumbUrl;
		this.preloaded = true;
	}

	this.getThumbUrl = function()
	{
		return thumbUrl;
	}

	this.getFullSizeUrl = function()
	{
		return fullSizeUrl;
	}

	this.isLoaded = function()
	{
		return loaded;
	}

}


function InfectedHtmlGallery(object, target, xmlPath)
{
	var targetDiv = target;
	var objName = object;
	var imagesTitle = '';

	if (!xmlPath)
		return null;
	var imageObj = new Array();
	xmlData = LoadXML(xmlPath);
	var imagesPerPage = 21;
	var imagesPerLine = 7;
	var imageItems = xmlData.getElementsByTagName('photo');
	var totalImages = imageItems.length;

	//create image list
	for (var i=0; i<totalImages; i++)
		imageObj[i] = new ImageObj('tn'+i, imageItems[i].getAttribute('thumburl'), imageItems[i].getAttribute('bigurl'));

	this.drawPage = function (pageNumber) {
		if (pageNumber > Math.ceil(totalImages/imagesPerPage))
			pageNumber = 0;

		var from = pageNumber * imagesPerPage;
		var to = from + imagesPerPage;
		if (to > totalImages)
			to = totalImages;

		htmlData = '<div class="htmlGalleryMinHeight">';
		for (var j=0, i=from; i<to; i++) {
			if (!j)
				htmlData += '<div class="gallery_line">';

			htmlData += '<div class="gallery_item">';
			htmlData += '<div class="gallery_preview" id="tn'+i + '" onclick=\'parent.openLightBox("' + imageObj[i].getFullSizeUrl() + '", "' + imagesTitle + '"); return false;\'';
			if (imageObj[i].isLoaded())
				htmlData += 'style="background-image: url(' + imageObj[i].getThumbUrl() + ')">';
			else
				htmlData += 'style="background-image: url(images/snakeLoadingBlack.gif)">';
			//htmlData += '<div class="gallery_mask">';
			//htmlData += '<a class="gallery_mask" href="' + imageObj[i].getFullSizeUrl() + '" onclick=\'parent.openLightBox("' + imageObj[i].getFullSizeUrl() + '", "' + imagesTitle + '"); return false;\'></a>';
			htmlData += '<a class="gallery_mask" href="' + imageObj[i].getFullSizeUrl() + '" nohref></a>';
			//htmlData += '</div>';
			htmlData += '</div></div>';
			j++;
			if (j == imagesPerLine) {
				htmlData += '</div>';
				j = 0;
			}
		}
		if (j)
			htmlData += '</div>';
		//close min height div
		htmlData += '</div>';

		//draw navigation if needed
		if (totalImages > imagesPerPage) {
			htmlData += '<div class="picnav_line">';
			if (pageNumber > 0)
				htmlData += '<a class="black_prev" href="javascript:void(0);" onclick="' + objName + '.drawPage(' + parseInt(pageNumber-1) + ');">Previous</a>'
			if (pageNumber < Math.ceil(totalImages/imagesPerPage)-1)
				htmlData += '<a class="black_next" href="javascript:void(0);" onclick="' + objName + '.drawPage(' + parseInt(pageNumber+1) + ');">Next</a>'
			htmlData += '</div>';
		}

		var obj = document.getElementById(targetDiv);
		if (!obj)
			return;
		obj.innerHTML = htmlData;
		//now preload what wasn't preloaded
		for (i=from; i<to; i++) {
			if (!imageObj[i].isLoaded())
				imageObj[i].preLoad();
		}
	}

	this.setGalleryTitle= function (str)
	{
		imagesTitle = str;
	}

	/*
	next function prepars a modded lightbox image navigation array from within the lightbox, on parent window
	*/
	this.createLightboxNavigation = function()
	{
		parent.lbImageArray = new Array();
		for (var i=0; i<totalImages; i++) {
			parent.lbImageArray[i] = new Array();
			parent.lbImageArray[i]['url'] = imageObj[i].getFullSizeUrl();
			parent.lbImageArray[i]['title'] = imagesTitle;//"Image " + parseInt(i+1);
		}
	}

}


/*--------------------------------
New wimpy player interface layer
Liran Oz - 3.11.2008
---------------------------------*/

function wWimpyLoadXmlPlaylist(xmlTarget, startOnLoad)
{
	var playFlag = startOnLoad || false;
	if (!xmlTarget.match(/^wimpy_playlist\.php/))
		return null;
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",xmlTarget,true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			var xmlData = xmlHttp.responseXML;
			var i=0;
			var fileNames = xmlData.getElementsByTagName('title');
			var fileLocations = xmlData.getElementsByTagName('filename');

			for (i=0; i<fileLocations.length; i++) {
				wimpy_addTrack(playFlag, fileLocations[i].firstChild.nodeValue, 'Infected Mushroom', fileNames[i].firstChild.nodeValue);
				if (playFlag) {
					playFlag = false;
				}
				else if (i == 0)
					wimpy_stop();		//fix pause button bug on wimpy, when loading playlist without autoplay
			}
		}
	};
	xmlHttp.send(null);
}


function changePlayer(pType, pId)
{
	var url = "wimpy_playlist.php?type="+pType+"&id="+pId;
	parent.wimpy_stop();
	parent.wimpy_clearPlaylist();
	parent.wWimpyLoadXmlPlaylist(url, true);
}

/*------------------
YouTube player TB Ajax
-------------------*/

function getBlogTalkbacks(tid)
{
	var req;
	var obj = document.getElementById('blog_tb');
	if (!obj)
		return;
	//Loading animation
	obj.innerHTML = '<div class="ajaxBlackLoader"></div>';

	var action_url = 'blogtb_ajax.php';
	req = createRequest();
	req.onreadystatechange=function()
	{
		if(req.readyState==4) {
		  obj.innerHTML = req.responseText;
		}
	}


	req.open("GET", action_url+"?id="+tid, true);
	req.send(null);
}
