var IsDevelopmentServer;
var DomainURL;

if (location.href.toLowerCase().indexOf('http://127.0.0.1') != -1) {IsDevelopmentServer = true; DomainURL = 'http://127.0.0.1/vidxnet/www';}
if (location.href.toLowerCase().indexOf('http://dev.vidxnet.com') != -1) {IsDevelopmentServer = false; DomainURL = 'http://dev.vidxnet.com';}
if (location.href.toLowerCase().indexOf('http://www.vidxnet.com') != -1) {IsDevelopmentServer = false; DomainURL = 'http://www.vidxnet.com';}
if (location.href.toLowerCase().indexOf('http://vidxnet.com') != -1) {IsDevelopmentServer = false; DomainURL = 'http://vidxnet.com';}

// global event listeners

if ( (location.href.toLowerCase().indexOf('mail') == -1) && (location.href.toLowerCase().indexOf('register.asp') == -1) && (location.href.toLowerCase().indexOf('uploadmovie.asp') == -1) && (location.href.toLowerCase().indexOf('search') == -1) && (location.href.toLowerCase().indexOf('/tags/') == -1) && (location.href.toLowerCase().indexOf('/categories/') == -1) )
{
	addListener(window, 'load', makeObjectsTransparent);
}

addListener(window, 'load', newWindowLinks);


function makeObjectsTransparent()
{
	
	// change first banner on side menu to wmode=transparent and re-render it so that playlist div will be z-indexed over the flash.
	objectTags = document.getElementById("banner2").getElementsByTagName ("object");

	for (i=0; i<objectTags.length; i++)
	{	

		paramTags = objectTags[i].childNodes;
		paramTags_text = '';

		for (j=0; j<paramTags.length; j++)
		{
			paramTags_text+= paramTags[j].outerHTML;
		}
		if (paramTags_text.toLowerCase().indexOf ('<param name=wmode') == -1)
		{
			paramTags_text += '<param name=wmode value=transparent>';
		}
		objectTags[i].parentElement.innerHTML = '<object width="'+objectTags[i].width+'" height="'+objectTags[i].height+'" id="'+objectTags[i].id+'" classid="'+objectTags[i].classid+'">'+paramTags_text+'</object>';
	}

	// for firefox (no outerHTML)
	embedTags = document.getElementById("banner2").getElementsByTagName ("embed");

	if (embedTags.length > 0)
	{
		embed_text = document.getElementById("banner2").innerHTML;

		if (embed_text.toLowerCase().indexOf ('wmode') == -1)
		{
			embed_text = embed_text.replace ('<embed', '<embed wmode="transparent"');
			document.getElementById("banner2").innerHTML = embed_text;
		}
	}

}



// closes the login box
function popout_Login()
{
    document.body.removeChild (document.getElementById('LoginBox'));
    document.body.removeChild (document.getElementById('LoginBox_BG'));
}

// opens the login box
function popup_Login()
{


	HTML = '<table width="302" height="185" cellspacing="0" cellpadding="0" background="'+VirtualPathFromRoot+'Design/Header/Login_bg.gif">';
		HTML += '<tr>';
			HTML += '<td valign="top" style="padding:10px;">';
				HTML += '<span style="font-size:14px; font-weight:bold; color:#8E0202">Log in</span>';
				HTML += '<br><br>';
				HTML += '<table align="center">';

					HTML += '<tr>';
						HTML += '<td style="font-size:12px; font-weight:bold; color:#6D6D6D">User name</td>';
						HTML += '<td><input type="text" name="login_username" id="login_username" maxlength="20" style="width:150px; border:solid 1px #DDDDDD"></td>';
					HTML += '</tr>';

					HTML += '<tr>';
						HTML += '<td style="font-size:12px; font-weight:bold; color:#6D6D6D">Password</td>';
						HTML += '<td><input type="password" name="login_password" id="login_password" maxlength="20" style="width:150px; border:solid 1px #DDDDDD"></td>';
					HTML += '</tr>';

					HTML += '<tr>';
						HTML += '<td colspan="2" style="height:20px;">';
							HTML += '<span style="color:red" id="login_err">&nbsp;</span>';
						HTML += '</td>';
					HTML += '</tr>';

					HTML += '<tr>';
						HTML += '<td></td><td style="font-size:12px; font-weight:bold; color:#FFFFFF; text-align:right"><img src="'+VirtualPathFromRoot+'Design/Header/arrow_blue.gif" align="absmiddle">&nbsp;<span style="color:#296894">Forgot Account Info?</span><br><br><table cellspacing="0" cellpadding="0"><tr><td><div style="background-image:url('+VirtualPathFromRoot+'Design/Common/b_empty.gif); text-align:center; width:59px; height:22px;"><div style="padding-top:3px"><a href="#a" onclick="VerifyAccount()" style="font-size:12px; font-weight:bold; color:#FFFFFF; text-decoration:none;">Login</a></div></div><td><td><div style="background-image:url('+VirtualPathFromRoot+'Design/Common/b_empty.gif); text-align:center; width:59px; height:22px;"><div style="padding-top:3px;"><a style="font-size:12px; font-weight:bold; color:#FFFFFF; text-decoration:none;" href="#a" onclick="popout_Login()">Close</a></div></div></td></tr></table></td>';
					HTML += '</tr>';

				HTML += '</table>';
			HTML += '</td>';
		HTML += '</tr>';
	HTML += '</table>';



	// calculate inner width and height for background div
	if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") {
		  winW = window.innerWidth-16;
		  winH = window.innerHeight-16;
		 }
		 if (navigator.appName.indexOf("Microsoft")!=-1) {
		  winW = document.body.clientWidth-2;
		  winH = document.body.clientHeight+18;
		 }
		}

		if (winH<570)
		{
			winH = 570;
		}


	 // create semi-transparent background
	 var BGContainer  = document.createElement('div');
	 BGContainer.id = 'LoginBox_BG';
	 BGContainer.style.position = 'absolute';
	 BGContainer.style.top = '1px';
	 BGContainer.style.left = '1px';
	 BGContainer.style.height = _docHeight + 'px';
	 BGContainer.style.width = _docWidth + 'px';     
	 BGContainer.style.backgroundColor = '#F7F7F7';  
	 BGContainer.style.filter =  'alpha(opacity=70)';  
	 BGContainer.style.MozOpacity = '0.7';
	 
	 document.body.appendChild(BGContainer);


	 // create main container box
	 var mainContainer  = document.createElement('div');
	 mainContainer.id = 'LoginBox';
	 mainContainer.style.position = 'fixed';
	 mainContainer.style.zIndex = '100';     
	 mainContainer.style.top = '20px';
	 mainContainer.style.left = (winW / 2) - (302 / 2) + 'px';
	 mainContainer.style.height = '185px';
	 mainContainer.style.width = '302px';     
 
	 document.body.appendChild(mainContainer);


	 document.getElementById('LoginBox').innerHTML = HTML;

}

var _docHeight = 0;
var _docWidth = 0;

addListener(window, 'load', updatePageSize, false);
function updatePageSize()
{
	_docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
	_docWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth;

	_docWidth -= 2;
}



function VerifyAccount()
{
	// Create http request
	var xmlhttp = getTransferObject();
	if(!xmlhttp)
	{
		throw "Download the newer Firefox/IE or upgrade your browser please.";
		return false;
	}
		
	else
	{
		TheUsername = document.getElementById ("login_username").value;
		ThePassword = document.getElementById ("login_password").value;
		File = DomainURL+'/ajax_VerifyAccount.asp';

		Parameters = '?username='+TheUsername+'&password='+ThePassword;
		TheUrl = File + Parameters;
		xmlhttp.open("GET",TheUrl ,true);
		xmlhttp.send(null);

		document.getElementById ("login_err").innerHTML = '<img src="'+VirtualPathFromRoot+'Design/Header/AjaxLoader_Hypnotize.gif" style="height:16px;">';
		xmlhttp.onreadystatechange = function ()
		{
			
			if (xmlhttp.readyState == 4)
			{
				HttpStatus = xmlhttp.status;
				HttpResponseText = xmlhttp.responseText;
				HttpResponseXml = xmlhttp.responseXml;

				if (HttpStatus == 200)
				{
					if (HttpResponseText == '0') {document.getElementById("login_err").innerHTML = '* Account information is incorrect';}
					if (HttpResponseText == '1') {location.reload();}

				}
				else
				{
					errorContent = 'An error has occured while verifying your account.<br>Error information was sent to technical team.<br>Please try again at a later time.';
					alert (errorContent);
					//popup_ErrorMsgBox (errorContent, HttpStatus);
				}
			}
		}
	}
	delete xmlhttp;	
}


function LogOff()
{
	// Create http request
	var xmlhttp = getTransferObject();
	if(!xmlhttp)
	{
		throw "Download the newer Firefox/IE or upgrade your browser please.";
		return false;
	}
		
	else
	{
		File = DomainURL+'/ajax_Logoff.asp';
		Parameters = '';
		TheUrl = File + Parameters;
		xmlhttp.open("GET",TheUrl ,true);
		xmlhttp.send(null);

		xmlhttp.onreadystatechange = function ()
		{
			
			if (xmlhttp.readyState == 4)
			{
				HttpStatus = xmlhttp.status;
				HttpResponseText = xmlhttp.responseText;
				HttpResponseXml = xmlhttp.responseXml;

				if (HttpStatus == 200)
				{
					location.reload();

				}
				else
				{
					errorContent = 'An error has occured while trying to log you off.<br>Error information was sent to technical team.<br>Please try again at a later time.';
					alert (errorContent);
					//popup_ErrorMsgBox (errorContent, HttpStatus);
				}
			}
		}
	}
	delete xmlhttp;	
}


function popup_Playlist(showEffect)
{

	if (PlaylistOpened) {popout_Playlist(); return false;}

	var obj_playlistContainer = document.getElementById("playlist_Container");

	if (!(PlaylistLoaded))
	{
		// Create http request
		var xmlhttp = getTransferObject();
		if(!xmlhttp)
		{
			throw "Download the newer Firefox/IE or upgrade your browser please.";
			return false;
		}
			
		else
		{

			var playlistID;
			var movieID;
			var movieTitle;

			obj_playlistContainer.innerHTML = '<img src="'+VirtualPathFromRoot+'Design/Header/AjaxLoader_Arrows.gif">';

			new Effect.Appear(document.getElementById("playlist_Container"), {duration: 1})
			document.getElementById("btn_playlist").src = VirtualPathFromRoot+'Design/Header/b_Closeplaylist.gif';
			PlaylistOpened = true;

			File = DomainURL+'/ajax_getPlaylist.asp';

			Parameters = '';
			TheUrl = File + Parameters;
			xmlhttp.open("GET",TheUrl ,true);
			xmlhttp.send(null);

			xmlhttp.onreadystatechange = function ()
			{
				
				if (xmlhttp.readyState == 4)
				{
					HttpStatus = xmlhttp.status;
					HttpResponseText = xmlhttp.responseText;
					HttpResponseXml = xmlhttp.responseXml;

					if (HttpStatus == 200)
					{

						xmlDoc = loadXMLfromString(HttpResponseText);
						totalMovies = xmlDoc.getElementsByTagName("movies")[0].childNodes.length;

						obj_playlistContainer.innerHTML = '';


						for (i=0; i<totalMovies; i++)
						{
							nodeType = xmlDoc.getElementsByTagName("movies")[0].childNodes[i].nodeType;

							if (nodeType == 1)
							{

								playlistID = getXMLNodeValue(xmlDoc.getElementsByTagName("movies")[0].childNodes[i].attributes.getNamedItem("playlistID"));
								movieID = getXMLNodeValue(xmlDoc.getElementsByTagName("movies")[0].childNodes[i].attributes.getNamedItem("recordID"));
								movieTitle = getXMLNodeValue(xmlDoc.getElementsByTagName("movies")[0].childNodes[i]);

								Render_CurrentMovie = '<div id="playlistMovie'+i+'" style="margin-bottom:5px;"><table cellspacing="0" cellpadding="0" width="200"><tr><td><a href="'+VirtualPathFromRoot+'movie.asp?movieID='+movieID+'" class="lnk_PlaylistMovie">'+movieTitle+'</a></td><td width="14"><img onclick="removeFromPlaylist('+movieID+');" style="cursor:pointer;" align="absmiddle" title="Remove from playlist" src="'+VirtualPathFromRoot+'Design/Header/Icon_RemoveFromPlaylist.gif"></td></tr></table><div style="height:1px; width:200px; background-color:#6397BE; margin-top:5px;">&nbsp;</div></div>';
								obj_playlistContainer.innerHTML += Render_CurrentMovie;
							}
						}

						PlaylistLoaded = true;
					}
					else
					{
						errorContent = 'An error accessing the playlist has occured.<br>Error information was sent to technical team.<br>Please try again at a later time.';
						alert (errorContent);
						//popup_ErrorMsgBox (errorContent, HttpStatus);
					}
				}
			}
		}
		delete xmlhttp;
	}

	else
	{

		if (showEffect)
		{		
			new Effect.Appear(document.getElementById("playlist_Container"), {duration: 0.5})
		}
		document.getElementById("btn_playlist").src = VirtualPathFromRoot+'Design/Header/b_Closeplaylist.gif';

		PlaylistOpened = true;
	}


}


function popout_Playlist()
{
	var obj_playlistContainer = document.getElementById("playlist_Container");	

	new Effect.Fade(document.getElementById("playlist_Container"), {duration: 1})
	document.getElementById("btn_playlist").src = VirtualPathFromRoot+'Design/Header/b_dropdownplaylist.gif';
	PlaylistOpened = false;
}



function val_HeaderSearch(object)
{

	if (object.SearchKeywords.value == '')
	{object.SearchKeywords.value = 'Please enter keywords...'; return false;}

	if (object.SearchKeywords.value.length < 3)
	{SearchKeywords = object.SearchKeywords.value; object.SearchKeywords.value = 'Enter 3 chars. minimum...'; return false;}

	if (object.SearchContentType[object.SearchContentType.selectedIndex].value == '3')
	{
		document.getElementById ("frm_HeaderSearch").action = VirtualPathFromRoot+'myMail.asp';
	}
	return true;
}

function handle_HeaderSearch(object)
{
	if (object.value == 'Please enter keywords...') {object.value = '';}
	if (object.value == 'Enter 3 chars. minimum...') {object.value = SearchKeywords;}
}

