// sets height of map based on ammount of content
function getHeight(column,map){
	var columnHeight = document.getElementById(column).offsetHeight;
	if (map == 'projectMap') {
		columnHeight = columnHeight - 160;
	}
	document.getElementById(map).style.height=columnHeight+'px';
}

// open pop-up
function popWindow(page, xSize, ySize) {
	window.open(page,"navWindow","toolbar=no,scrollbars=1,location=0,status=0,menubar=0,resizable=yes,width="+xSize+",height="+ySize);
}


// confirm logout
function logOUT() {
	var userResponce = window.confirm('Are you sure you want to logout?');
	if (userResponce == true)  { 
    	document.location = '../../login/logout.php';	
	} 
}


// confirm display (PRINT vs WEB) change
function displayWarning(item,thisform){
	if (item == "0") {
		var userResponce = window.confirm('Checking this option will remove this project from the Print Ad list, and move it to the Web ONLY list.');
		if (userResponce == false) {
			document.forms[thisform].projDisplay[item].checked=true;
		}
	} else {
		var userResponce = window.confirm('Checking this option will remove this project from the Web ONLY list, and move it to the Print Ad list.');
		if (userResponce == false) {
			document.forms[thisform].projDisplay[item].checked=true;
		} else {
			document.getElementById('selectLetter_' + item).style.display='block';
		}
	}
}


// confirm approval
function approve(sponsor) {
	var userResponce = window.confirm('Do you want to approve all projects\nas listed on this page?');
	if (userResponce == true)  { 
    	document.location = 'approve_all.php?sponsor=' + sponsor;	
	} 
}

// confirm submission to live web for project
function setLive(formVal) {
	var userResponce = window.confirm('You are about to post this project as is to the live website.');
	if (userResponce == true)  { 
    	document.forms[formVal].live.value="1";
	return true;	
	} 
}


// confirm and delete project
function removeProject(name,id) {
	var userResponce = window.confirm('Are you sure you want to delete the ' + name + ' project?');
	if (userResponce == true)  { 
    	document.location = 'remove.php?project=' + id;	
	} 
}


// confirm and delete document
function removeDocument(id, name) {
	var userResponce = window.confirm('Are you sure you want to delete the document:  ' + name + ' ?');
	if (userResponce== true) {
		document.location = "remove.php?id=" + id + "&kind=doc";
	}
}
	
// confirm and delete user
function removeUser(id, name) {
	var userResponce = window.confirm('Are you sure you want to delete the user:  ' + name + ' ?');
	if (userResponce== true) {
		document.location = "remove.php?id=" + id + "&kind=user";
	}
}

// confirm and delete region
function removeRegion(name) {
	var userResponce = window.confirm('Are you sure you want to delete the region:  ' + name + ' ?');
	if (userResponce== true) {
		document.location = "regionEdit.php?id=" + name + "&kind=region";
	}
}
	

// change value of edit field in form & remove update message
function changeUpdate() {
	if (document.forms[0].edit) {
		document.forms[0].edit.value = 'yes';
	}
	document.getElementById('updateSucess').style.display="none";
}


// shows/hides project letter select list based on radio button
function radioSwap(showState){
	if (showState == 1) {
		document.getElementById('selectLetter').style.display="block";
	} else {
		document.getElementById('selectLetter').style.display="none";
	}
}


// show or hide extra project information
function showHide(project, state) {
	/*alert('show_' + project);*/
	if (state == 1) {
		document.getElementById('show_' + project).style.display="block";
		document.getElementById('hide_' + project).style.display="none";
	} else {
		document.getElementById('show_' + project).style.display="none";
		document.getElementById('hide_' + project).style.display="block";
	}
}


// Change Subject and Body of Email
function unCheck(){
	i = 1;
	while(document.forms[0].elements[i]) {
		if(document.forms[0].elements[i].type == "checkbox") {
			if(document.forms[0].elements[i].defaultChecked == false) {
				document.forms[0].elements[i].checked = false;
			}
		}
		i++;
	}
}

	
function mailSwitch(id,theDates,name){
	switch (id) {
		case "generic" :
			document.forms[0].subject.value = "";
			document.forms[0].body.value = "";
			i = 1;
			while(document.forms[0].elements[i]) {
				if(document.forms[0].elements[i].type == "checkbox") {
					document.forms[0].elements[i].checked = true;
				}
				i++;
			}
		break;

		case "new" :
			document.forms[0].subject.value = "Online Navigator projects ready for review";
			document.mailForm.body.value = "Projects for the week of " + theDates + " are posted on line at http://www.alaskanavigator.org/login. Your login is your email address and your password is your first name with the first letter capitalized. Please review the details for your project and update accordingly no later than Monday morning. Contact me with any questions or problems accessing the site. Thanks, " + name + ".";
			unCheck()
		break;

		case "remind" :
			document.forms[0].subject.value = "Reminder: Online Navigator projects";
			document.mailForm.body.value = "Your projects for the week of " + theDates + " , posted on line at http://www.alaskanavigator.org/login, have not yet been reviewed. Please login and review your projects for the weekly navigator no later than noon today. Your login is your email address and your password is your first name with the first letter capitalized. Please review the details for your project and update accordingly. Contact me with any questions or problems accessing the site. Thanks, " + name + ".";
			unCheck()
			break; 
	}
}


// check for form submission before continuing    
function checkForm(page) {
	if (document.forms[0].edit.value == 'no') {
    	if (page == 'close') {
    		window.close();
    	} else {
    		var destination=page;
    		document.location=destination;
    	}	
	} else {
    	var userResponce = window.confirm('You are about to leave this window without saving your changes.');
		if (userResponce == true)  { 
    		if(page == 'close') {
    			window.close();
    		} else {
    			var destination=page;
    			document.location=destination;
    		}
		}
	}
}

// center the map based on the marker location
function centerTheMap (nLat, nLng, nZoom) {
	if (nZoom) { document.map.setZoom(nZoom) };
	document.map.panTo(new GLatLng(nLat, nLng));
}


		
// closure marker icon
var closedIcon = new GIcon(); 
closedIcon.image = 'http://alaskanavigator.org/images/markerRed.png';
closedIcon.shadow = 'http://alaskanavigator.org/images/shadow.png';
closedIcon.iconSize = new GSize(20, 34);
closedIcon.shadowSize = new GSize(37, 34);
closedIcon.iconAnchor = new GPoint(9, 34);
closedIcon.infoWindowAnchor = new GPoint(9, 2);

// standard marker icon
var standardIcon = new GIcon(); 
standardIcon.image = 'http://alaskanavigator.org/images/markerYellow.png';
standardIcon.shadow = 'http://alaskanavigator.org/images/shadow.png';
standardIcon.iconSize = new GSize(20, 34);
standardIcon.shadowSize = new GSize(37, 34);
standardIcon.iconAnchor = new GPoint(9, 34);
standardIcon.infoWindowAnchor = new GPoint(9, 2);

// small marker icon
var smallIcon = new GIcon(); 
smallIcon.image = 'http://alaskanavigator.org/images/small_yellow.png';
smallIcon.shadow = 'http://alaskanavigator.org/images/small_shadow.png';
smallIcon.iconSize = new GSize(12,20);
smallIcon.shadowSize = new GSize(22, 20);
smallIcon.iconAnchor = new GPoint(6,20);
smallIcon.infoWindowAnchor = new GPoint(6, 1);

// small closure marker icon
var smallCloseIcon = new GIcon(); 
smallCloseIcon.image = 'http://alaskanavigator.org/images/small_red.png';
smallCloseIcon.shadow = 'http://alaskanavigator.org/images/small_shadow.png';
smallCloseIcon.iconSize = new GSize(12,20);
smallCloseIcon.shadowSize = new GSize(22, 20);
smallCloseIcon.iconAnchor = new GPoint(6,20);
smallCloseIcon.infoWindowAnchor = new GPoint(6, 1);


var customIcons = [];
customIcons["largeStandard"] = standardIcon;
customIcons["largeClosure"] = closedIcon;
customIcons["standard"] = smallIcon;
customIcons["closure"] = smallCloseIcon;

// project boundry line
var projectBoundry = new GPolyline();
projectBoundry.color = "#3333cc";
projectBoundry.weight = 10;
projectBoundry.opacity = 0.6;
projectBoundry.zoomFactor = 6;
projectBoundry.numLevels = 4;

// detour line
var detourLine = new GPolyline();
detourLine.color = "#42D61D";
detourLine.weight = 4;
detourLine.opacity = 0.8;
detourLine.zoomFactor = 6;
detourLine.numLevels = 4;

// closure line
var closureLine = new GPolyline();
closureLine.color = "#FF0000";
closureLine.weight = 10;
closureLine.opacity = 0.9;
closureLine.zoomFactor = 6;
closureLine.numLevels = 4;

// function to toggle between mid-month marker and days
function midMarker(userItem,userForm) {
	if (userForm == undefined) { userForm = '0'; }
	if (userItem == 'projDay') {
		document.forms[userForm].mid.checked=false;
	} else {
		document.forms[userForm].projDay.selectedIndex=0;
	}
}