// JavaScript Document
var buildsendtomehtml;
var mapbubblehtml;

var pagemode;
var destarray=[];
var desteventarray = [];
var updatedmarker;
var sectionlayouts;
//Added to make the searchfunction.js file compatible
var currentuser;

var globalscenepath;
var globalinputfield = 'blank';
var globalheaderitem;

//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 searchscripts = false;
var calendarscripts = false;

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 setthefocus(activeid){
    //alert('Setting globalenter to: '+activeid );
	document.getElementById(activeid).value = '';
	var newfocus = 	document.getElementById(activeid);
	newfocus.focus();
	globalinputfield = activeid;
}

function winattributes(){
	getbrowser();
	getwinsize();
	//alert(windowheight);
	document.getElementById("dynamback").style.minHeight = windowheight + 'px';
}

//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 'txtLocationSearchAjax':
				geopurpose = 'createctherehome';
				templocstring = document.getElementById("txtLocationSearchAjax").value;
				//alert(templocstring);
				if(templocstring != ''){
					callgeocode(templocstring);
				}else{
					alert('Please enter a valid location search term');	
				}
			break;
			
			case 'txtBusinessSearchAjax':
				geopurpose = 'createctherebiz';
				currentbizsearchterm = document.getElementById('txtBusinessSearchAjax').value;
				templocstring = document.getElementById("txtBusinessSearchAjaxLoc").value;
				if((templocstring != '')&&(currentbizsearchterm != '')){
					callgeocode(templocstring);
					//closeactiveexpander();
				}else{
					alert('Please enter valid search terms');	
				}
			break;
			
			case 'txtctheresearch':
				searchctheredest();
			break;
			
			case 'password':
				loginButton_Click();
			break;
			
			case 'saddr':
				getdirections('to', globaldirectionpoint);
			break;
			
			case 'daddr':
				getdirections('from', globaldirectionpoint);
			break;
			
			default:
				return false;
			break;
		}
		
		globalinputfield = 'blank';
	  
}

function getlayout(whichl){
	
	switch(whichl){
		
		case 'createcthere':
			makeHttpRequest('cpajax/cplayouts.xml', setcreatecthere, true, 'ctherelocatedest');
		break;
		
		case 'createctherebiz':
			makeHttpRequest('cpajax/cplayouts.xml', replacecreateajax, true, 'ctherelocatedestbiz');
		break;
		
		case 'newdestmenu':
			makeHttpRequest('cpajax/cplayouts.xml', replacecreateajax, true, 'ctherenewdestmenu', 'newdestmenu');
		break;
		
		case 'ctheremapclick':
			makeHttpRequest('cpajax/cplayouts.xml', setcreatecthere, true, 'ctherelocatedestmapclick');
		break;
		
		case 'ctherelatlng':
			makeHttpRequest('cpajax/cplayouts.xml', setcreatecthere, true, 'ctherelocatedestlatlng')
		break;
		
		case 'ctherebizsearch':
			addsearchscripts();
			makeHttpRequest('cpajax/cplayouts.xml', setcreatecthere, true, 'ctherelocatedestbiz')
		break;
	}
	
}

function createstepone(){
	makeHttpRequest('cpajax/cplayouts.xml', setcreatecthere, true, 'ctherelocatedest');	
}

function setcreatecthere(rethtml){
	//alert(rethtml);
	document.getElementById("ctherelocatedest").innerHTML = rethtml;
}

function restartcreate(){
	resetcreatepanels();
	createstepone();
	changetabstrip('cthere');
}

function detailsform(){
	changetabstrip('details');
}

function addsearchscripts(){
	addjspage('cpsearchfunctions');
	searchscripts = true;
}
