// JavaScript Document
var buildsendtomehtml;

var pagemode;
var destarray=[];
var desteventarray = [];
var sectionlayouts;
var activeuser;
//Added to make the searchfunction.js file compatible
var currentuser;

var globalscenepath;
var globalinputfield = 'blank';

//MAP GLOBALS
// GLOBAL SWITCHES FOR MAP FUNCTIONALTIY: 0 = Off; 1 = On;
var includemapcontrols = 1;
var includecreatecontrols = 0;
var includecustommarkers = 1;
var includedirections = 1;
var includepano = 1;

// GLOBAL TOGGLES FOR TRAFFIC AND STREETVIEW: 0 = OFF AT PAGELOAD; 1 = ON AT PAGELOAD.
var traffictoggleState = 0;
var panotoggleState = 0;

var defaultmapoff;
var mapdiv;
var	mapcontrolsdiv;
var	mapcreatetoolsdiv;
var	mapdirectionsdiv;
var	mappanodiv;
var	mappanodetailsdiv;
var	highslidepanodiv;

//THE FOLLOWING FUNCTION NEEDS TO BE CALLED FROM THE "PAGE SPECIFIC" JAVASCRIPT FILE TO SET THE GLOBAL DIVS NEEDED FOR THE CORRESPONDING FUNCTIONS.
function setmapglobals(){
	
	mapdiv = document.getElementById("greetingmap");
	defaultmapoff = document.getElementById("HiddenMapOff").value;
	
	var mapsetupflag = loadmap();
	
	if(mapsetupflag == 'success'){
		
		if(includecustommarkers == 1){
			addcustommarkers();
		}
		
		if(includemapcontrols == 1){
			mapcontrolsdiv = document.getElementById("mapcontrols");
			setup_mapcontrols();
		}
		
		if(includecreatecontrols == 1){
			mapcreatetoolsdiv = document.getElementById("createcontrols");
			setup_createcontrols();
		}
		
		if(includedirections == 1){
			mapdirectionsdiv = document.getElementById("directionscontent");
			setup_intdirections();
		}
		
		if(includepano == 1){
			mappanodiv = document.getElementById("pano");
			mappanodetailsdiv = document.getElementById("panodetails");
			highslidepanodiv = document.getElementById("panopanel");
			if(panotoggleState == 1){
				init_streetview();
			}
		}
		
	}
	
}

function winattributes(){
	getbrowser();
	getwinsize();
	//alert(windowheight);
	document.getElementById("dynamback").style.minHeight = windowheight + 'px';
}


function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return yWithScroll;
}


function displayevent(i){
	//alert(eventsarray[i].ename);
	custommessage(desteventarray[i].edescription, desteventarray[i].ename, 900, 650);
}


function checkforparent(){
	
	try{
		if(parent.parenttype){
			if(parent.parenttype=='edit'){
				//alert('This Cthere Page is in EDIT Mode'); 
				pagemode='edit';
				document.getElementById("HiddenEditMode").value = 'true';
				displayeditbars('all');
				var newpageheight = getPageSizeWithScroll();
				setTimeout("parent.sizeiframe("+newpageheight+")",500);
			}
			
			if(parent.parenttype=='display'){
				//alert('This Cthere Page is in Display Mode'); 
				pagemode='display';
				document.getElementById("HiddenEditMode").value = 'false';
			}
		}else{
			//alert('This Cthere Page is running in Standalone Mode');
			pagemode='standalone';
			document.getElementById("HiddenEditMode").value = 'false';
		}
	}catch(err){
		//alert('This is a framed page running from a different server');
		pagemode='standalone';
		document.getElementById("HiddenEditMode").value = 'false';
	}
	
}

function parsedestinfo(destid){
	
	var alldestdetails = document.getElementById("HiddenFieldDestInfo").value;
	var destdetails = alldestdetails.split("|");
	
	//alert(destdetails.length);
	
	if(destdetails.length==22){
		destarray[0] = new popdestination(destid, destdetails[0], destdetails[1], destdetails[2], destdetails[3], destdetails[4], destdetails[5], destdetails[6], destdetails[7], destdetails[8], destdetails[9], destdetails[10], destdetails[11], destdetails[12], destdetails[13], destdetails[14], destdetails[15], destdetails[16], destdetails[17], destdetails[18], destdetails[19], destdetails[20], destdetails[21]);
	}
	
	buildgreetingpage();
	//setloggedinstatus();
	
	if(pagemode=='edit'){
		parent.setdestelements(destarray);	
	}
	
}


function popdestination(destinationid, name, description, address1, address2, city, state, zip, country, phone, fax, email, weblink, datemanual, datecreated, datemodified, username, lat, lng, zoom, maptype, marker, desttype){
	
	this.destinationid=destinationid;
	
	this.name=name;
	this.description=description;
	this.address1=address1;
	this.address2=address2;
	this.city=city;
	this.state=state;
	this.zip=zip;
	this.country=country;
	this.phone=phone;
	this.fax=fax;
	this.email=email;
	this.weblink=weblink;
	
	this.datemanual=datemanual;
	this.datecreated=datecreated;
	this.datemodified=datemodified;
	this.username=username;
	this.lat = lat;
	this.lng = lng;
	this.zoom= zoom;
	this.maptype=maptype;
	this.marker=marker;
	this.desttype=desttype;
	
}

function setthefocus(activeid){
    //alert('Setting globalenter to: '+activeid );
	//multilinetext=true;
	var newfocus = 	document.getElementById(activeid);
	newfocus.focus();
	globalinputfield = activeid;
}

//THE CHECH KEY FUNCTION SORTS OUT ALL KEY PRESSES EXCEPT THE ENTER KEY THEN TRIGGERS THE "processinput()" FUNCTION
//****NOTE: CHECK KEY FUNCTION REQUIRES THE JAVASCRIPT LINE "document.onkeypress = checkKey;" ON THE MASTER PAGE
//****NOTE: CHECK KEY FUNCTION REQUIRES A "processinput()" FUNCTION TO HANDLE THE ENTER KEY.
function checkKey(e)
{
	//alert(browsertype);
	var intKeyCode = 0;
	if (browsertype == "ie"){
		if (window.event.keyCode == 13){
			if(multilinetext==false){
				//alert(window.event.keyCode);
				processinput();
				return false;
			}
		}
	}
	if (browsertype == "netscape"){
		//alert(e.which);
		intKeyCode = e.which;
		if (intKeyCode == 13){
			//alert('Enter key has been pressed');
			if(multilinetext==false){
				processinput();
				return false;
			}
		}
	}
	
}

function settextareareturn(){
	try{
		multilinetext = true;
	}catch(err){
		//NO ACTION
	}
}

function processinput(whichinput){
		
		if(globalinputfield == 'blank'){
			var activeinputfield = whichinput;
		}else{
			var activeinputfield = globalinputfield;	
		}
		
      	switch (activeinputfield){
			case 'password':
				loginButton_Click();
			break;
			
			case 'saddr':
				getdirections('to', globaldirectionpoint);
			break;
			
			case 'daddr':
				getdirections('from', globaldirectionpoint);
			break;
			
			default:
				return false;
			break;
		}
		
		globalinputfield = 'blank';
	  
}


function setloggedinstatus(){
	
	var gcontrolshtml;
	
	if(pagemode != 'edit'){
		
		if(document.getElementById("HiddenFieldloggedonusername").value != ''){
			activeuser = document.getElementById("HiddenFieldloggedonusername").value;
			
	//************ADDED FOR SEACHFUNCTIONS.JS COMPATIBILIY
			currentuser = activeuser;
			gcontrolshtml = 'Welcome '+activeuser+'  |  <a href="javascript:logoutButton_Click()">Log Out</a>';
			
			//WE NEED TO ADD ANOTHER CHECK TO THIS STATEMENT AFTER WE ADD A DEVELOPER FIELD TO THE STOREFRONT.
			var alloweditflag = allowedit(destinationid);
			//alert(alloweditflag);
			if((alloweditflag=='True')&&(pagemode != 'edit')){
				//gcontrolshtml += '  |  <a href="http://www.cplanet.com/destcontrolpanel.aspx?destid='+destarray[0].destinationid+'">Control Panel</a>';
				gcontrolshtml += '  |  <a href="http://www.cplanet.com/cthere.aspx?destid='+destarray[0].destinationid+'&editmode=true"  target="_top">Control Panel</a>';
			}
			
		}else{
			gcontrolshtml = '<a href="javascript:highslidecontrol(\'login\')">Login</a>';
		}
		
		document.getElementById("globalcontrols").innerHTML = gcontrolshtml;
	}
	
	
}


function displayeditbars(state){
		
	switch (state){
			case 'all': 
				document.getElementById("editbanner").style.visibility = 'visible';
				document.getElementById("editbanner").style.height = '15px';
				document.getElementById("editbanner").innerHTML='<a href="javascript:parent.dynamicedit(\'banner\')"><b>EDIT BANNER</b></a>';
				document.getElementById("editgreeting").style.visibility = 'visible';
				document.getElementById("editgreeting").style.height = '15px';
				document.getElementById("editgreeting").innerHTML = '<a href="javascript:parent.dynamicedit(\'greeting\')"><b>EDIT GREETING</b></a>';
			break;
			
			case 'banneronly': 
				document.getElementById("editbanner").style.visibility = 'visible';
				document.getElementById("editbanner").style.height = '15px';
				document.getElementById("editbanner").innerHTML='<a href="javascript:parent.dynamicedit(\'banner\')"><b>EDIT BANNER</b></a>';
				document.getElementById("editgreeting").style.visibility = 'hidden';
				document.getElementById("editgreeting").style.height = '0px';
				document.getElementById("editgreeting").innerHTML = '';
			break;
		}
}

function checkdesttype(){
	
	var commecialtype = false;
	
	var classify = destarray[0].desttype;
	
	switch (classify){
		case "3":
			commecialtype = true;
		break;
		
		case "6":
			commecialtype = true;
		break;
		
	}
	
	return commecialtype;
	
}


function buildgreetingpage(){
		
	//alert('Name: '+destarray[0].name+'\nDescription: '+destarray[0].description+'\nLat: '+destarray[0].lat);
	var commecialtype = checkdesttype();
	
	if(commecialtype == false){
		document.getElementById("ctherebanner").innerHTML = '<img id="ctherebanner2" src="globalgraphics/storefront/ctherebanner.png" alt="Cthere" height="50" />';
	}else{
		document.getElementById("ctherebanner").style.visibility = 'hidden';
		document.getElementById("ctherebanner").style.height = '0px';
	}
	
	var destdetailshtml='<div id="greetingtextholder" class="sfmediaholder" style="width:90%;">';
	var mapbubblehtml='<div id="mapbubblediv" align="left" class="cpfontblack" style="width:225px;">';
	var footerhtml='';
	buildsendtomehtml='';
	
	if(destarray[0].name!=''){
		destdetailshtml += '<span class="cpfontheading18">'+destarray[0].name+'</span>';
		mapbubblehtml += '<span class="cpfontbold">'+destarray[0].name+'</span>';
		buildsendtomehtml += destarray[0].name;
		footerhtml += destarray[0].name;
	}
	
	if(destarray[0].description!=''){
		destdetailshtml += '<br /><span class="cpfontbold">'+destarray[0].description+'</span>';
	}
	
	if(destarray[0].address1!=''){
		destdetailshtml += '<hr />'+destarray[0].address1;
		mapbubblehtml += '<br />'+destarray[0].address1;
		buildsendtomehtml += '\n'+destarray[0].address1;
		footerhtml += ' | '+destarray[0].address1;
	}
	
	if(destarray[0].address2!=''){
		destdetailshtml += '<br />'+destarray[0].address2;
		mapbubblehtml += '<br />'+destarray[0].address2;
		buildsendtomehtml += '\n'+destarray[0].address2;
		footerhtml += ' | '+destarray[0].address2;
	}
	
	if(destarray[0].city!=''){
		destdetailshtml += '<br />'+destarray[0].city+', ';
		mapbubblehtml += '<br />'+destarray[0].city+', ';
		buildsendtomehtml += '\n'+destarray[0].city+', ';
		footerhtml += ' | '+destarray[0].city;
	}
	
	if(destarray[0].state!=''){
		destdetailshtml += destarray[0].state+', ';
		mapbubblehtml += destarray[0].state+', ';
		buildsendtomehtml += destarray[0].state+', ';
		footerhtml += ' | '+destarray[0].state;
	}
	
	if(destarray[0].zip!=''){
		destdetailshtml += destarray[0].zip+', ';
		mapbubblehtml += destarray[0].zip+', ';
		buildsendtomehtml += destarray[0].zip+', ';
		footerhtml += ' | '+destarray[0].zip;
	}
	
	if(destarray[0].country!=''){
		destdetailshtml += destarray[0].country;
		mapbubblehtml += destarray[0].country;
	}
	
	if(destarray[0].phone!=''){
		destdetailshtml += '<br />Phone: '+destarray[0].phone;
		mapbubblehtml += '<br />Phone: '+destarray[0].phone;
		buildsendtomehtml += '\n'+destarray[0].phone;
		footerhtml += ' | '+destarray[0].phone;
	}
	
	if(destarray[0].fax!=''){
		destdetailshtml += '<br />Fax: '+destarray[0].fax;
		mapbubblehtml += '<br />Fax: '+destarray[0].fax;
	}
	
	if(destarray[0].email!=''){
		destdetailshtml += '<br />Contact Email: '+destarray[0].email;
	}
	
	if(destarray[0].weblink!=''){
		destdetailshtml += '<br />Weblink: '+destarray[0].weblink;
		buildsendtomehtml += '\n'+destarray[0].weblink;
	}
	
	destdetailshtml+='</div>';

	buildsendtomehtmlpreview = mapbubblehtml+'</div>';
	mapbubblehtml+='<div align="right"><hr><table width="100%"><tr><td align="left"><div id="panobutton"></div></td><td align="right"><a href="javascript:prepforsend()">Send to me</a></td></tr></table></div></div>';
	
	var dynbannerhtml = destarray[0].name;
	var dyngreetingmedia = '';
	//var dyngreetingmedia = '<img src="globalgraphics/storefront/storefront_sample.jpg" alt="Storefront Sample" border="0" />';	
	
	var dyngreetinghtml = '<table width="100%" border="0"><tr>'
						+'<td align="center" valign="middle">'+destdetailshtml+'</td>'
						+'</tr></table>';
						
	//buildsections(dynbannerhtml, dyngreetinghtml, mapbubblehtml, footerhtml);
	buildauxsections(mapbubblehtml, footerhtml);
	
}

function buildauxsections(mapbubblehtml, footerhtml){
	document.getElementById("sffooter").innerHTML=footerhtml;
	
//	if(sitecontainerflag){
//		alert('injecting 3third party site');
//		document.getElementById('ctsitecontainer').src = containerpage;	
//	}

	plotdestination(mapbubblehtml);
	
	//alert(defaultmapoff);
	if(defaultmapoff == 'True'){
		togglemapdisplay('off');
	}else{
		togglemapdisplay('full');
	}
}


function checkpage(sender, args){
	
	//RESET THE MULTI-LINE TEXT FLAG
	multilinetext = false;
	
	//GET AND PARSE THE PAGE PAGE ARGUMENTS
	var activepagename=args.get_item().get_text();//eventArgs.Item.Text;
	var activepagevalue=args.get_item().get_value();//Args.Item.Value;
	var mapoffsetting;
	var multiplesubs = false;
	
	//alert('Page Name: '+activepagename+'Argument String: '+activepagevalue);
	var checkvaluestring = activepagevalue.search(/\?/);
		
	if(checkvaluestring != -1){
		var valuestring = activepagevalue.split("?");
		if(valuestring.length == 7){
			var activemediatype = valuestring[0];
			var activemediaid = valuestring[1];
			var activepageid = valuestring[2];
			var menuitemtype = valuestring[3];
			var menuordernumber = valuestring[4];
			mapoffsetting = valuestring[5];
			var mediapath = valuestring[6];
						
			//THIS SEARCH AND IF STATEMENT HANDLE A VARIABLE GLITCH IN THE DATABASE.
			try{
				var trimmapflag = mapoffsetting.search("True");
				
				if(trimmapflag != -1){
					mapoffsetting = 'True';
				}
			}catch(err){
				mapoffsetting = 'True';
			}
			
			if(menuitemtype!='main'){
				document.getElementById("sfmediaholder").innerHTML='';
			}
			
			switch (activemediatype){
				case 'Home':
					var reservedpage=true;
					if(defaultmapoff == 'False'){
						mapoffsetting = 'False';
					}else{
						mapoffsetting = 'True';
					}
				break;
				
				case 'Community':
					var reservedpage=true;
					mapoffsetting = 'True';
				break;
				
				case 'Calendar':
					var reservedpage=true;
					displaycalendar();
					mapoffsetting = 'True';
				break;
				
				case 'Spin':
					args.set_cancel(true); 
					displayspin(mediapath, activepageid, activemediaid);
					//displayspin(mediapath);
					mapoffsetting = 'True';
				break;
				
				case '3d':
					args.set_cancel(true); 
					display3d(mediapath);
					mapoffsetting = 'True';
				break;
				
				case 'order':
					//THIS CASE HANDLE THE SITUATION OF A MAIN MENU HEADER WITH MULTIPLE SUB ITEMS. THE CLICK HAS NO MEDIA TO EDIT.
					//alert('setting multiple subs to true.\nPageid = '+activepageid);
					multiplesubs = true;
					mapoffsetting = 'True';
				break;
				
			}
			
			//alert(mapoffsetting);
			if(mapoffsetting == 'True'){
				togglemapdisplay('off');
			}else{
				togglemapdisplay('full');
			}
			
		}else{
			alert('Error in Nav Menu String Arguments.');	
		}	
	}else{
		alert('No argument delimiter found.');	
	}
	
	
	if(pagemode=='edit'){

		parent.setcontrolview('menu');
		var buttonoptions = '';
		
		parent.document.getElementById("HiddenPageID").value = activepageid;
		parent.document.getElementById("HiddenMediaID").value = activemediaid;
		parent.document.getElementById("HiddenMediaType").value = activemediatype;
		//alert('activemediatype: '+activemediatype+'\nPage ID: '+activepageid+'\nMedia ID: '+activemediaid +'\nMenu Item Type:'+menuitemtype);
		
		if(multiplesubs == false){
			
			switch (activemediatype){
				case 'Info': 
					//buttonoptions += '<input type="button" id="editpage" value="Edit This Media" Onclick="dynamicedit(\'Info\')" />';
					buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_editmedia_but.png" alt="Edit this media" style="width:110px; height:110px" border="0" id="editmedia_but" onmouseover="this.style.cursor=\'pointer\'" onclick="dynamicedit(\'Info\')" />';
				break;
				
				case 'Tag': 
					//buttonoptions += '<input type="button" id="editpage" value="Edit This Media" Onclick="dynamicedit(\'Tags\')" />';
					buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_editmedia_but.png" alt="Edit this media" style="width:110px; height:110px" border="0" id="editmedia_but" onmouseover="this.style.cursor=\'pointer\'" onclick="dynamicedit(\'Tags\')" />';
				break;
				
				case 'Gallery': 
					//buttonoptions += '<input type="button" id="editpage" value="Edit This Media" Onclick="dynamicedit(\'Image\')" />';
					buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_editmedia_but.png" alt="Edit this media" style="width:110px; height:110px" border="0" id="editmedia_but" onmouseover="this.style.cursor=\'pointer\'" onclick="dynamicedit(\'Image\')" />';
				break;
				
				case 'Video': 
					//buttonoptions += '<input type="button" id="editpage" value="Edit This Media" Onclick="dynamicedit(\'Video\')" />';
					buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_editmedia_but.png" alt="Edit this media" style="width:110px; height:110px" border="0" id="editmedia_but" onmouseover="this.style.cursor=\'pointer\'" onclick="dynamicedit(\'Video\')" />';
				break;
				
				case 'Spin': 
					//buttonoptions += '<input type="button" id="editpage" value="Edit This Media" Onclick="dynamicedit(\'Spin\')" />';
					buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_editmedia_but.png" alt="Edit this media" style="width:110px; height:110px" border="0" id="editmedia_but" onmouseover="this.style.cursor=\'pointer\'" onclick="dynamicedit(\'Spin\')" />';
				break;
				
				case '3D': 
					//buttonoptions += '<input type="button" id="editpage" value="Edit This Media" Onclick="dynamicedit(\'Spin\')" />';
					buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_editmedia_but.png" alt="Edit this media" style="width:110px; height:110px" border="0" id="editmedia_but" onmouseover="this.style.cursor=\'pointer\'" onclick="dynamicedit(\'3D\')" />';
				break;
			}
//			
//			var directlinkhtml = 'http://www.cplanet.com/destwindow.aspx?destid='+destinationid+'&pageid='+activemediaid+'&mediatype='+activemediatype;
//			buttonoptions +='<a href="javascript:highslide_html(\''+directlinkhtml+'\', \'250\', \'100\', true)" />Generate Direct Link</a>';
			
			if(menuitemtype=='main'){
				if(reservedpage == true){
					buttonoptions += customeditmenu(activemediatype);
				}else{
					buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_addmoremedia_but.png" alt="Add more media to this page header" style="width:110px; height:110px" border="0" id="addmoremedia_but" onmouseover="this.style.cursor=\'pointer\'" onclick="setcontrolview(\'mediatype\')" />';
					
					activemediatype='all';
					buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_deletepage_but.png" alt="Delete this page header" style="width:110px; height:110px" border="0" id="deletepage_but" onmouseover="this.style.cursor=\'pointer\'" onclick="deleteactivepage(\''+activemediatype+'\', \''+activemediaid+'\', \''+activepageid+'\')" />';
				}
			}else{
				buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_deletemedia_but.png" alt="Add more media to this page header" style="width:110px; height:110px" border="0" id="deletemedia_but" onmouseover="this.style.cursor=\'pointer\'" onclick="deleteactivemedia(\''+activemediatype+'\', \''+activemediaid+'\')" />';
			}
			
			if(activemediatype == 'Home'){
				displayeditbars('all');
			}else{
				displayeditbars('banneronly');
			}
			
			
			var newpageheight = getPageSizeWithScroll();
			setTimeout("parent.sizeiframe("+newpageheight+")",500);
			
			
		}else{
			activemediatype = 'blank';
			activemediaid = 'blank';
			//activepageid = activepagevalue;
			activemediatype='all';
			
			if(reservedpage == true){
				customeditmenu(activemediatype);
			}else{
				buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_addmoremedia_but.png" alt="Add more media to this page header" style="width:110px; height:110px" border="0" id="addmoremedia_but" onmouseover="this.style.cursor=\'pointer\'" onclick="setcontrolview(\'mediatype\')" />';
									
				buttonoptions += '<img src="/globalgraphics/catalogbuttons/cp_deletepage_but.png" alt="Delete this page header" style="width:110px; height:110px" border="0" id="deletepage_but" onmouseover="this.style.cursor=\'pointer\'" onclick="deleteactivepage(\''+activemediatype+'\', \''+activemediaid+'\', \''+activepageid+'\')" />';
			}
								
//			var directlinkhtml = 'http://www.cplanet.com/destwindow.aspx?destid='+destinationid+'&pageid='+activemediaid+'&mediatype='+activemediatype;
//			buttonoptions +='<a href="javascript:highslide_html(\''+directlinkhtml+'\', \'250\', \'100\', true)" />Generate Direct Link</a>';
		}
		
		parent.toggleedit('on', activepagename);
		//parent.setcontrolview('editon');
		parent.globalactivepage=activepagename;
		parent.globaloldorder=menuordernumber;
		parent.document.getElementById("editbuttons").innerHTML=buttonoptions;
		parent.document.getElementById("currentpagetitle").innerHTML=activepagename;
		//alert("Page Name: " + eventArgs.Item.Text+"\nPage Value: " + eventArgs.Item.Value);
	}
	
}

function customeditmenu(activepagename){
	
	var editmenuhtml;
	
	switch (activepagename){
		case 'Home': 
		
			if(defaultmapoff == 'False'){
				var mapcheckbox = '<input id="maponcheckbox" name="maponcheckbox" type="checkbox" onchange="setmapstatus(this.id)" />'
			}else{
				var mapcheckbox = '<input id="maponcheckbox" name="maponcheckbox" type="checkbox" checked onchange="setmapstatus(this.id)" />'
			}
			
			editmenuhtml = '<div><table width="100%" border="0" cellpadding="10"><tr>'
						+'<td align="center"><img src="/globalgraphics/catalogbuttons/cp_modgreeting_but.png" alt="Modify the greeting content" style="width:110px; height:110px" border="0" id="modgreeting_but" onmouseover="this.style.cursor=\'pointer\'" onclick="parent.setcontrolview(\'editsection\', \'Greeting\')" /></td>'
						+'<td align="center" valign="top" class="cpfontheading">Hide map on Home page:'+mapcheckbox
						+'<br><img src="/globalgraphics/catalogbuttons/cp_hidemap_sym.png" /><br><span class="minifont">For more map options click on Manage Navigation.</span></td></tr></table>';
		break;
		
		case 'Calendar': 
		
			editmenuhtml = '<table width="100%" border="0" cellspacing="0" cellpadding="5">'
						  +'<tr><td colspan="2" class="cpfontheading" align="center">Add or Edit Dates on your Event Calendar</td></tr>'
						  +'<tr><td><img src="globalgraphics/catalogbuttons/but_addevent.gif" border="0" onclick="hs_editpanels(\'eventeditor\')" /></td>'
						  +'<td>Click the Add Event button to add an event to the selected date.</td></tr>'
						  +'<tr><td><img src="globalgraphics/catalogbuttons/but_editevent.gif" border="0" onclick="hs_editpanels(\'eventeditor\')" /></td></tr>'
						  +'</table>';
		break;
		
		case 'Community': 
		
			editmenuhtml = 'Modify options coming soon.';
		break;
	}
	
	return editmenuhtml;
}
//END OF PAGE LOAD AND CONFIG FUNCTIONS	

function displayspin(spininfo, mpageid, mmediaid){
	
		//var spininfo = document.getElementById("HiddenSpinInfo").value
		
		var spindetails = spininfo.split("||");
		var spin = spindetails[0];
		var spintext = spindetails[1];
		var spindesc = spindetails[2];
	
		//alert(spininfo + " , " + mpageid + " , " + mmediaid);
		
		panostring = '<div align="left" style="padding:10px;"><span style="font-size:18px;"><i><b>'+spintext+'</b></i></span><br /><br />'
					+'<span style="font-size:11px;">'+spindesc+'</span></div>'
					+'<div style="z-index: 1;"><APPLET archive=http://www.cplanet.com/ptviewer.jar  code=ptviewer.class width=800 height=450 name="ptviewer" mayscript=trues>'
					+'<PARAM name=file 			value="'+spin+'">'
					+'<PARAM name=showToolbar 	value="true">'
					+'<PARAM name=auto			value="0.15">'
					+'<PARAM name=fov			value="95">'
					+'<PARAM name=wait			value="globalgraphics/general/wait.jpg">'
					+'</APPLET></div>';
					
					
		if(document.getElementById("HiddenEditMode").value == "True"){
			var musername = document.getElementById("HiddenFieldDestUserName").value
			var mdestid = document.getElementById("HiddenDestinationID").value
			
			var argstring = '?username='+musername;
				argstring += '&destid='+mdestid;
				argstring += '&pageid='+mpageid;
				argstring += '&mediaid='+mmediaid;
				
			var editboxhtml = '<table width="100%" align="center" class="editboxgreen"><tr>';
			editboxhtml += '<td align="center" width="150" bgcolor="#00FF00">Panorama Spin Media</td>';
			editboxhtml += '<td align="right"><img src="http://www.cplanet.com/globalgraphics/general/icon_edit.png" align="right" /></td>';
			editboxhtml += '<td align="left"><a id="mediatypeanchor" href="http://www.cplanet.com/Content_Forms/cpspineditor.aspx' + argstring + '">Edit</a></td>';
			editboxhtml += '<td align="right" style="padding-left:15px;"><img src="http://www.cplanet.com/globalgraphics/general/icon_delete.png"></td>';
			editboxhtml += '<td align="left"><a id="deletemediaanchor" href="javascript:deleteactivemedia()">Delete</a></td>';
			editboxhtml += '</tr></table>';
			
			if(globalheaderitem == 'main'){
				var naveditbox = buildheadereditbox();
				document.getElementById("sfmediaholder").innerHTML = naveditbox + editboxhtml + panostring;
			}else{
				document.getElementById("sfmediaholder").innerHTML = editboxhtml + panostring;
			}
			
		}else{
			document.getElementById("sfmediaholder").innerHTML = panostring;
		}
							
		

//		//spin = "panofiles/CplanetPano.xml";
//		
//		var spinfile = 'controls/spinsxml.aspx?path='+spin;
//		
//		var spinstring = '<div id="spinholder" style="margin-top:40px;"></div>';
//		
//		document.getElementById("sfmediaholder").innerHTML = spinstring;
//
//		so = new SWFObject("panofiles/ModuleLoader.swf?xml="+spinfile, "pano", "600", "400", "9", "#000000"); 	
//		so.addParam("allowFullScreen","true");
//		so.addParam("allowScriptAccess","sameDomain");
//		so.write("spinholder");
	
	
}

function displayspinold(spin){
	
		try{
			var communitypanel = getcommunitypanel();
			communitypanel.style.display = "none";
		}catch(err){
			//alert('Community Panel is Hidden');
		}
		
		panostring = '<div align="center" style="height:60px">Panorama Spin</div>'
					+'<div style="z-index: 1;"><APPLET archive=http://www.cplanet.com/ptviewer.jar  code=ptviewer.class width=800 height=450 name="ptviewer" mayscript=trues>'
					+'<PARAM name=file 			value="'+spin+'">'
					+'<PARAM name=showToolbar 	value="true">'
					+'<PARAM name=auto			value="0.15">'
					+'<PARAM name=fov			value="95">'
					+'<PARAM name=wait			value="globalgraphics/general/wait.jpg">'
					+'</APPLET></div>';
							
		document.getElementById("sfmediaholder").innerHTML=panostring;

//		//spin = "panofiles/CplanetPano.xml";
//		
//		var spinfile = 'controls/spinsxml.aspx?path='+spin;
//		
//		var spinstring = '<div id="spinholder" style="margin-top:40px;"></div>';
//		
//		document.getElementById("sfmediaholder").innerHTML = spinstring;
//
//		so = new SWFObject("panofiles/ModuleLoader.swf?xml="+spinfile, "pano", "600", "400", "9", "#000000"); 	
//		so.addParam("allowFullScreen","true");
//		so.addParam("allowScriptAccess","sameDomain");
//		so.write("spinholder");
	
	
}


function displayhsspin(spin, title){
	
		var newtitle = "Panorama Spin";
		
		if(title){
			newtitle = title;
		}
	
		if(spin){
		
			panostring = '<div align="center"><div style="z-index: 1;"><APPLET archive=http://www.cplanet.com/ptviewer.jar  code=ptviewer.class width=625 height=400 name="ptviewer" mayscript=trues>'
						+'<PARAM name=file 			value="'+spin+'">'
						+'<PARAM name=showToolbar 	value="true">'
						+'<PARAM name=auto			value="0.15">'
						+'<PARAM name=fov			value="95">'
						+'<PARAM name=wait			value="globalgraphics/general/wait.jpg">'
						+'</APPLET></div></div>';
			
			
			displayMessage(panostring, newtitle, '700', '475');
		
		}
					
}

function displaycalendar(){
	
	try{
		var communitypanel = getcommunitypanel();
		communitypanel.style.display = "none";
	}catch(err){
		//alert('Community Panel is Hidden');
	}
	
	var calendarhtml='<div align="center"><iframe src="Calendar.aspx?destid='+destinationid+'" id="calendarframe" width="800" height="700" frameborder="0" allowtransparency="true" name="calendarframe"></iframe></div>';
	
	document.getElementById("sfmediaholder").innerHTML = calendarhtml;
	
}

function display3d(scenefile){
	//alert(scenefile);
	var scenetitle = '3D Scene Title';
	globalscenepath = scenefile;
	//loadscenehtml='<a id="scenelink" href="javascript:highslidepanel(\'3dscene\')">Open 3d Scene</a>';
	loadscenehtml='<div align="center"><div id="launchmessgae" style="width:550px; border:solid thin #0066CC; padding:15px; background-color:#FFFFFF;">'
    			  	+'<table width="100%" border="0">'
      				+'<tr><td colspan="2" align="center"><span style="font-size:18px; color:#0066CC; font-weight:bold;">'
					+'Clicking the image below will launch a three dimensional, interactive simulation.</span><br />'
					+'To experience the 3D effects you must have the <b>Viewpoint Media Player Plugin</b> installed on your computer. '
					+'If you do not, you will be prompted to do so.<br /><br />'
					+'<span style="font-size:20px">Enjoy the Cplanet 3D Experience</span>.</td></tr>'
      				+'<tr><td colspan="2" align="center">'
					+'<div id="scenetitle"><a id="scenelink" href="javascript:highslidecontrol(\'3dscene\')">'
					+'<img src="/globalgraphics/instructions/launch3dimage.gif" alt="Launch 3D Scene" /><br />'+scenetitle+'</a></div><hr/></td></tr>'
      				+'<tr><td align="center"><img src="/globalgraphics/instructions/viewpoint_logo.gif" alt="Viewpoint" /></td>'
        			+'<td align="center"><i><strong>Known issues:</strong> Safari browser has installation issues on select operating systems.</i> </td>'
      				+'</tr></table></div></div>';
					
					
	document.getElementById("sfmediaholder").innerHTML=loadscenehtml;
	
}

function turnpanooff(){
	//var appletinfo = document.ptviewer.getAppletInfo();
	var newpano = '{file=patio.jpg}';
	document.ptviewer.newPano(newpano);
	//alert(appletinfo);
}

function expandmappane(){
	togglemapdisplay('full')
}

function collapsemappane(){
	togglemapdisplay('off')
}


function togglemapdisplay(state){
	
	var viewingbuffer = 25;
	var viewingwidth=(document.getElementById('sfbanner').offsetWidth - viewingbuffer);
	
	//alert(pagesize.offsetWidth );
	
	if(state=='full'){
		document.getElementById("greetingmap").style.visibility = "visible";
		document.getElementById('greetingmap').style.height = '375px';
		var maptriggerhtml = '<a href="javascript:togglemapdisplay(\'off\')">Turn Map Off</a>';
		document.getElementById("editmap").innerHTML = maptriggerhtml;
	}
	
	if(state=='off'){
		document.getElementById("greetingmap").style.visibility = "hidden";
		document.getElementById('greetingmap').style.height = '0px';
		var maptriggerhtml = '<a href="javascript:togglemapdisplay(\'full\')">Turn Map On</a>';
		document.getElementById("editmap").innerHTML = maptriggerhtml;
	}
	
	if(state=='split'){
		document.getElementById("greetingmap").style.visibility = "visible";
		document.getElementById('greetingmap').style.height = '375px';
		document.getElementById('greetingmap').style.width = (viewingwidth/2) + 'px';
		
		document.getElementById("greetingmedia").style.visibility = "visible";
		document.getElementById('greetingmedia').style.height = '375px';
		document.getElementById('greetingmedia').style.width = (viewingwidth/2) + 'px';
	}
	
	map.checkResize();
	
}

function plotdestination(mapbubblehtml){
	
	var lat = parseFloat(destarray[0].lat);
	var lng = parseFloat(destarray[0].lng);
	var zoom = parseFloat(destarray[0].zoom);
	var point = new GLatLng(lat,lng);
	
	panoClient.getNearestPanorama(point, ispanoavailable);
	
	var label1 = 'Info';
	var label2 = 'Directions';
	
	configmap(point, zoom, destarray[0].maptype);
    var newmarker = new GMarker(point, {icon:location_marker});
    map.addOverlay(newmarker);
	activemarker=newmarker;
	
	var directionpoints = newmarker.getPoint().y+','+newmarker.getPoint().x;
	var directionstab ='<div align="left" class="cpfontblack" id="bubble"><span class="titlefont">DIRECTIONS:<br><br><a href="javascript:setdirectionbubble(\'to\', \''+directionpoints+'\' )">To Here  </a>   OR   <a href="javascript:setdirectionbubble(\'from\', \''+directionpoints+'\')">  From Here</a></span></div><div><a href="javascript:connecttostorefront('+lat+','+lng+')"><span style="font-size:8px;">Connect Destinations</span></a></div>';
		
	GEvent.addListener(newmarker, "click", function(marker, point) {
		newmarker.openInfoWindowTabsHtml([new GInfoWindowTab(label1,mapbubblehtml), new GInfoWindowTab(label2,directionstab)]);
	});
	
	newmarker.openInfoWindowTabsHtml([new GInfoWindowTab(label1,mapbubblehtml), new GInfoWindowTab(label2,directionstab)]);
	
}


function addblogentry(){
	parent.dynamicedit('blog');
}


function cleanstring(searchstring){
	var newstring=searchstring.replace(/'/g, "\\'");
	newstring=newstring.replace(/|/g, '');
	
	//alert(newstring);
	return newstring;
}

//SEND TO ME FUNCTION
function prepforsend(){
	
	sendtomehtml = buildsendtomehtml;
	
	buildsendbubble();
	
	setTimeout("highslidecontrol('sendtome')",500);
}

function sendtexttoowner(textsubject, sendtext){
	try{
		closeactiveexpander();
	}catch(err){
		//NO ACTION
	}
	
	//alert(textsubject);
	
	var owneruser = destarray[0].username;
	//alert(owneruser);
	
	var owneremail = getuseremail(owneruser);
	//var owneremail = 'mmedalia@virtualeyes.net'
	//alert(owneremail);
	
	sendemail(owneremail, textsubject, sendtext);
	alert("Your message as been sent.");
}

//LOAD CONTENT FUNCTIONS
function createXMLHttp(){if(typeof XMLHttpRequest!="undefined"){return new XMLHttpRequest()}else if(window.ActiveXObject){var aVersions=["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
for(var i=0;i<aVersions.length;i++){try{var xmlRequest=new ActiveXObject(aVersions[i]);
return xmlRequest}catch(oError){}}}throw new Error("XMLHttp object could be created.");}

function DoCallback(url,params){
	var pageUrl=url+"?callback=true&param="+params;
	var xmlRequest=createXMLHttp();
	xmlRequest.open("POST",pageUrl,false);
	xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlRequest.send('');
	return xmlRequest
}


//function getlayout(layoutdetinationid){
//	
//	//layoutdetinationid ='mmedaliaD938A04DA7D4BE40957C9289542AAED3D';
//	//alert(layoutdetinationid);
//	if(layoutdetinationid){
//		var xmlRequest=DoCallback('../controls/ServerToJavascript.aspx',layoutdetinationid+',layout');
//	
//		return(xmlRequest.responseText);
//		
//	}else{
//		return('failed.');
//	}
//}


function loadtag(content, name, description){
	
	document.getElementById("sfmediaholder").innerHTML = "Loading content";
		
	document.getElementById("sfmediaholder").innerHTML = '<div>'+ content + '</div>';
	//document.getElementById("sfmediadescription").innerHTML = description;
	
}


function loadvideo(video){

		var videoplayer = '<object type="application/x-shockwave-flash" data="FlowPlayerWhite.swf"';
       videoplayer +='width="320" height="240">';
       videoplayer +='<param name="allowScriptAccess" value="sameDomain" />';
       videoplayer +='<param name="movie" value="FlowPlayerWhite.swf" />';
       videoplayer +='<param name="quality" value="high" />';
       videoplayer +='<param name="scale" value="Scale" />';
       videoplayer +='<param name="wmode" value="transparent" />';
       videoplayer +='<param name="flashvars" value="config={videoFile: \'' + video + '\' , showMenu: false , loop: false , showLoopButton: false}" />';
       videoplayer +='</object>';
          //document.getElementById("sfmediadescription").innerHTML = videoplayer
}
//END OF LOAD CONTENT FUNCTION


