

var HTTPReq = null;
var iSnowRavenComponent = null;
var strSnowRavenDiv = "";
var strSnowRavenColorChange = "";
var strSnowRavenProperty = "";
var strSnowRavenSampleDiv = "";

function GetXmlHttpObject(handler)
{ 
  var objXMLHttp=null;
  if (window.XMLHttpRequest)
  {
    objXMLHttp=new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  return objXMLHttp;
}



function HideErrorBox()
{
	var dErrorBox = document.getElementById('dErrorBox');
	if (dErrorBox)
		dErrorBox.style.left = -1000 + 'px';
	else
		alert('Oh Crap');
}

function moveMenu(iLeft,iTop,iComponent,iPage,strFGColor,strBGColor,bRoundedCorners,bAutoScale,OtherOptions,bChild)
{

/*
	$strActionMenu .= "<a href=\"" . $PHPSELF . "?move=yes&amp;component=" . $arrayGetModules['componentid'] ."\">Move</a><br />";
	$strActionMenu .= "<a href=\"" . $PHPSELF . "?kill=yes&amp;component=" . $arrayGetModules['componentid'] ."\">Delete Component</a><br />";
	$strActionMenu .= "<a href=\"" . $PHPSELF . "?color=yes&amp;component=" . $arrayGetModules['componentid'] . "\">Border</a><br />";
	$strActionMenu .= "<a href=\"" . $PHPSELF . "?color=bg&amp;component=" . $arrayGetModules['componentid'] . "&amp;detail=" . $arrayGetModules['bgcolor'] . "\">Background</a><br />";
	$strActionMenu .= "<a href=\"" . $PHPSELF . "?color=fg&amp;component=" . $arrayGetModules['componentid'] . "&amp;detail=" . $arrayGetModules['fgcolor'] . "\">ForeGround</a><br />";
*/
	var componentEditBox = document.getElementById('ComponentEditBox');
	if (componentEditBox)
	{
		strMenu = iComponent + " (<a href=\"javascript:hideMenu()\"  >close</a>)<br /><br /><ul>";
		strMenu =  strMenu + "<li><a href=\"javascript:ActivateEditStyle(" + iComponent + "," + iPage + ")\" >Edit Apperance</a></li>";
		
		if (bChild == 0)
		{
		strMenu = strMenu +  
			   "<li><a href=\"index.php?page=" + iPage + "&amp;kill=yes&amp;component=" + iComponent + "\">Delete Component</a></li>";
		}
	
		//strMenu = strMenu + "<li><a href=\"index.php?page=" + iPage + "&amp;color=yes&amp;component=" + iComponent + "\">Border</a></li>" +
		//	  "<li><a href=\"index.php?page=" + iPage + "&amp;color=bg&amp;component=" + iComponent + "&amp;detail=" + strBGColor +  "\">Background</a></li>" +
		//	  "<li><a href=\"index.php?page=" + iPage + "&amp;color=fg&amp;component=" +iComponent + "&amp;detail=" + strFGColor + "\">ForeGround</a></li>"; 

		/*
		if (bRoundedCorners == 1)
		{
			strMenu = strMenu + "<li><a href=\"index.php?page=" + iPage + "&amp;autoscale=no&amp;component=" + iComponent +  "\">Disable Auto Scale</a></li>";
		}
		else
		{
			strMenu = strMenu + "<li><a href=\"index.php?page=" + iPage + "&amp;autoscale=yes&amp;component="  + iComponent + "\">Enable Auto Scale</a></li>";
		}

		if (bAutoScale == 1)
		{
			strMenu = strMenu + "<li><a href=\"index.php?page=" + iPage + "&amp;roundedcorners=0&amp;component=" + iComponent + "\">Disable Rounded Corners</a></li>";
			strMenu = strMenu + "<li><a href=\"index.php?page=" + iPage + "&amp;modifycorners=1&amp;component=" + iComponent + "\">Choose Rounded Corners</a></li>";
		}
		else
		{
			strMenu = strMenu + "<li><a href=\"index.php?page=" + iPage + "&amp;roundedcorners=1&amp;component=" +iComponent + "\">Enable Rounded Corners</a></li>" +
			  "<li><a href=\"index.php?page=" + iPage + "&amp;cmpimg=upload&amp;component=" +iComponent + "\">Background Image</a></li>";
		}
		*/
		strMenu = strMenu + "<li><a href=\"index.php?page=" + iPage + "&amp;displaycomponent=" + iComponent + "\" >Display Component Details</a></li>";

		strMenu = strMenu + OtherOptions;

		strMenu = strMenu + "</ul>";
		componentEditBox.innerHTML = strMenu;

		if (bChild == 0)
		{
			componentEditBox.style.left = iLeft + "px";
			componentEditBox.style.top = iTop + "px";
		}
		else
		{
		}
		
	}
}

function mouseUpMenu(evt)
{
	var componentEditBox = document.getElementById('ComponentEditBox');
	var iLeft = -1000;
	var iTop = -1000;
	var iOffsetX;
	var iOffsetY;

	if (document.all)
	{
	        iOffsetX = document.documentElement.scrollLeft;
        	iOffsetY = document.documentElement.scrollTop;


		iLeft = 10 + iOffsetX;
		iTop = 80 + iOffsetY; 


	}
	else
	{
	        iOffsetX = window.pageXOffset;
        	iOffsetY = window.pageYOffset;

		iLeft = evt.clientX - 100 + iOffsetX;
		iTop = evt.clientY + 10 + iOffsetY;


	}

	if (componentEditBox)
	{
		componentEditBox.style.left = iLeft + 'px';
		componentEditBox.style.top = iTop + 'px';
	}
	document.onmouseup = null;

	
}

function prepUpMenu(bEdit)
{
	if (bEdit == 0)
	{
		document.onmouseup = mouseUpMenu;
		//;alert('BEEEEEEEEEEP');
	}
}

function clearUpMenu(bEdit)
{
	if (bEdit == 0)
	{
		document.onmouseup = null;
	}
}
	
function hideMenu()
{
	var componentEditBox = document.getElementById('ComponentEditBox');
	if (componentEditBox)
	{
		componentEditBox.style.left = "-10000px";
		componentEditBox.style.top = "-10000px";
	}
}

function showhtml(idtag)
{
	htmlbox = document.getElementById(idtag);
	if (htmlbox.style.visibility=='hidden')
	{
		htmlbox.style.width='250px';
		htmlbox.style.height='150px';
		htmlbox.style.visibility='visible';
	}
	else
	{
		htmlbox.style.width='0px';
		htmlbox.style.height='0px';
		htmlbox.style.visibility='hidden';

	}
}

function toggleAltMenu(strAltMenu)
{
	var AltMenu = document.getElementById('AltMenu');
	var SubMenu = document.getElementById(strAltMenu);

	var Items = new Array(2);

	Items[0] = "Navigation";
	Items[1] = "AltBrowse";

	if (AltMenu)
	{

		//is SubMenu visible?  if it is not, then hide all of the children of the AltMenu's list items
		if (SubMenu && SubMenu.style.visibility == 'hidden')
		{
			var i =0;
			for (i = 0; i < Items.length; i++)
			{
				Item = document.getElementById(Items[i]);
				if (Item)
				{
					Item.style.visibility = 'hidden';
					Item.style.width = '0px';
				}
			}
			AltMenu.style.visibility = 'hidden';

		}

		if (AltMenu.style.visibility == 'hidden')
		{
			AltMenu.style.visibility = 'visible';
			//Now Get the right menu and display
			if (SubMenu)
			{
				SubMenu.style.width = '680px';
				SubMenu.style.visibility = 'visible';
			}
			
		}
		else
		{
			AltMenu.style.visibility = 'hidden';
			if (SubMenu)
			{
				SubMenu.style.width = '0px';
				SubMenu.style.visibility = 'hidden';
			}
		}
	}
}


function ExpandPhoto(strImage,iWidth,iHeight,iLeft,iTop)
{
	
	//Time to Hack the Function and get the correct iWidth/iHeight of the image
	var imgImage = new Image();
	imgImage.src = strImage;
	if (imgImage.complete)
	{
		iWidth = imgImage.width;
		iHeight = imgImage.height;
	}


	//photobox.style.left = "1px";
	//photobox.style.top = "1px";

	//Check for Safari as a Browser
	/*
	if(!document.all)
	{
		photobox.className = "TB_overlayMacFFBGHack";//use png overlay so hide flash
	}	
	*/
	//imagebox.style.top = "1px";
	//imagebox.style.left = "1px";
	//imagebox.innerHTML="<a href=\"javascript:HidePhoto()\"><img src=\"" + strImage + "\" style=\"height:" + iHeight + "px;width:" + iWidth +  "px;margin-right:auto;margin-left:auto;display:block;margin-top:" + iTop + "px;\" /></a>";

	var imageBackground = document.getElementById('lightbox');
	var imageImage = document.getElementById('photobookimage');

	
	if (imageBackground)
	{
		var iWindowHeight,iWindowWidth,iOffSetX,iOffSetY;
		if (parseInt(navigator.appVersion)>3) 
		{
			/*
			if (navigator.appName=="Netscape") 
			{
				iWindowWidth = window.innerWidth;
				iWindowHeight = window.innerHeight;
		        	iOffSetX = window.pageXOffset;
        			iOffSetY = window.pageYOffset;

			}*/
				
			if (navigator.appName.indexOf("Microsoft")!=-1 && navigator.appName.indexOf("8") == -1)  //For Microsoft Browsers before IE 8
			{
				iWindowWidth = document.body.offsetWidth;
				iWindowHeight = document.documentElement.clientHeight;
				iOffSetX = document.documentElement.scrollLeft;
        			iOffSetY = document.documentElement.scrollTop;				
			}
			else  //assume that the Browser Does Not Suck - Firefox, Opera, Safari, Chrome.......
			{
				iWindowWidth = window.innerWidth;
				iWindowHeight = window.innerHeight;
		        	iOffSetX = window.pageXOffset;
        			iOffSetY = window.pageYOffset;
			}
		}
		iWindowWidth = iWindowWidth - 3;
		iWindowHeight = iWindowHeight - 3;
		

	
		imageBackground.style.visibility = 'visible';
		imageBackground.style.height='7000px';
	

		//we need to make this thing the size of the client window
	}
	if (imageImage)
	{
		imageImage.style.height = iHeight + 'px';
		imageImage.style.width = iWidth + 'px';
		imageImage.src = strImage;
		imageImage.style.left = (iWindowWidth/2 - (iWidth / 2)) + iOffSetX + 'px';
		imageImage.style.top = (iWindowHeight/2 - (iHeight / 2)) + iOffSetY + 'px';
	}
}

function HidePhoto()
{
	

	var imageBackground = document.getElementById('lightbox');
	var imageImage = document.getElementById('photobookimage');
	
	
	if (imageBackground)
	{
		imageBackground.style.visibility = 'hidden';
		imageBackground.style.height='0px';
	}
	if (imageImage)
	{
		imageImage.style.height = 0 + 'px';
		imageImage.style.width = 0 + 'px';
		imageImage.style.top = -100 + 'px';
		imageImage.style.left = -100 + 'px';
	}

}	

function ShowLogin()
{
	var imageBackground = document.getElementById('lightbox');
	var loginBox = document.getElementById('CoolLogin');
	
	if (loginBox)
	{
		loginBox.style.left = '700px';
		imageBackground.style.visibility = 'visible';
		imageBackground.style.height='7000px';
	
	}

}

function CancelLogin()
{
	var imageBackground = document.getElementById('lightbox');
	var loginBox = document.getElementById('CoolLogin');
	
	if (loginBox)
	{
		loginBox.style.left = '-700px';
		imageBackground.style.visibility = 'hidden';
		imageBackground.style.height='0px';
	}

}
function ShowForgotPanel()
{
	var login = document.getElementById('loginboxpanel');
	var forgot = document.getElementById('forgotpasswordpanel');
	
	if (login && forgot)
	{
		login.style.display = 'none';
		forgot.style.display = 'block';
	}
}

function tb_detectMacXFF() 
{
	var userAgent = navigator.userAgent.toLowerCase();
	if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) 
	{
		return true;
	}
}

function bookmark(site)
{
	switch( site )
	{
		case "stumbleupon": 
			window.open("http://www.stumbleupon.com/submit?url=" + document.location.href + "&title=" + escape(document.title)); 
			return;
		case "digg": 
			window.open("http://digg.com/submit?phase=2&url=" + document.location.href + "&title=" + escape(document.title)); 
			return;
		case "delicious": 
			window.open("http://del.icio.us/post?url=" + document.location.href + "&title=" + escape(document.title)); 
			return;
		case "facebook": 
			window.open("http://www.facebook.com/sharer.php?u=" + document.location.href); 
			return;
		case "reddit": 
			window.open("http://reddit.com/submit?url=" + document.location.href + "&title=" + escape(document.title)); 
			return;
		case "newsvine": 
			window.open("http://www.newsvine.com/_wine/save?u=" + document.location.href); 
			return;	
		case "fark": 
			window.open("http://cgi.fark.com/cgi/fark/farkit.pl?h=" + escape(document.title) + "&u=" + document.location.href); 
			return;
		case "google": 
			window.open("http://www.google.com/bookmarks/mark?op=edit&bkmk=" + document.location.href + "&title=" + escape(document.title)); 
			return;
	}
}

//Project Snow Raven Upgrade

function ActivateEditStyle(iComponent,iPage)
{
	
	var dvEditBox = document.getElementById('EditBoxBottom');
	if (dvEditBox)
	{
		iSnowRavenComponent = iComponent;
		dvEditBox.style.display = 'block';
		ShowEditPane("EditColors",iPage); 
	
		
		hideMenu();
	}
}

//This function shows the specified panel in the edit appearance dialog
function ShowEditPane(strDiv,iPage)
{
	var aEditDivs = ["EditColors","EditShape","EditBGImage"];
	
	var i=0;
	
	for (i=0; i < aEditDivs.length; i++)
	{
		var dvHide = document.getElementById(aEditDivs[i]);
		if (dvHide)
		{
			dvHide.style.display = 'none';
		}
		
	}
	
	if (strDiv == "Close")
	{
		var dvShow = document.getElementById('EditBoxBottom');
		if (dvShow)
		{
			dvShow.style.display = 'none';
		}
	}
	else
	{
		var dvShow = document.getElementById(strDiv);
		if (dvShow)
		{
			
			dvShow.style.display = 'block';
			strSnowRavenDiv = strDiv;
			//call the ajax to show the details of this box
			 HTTPReq = GetXmlHttpObject();
			url= 'SnowRaven/' + strDiv + ".php?sid=" + Math.random() + "&component=" + iSnowRavenComponent + "&page=" + iPage;
			//Set up an event handler once the php page finishes processing
			HTTPReq.onreadystatechange=UpdateEditScreen;
			HTTPReq.open("GET",url,true);
			HTTPReq.send(null);//Process the page
			
		}
	}
	
	
}

function UpdateEditScreen()
{
	if (HTTPReq.readyState==4 && HTTPReq.status == 200)
	{ 
		var dvDiv = document.getElementById(strSnowRavenDiv);
		if (dvDiv)
		{
			dvDiv.innerHTML =  HTTPReq.responseText;
			
		}
	}
}


function ModifyColor(strColorToChange,strSampleDiv)
{
	var aChoices = ['fgcolor','bgcolor','bdcolor'];
	for (var i =0; i < aChoices.length; i++)
	{
		if ($(aChoices[i]) != null)
		{
			$(aChoices[i]).setStyle({'border':" 1px solid #000000"});
		}
	}

	strSnowRavenColorChange = strColorToChange;
	
	strSnowRavenProperty = strColorToChange;
	var dvCommon = document.getElementById('EditBoxColorsCommon');
	var dvAll = document.getElementById('EditBoxColorsAll');
	
	if (dvCommon && dvAll)
	{
		dvCommon.style.display = 'block';
		dvAll.style.display = 'block';
	}
	
	var dvSample = document.getElementById(strSampleDiv);
	if (dvSample)
	{
		$(strSampleDiv).setStyle({'border':" 5px solid #ff0000"});
		strSnowRavenSampleDiv = strSampleDiv;
	}
	
}

//This is the javascript function which changes the on screen values and calls the Ajax functions
function SaveValue(strValue)
{
	
	var bRoundedCorners = false;
	var dvCheck = document.getElementById('Item_Internal_' +iSnowRavenComponent);
	if (dvCheck) //If the internal dialog exists, then this component has rounded corners
	{
		bRoundedCorners = true;
	}
	
	switch(strSnowRavenProperty)
	{
		//Changing the Background Color
		case 'background-color':
		
		if (bRoundedCorners)
		{
			
			if (strValue == "#XXXXXX")
			{
				$('Item_Internal_' +iSnowRavenComponent).setStyle({'backgroundColor':"transparent"});
				$(strSnowRavenSampleDiv).setStyle({'backgroundColor':"transparent"});
				$('b2f_' +iSnowRavenComponent).setStyle({'backgroundColor':"transparent"});
				$('b3f_' +iSnowRavenComponent).setStyle({'backgroundColor':"transparent"});
				$('b4f_' +iSnowRavenComponent).setStyle({'backgroundColor':"transparent"});
				$('b5f_' +iSnowRavenComponent).setStyle({'backgroundColor':"transparent"});
				$('b2fb_' +iSnowRavenComponent).setStyle({'backgroundColor':"transparent"});
				$('b3fb_' +iSnowRavenComponent).setStyle({'backgroundColor':"transparent"});
				$('b4fb_' +iSnowRavenComponent).setStyle({'backgroundColor':"transparent"});
				$('b5fb_' +iSnowRavenComponent).setStyle({'backgroundColor':"transparent"});
			}
			else
			{
				$('Item_Internal_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$(strSnowRavenSampleDiv).setStyle({'backgroundColor':strValue});
				$('b2f_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$('b3f_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$('b4f_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$('b5f_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$('b2fb_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$('b3fb_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$('b4fb_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$('b5fb_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
			}
				
		}
		else
		{
			if (strValue == "#XXXXXX")
			{
				$('Item_' +iSnowRavenComponent).setStyle({'backgroundColor':"transparent"});
				$(strSnowRavenSampleDiv).setStyle({'backgroundColor':"transparent"});
				
			}
			else
			{
				$('Item_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$(strSnowRavenSampleDiv).setStyle({'backgroundColor':strValue});
				
			}
			
			
			
			
		}
		
		strValue = strValue.substring(1,7);
		url= "SnowRaven/SaveAttribute.php?sid=" + Math.random() + "&component=" + iSnowRavenComponent + "&page=" + iPage + "&att=bgcolor&value=" + strValue;
		SaveChange(url);
		break;
		//Foreground Color
		case 'color':
		
			if (bRoundedCorners)
			{
				if (strValue == "#XXXXXX")
				{
					$('Item_Internal_' +iSnowRavenComponent).setStyle({'color':'transparent'});
					$(strSnowRavenSampleDiv).setStyle({'backgroundColor':'transparent'});
				}
				else
				{
					$('Item_Internal_' +iSnowRavenComponent).setStyle({'color':strValue});
					$(strSnowRavenSampleDiv).setStyle({'backgroundColor':strValue});
				}
			}
			else
			{
				if (strValue == "#XXXXXX")
				{
					$('Item_' +iSnowRavenComponent).setStyle({'color':'transparent'});
					$(strSnowRavenSampleDiv).setStyle({'backgroundColor':'transparent'});
				}
				else
				{
					$('Item_' +iSnowRavenComponent).setStyle({'color':strValue});
					$(strSnowRavenSampleDiv).setStyle({'backgroundColor':strValue});
				}				
				
			}
			
			strValue = strValue.substring(1,7);
			url= "SnowRaven/SaveAttribute.php?sid=" + Math.random() + "&component=" + iSnowRavenComponent + "&page=" + iPage + "&att=fgcolor&value=" + strValue;
			SaveChange(url);
			
			
		break;
		case "border-color":
			if (bRoundedCorners)
			{
				$('Item_Internal_' +iSnowRavenComponent).setStyle({'borderColor':strValue});
				$(strSnowRavenSampleDiv).setStyle({'backgroundColor':strValue});
				$('b1f_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$('b2f_' +iSnowRavenComponent).setStyle({'borderColor':strValue});
				$('b3f_' +iSnowRavenComponent).setStyle({'borderColor':strValue});
				$('b4f_' +iSnowRavenComponent).setStyle({'borderColor':strValue});
				$('b5f_' +iSnowRavenComponent).setStyle({'borderColor':strValue});
				$('b1fb_' +iSnowRavenComponent).setStyle({'backgroundColor':strValue});
				$('b2fb_' +iSnowRavenComponent).setStyle({'borderColor':strValue});
				$('b3fb_' +iSnowRavenComponent).setStyle({'borderColor':strValue});
				$('b4fb_' +iSnowRavenComponent).setStyle({'borderColor':strValue});
				$('b5fb_' +iSnowRavenComponent).setStyle({'borderColor':strValue});
			
			
			}
			else
			{
				if (strValue == "#XXXXXX")
				{
					
					$('Item_' +iSnowRavenComponent).setStyle({'borderColor':'transparent'});
					$(strSnowRavenSampleDiv).setStyle({'backgroundColor':'transparent'});
				}
				else
				{
					$('Item_' +iSnowRavenComponent).setStyle({'borderColor':strValue});
					$(strSnowRavenSampleDiv).setStyle({'backgroundColor':strValue});
				}
			}
		
			strValue = strValue.substring(1,7);
			url= "SnowRaven/SaveAttribute.php?sid=" + Math.random() + "&component=" + iSnowRavenComponent + "&page=" + iPage + "&att=bordercolor&value=" + strValue;
			SaveChange(url);
		
		break;
		
		
		default:
			
		break;
	}
}

function SaveChange(url)
{
	HTTPReq = GetXmlHttpObject();
	//Set up an event handler once the php page finishes processing
	HTTPReq.onreadystatechange=ChangesSaved;
	HTTPReq.open("GET",url,true);
	HTTPReq.send(null);//Process the page

}

function ChangesSaved()
{
}

