
var viewer = null;

function doWindow(name,url,width,height,sbars){
	
	window.open(url, name, 'width=' + width + ',height=' + height + ',' + getPosition(width, height) + ',resizable=no,scrollbars=' + ((sbars) ? 'yes': 'no') + ',status=1');
	
	return false;
}

function doNews(path){
	
	doWindow("NewsWindow","/scripts/events/editNews.jsp?" + path,550,450,false);				
	
	return false;
}

function doUser(path){
	
	doWindow("UserWindow","/scripts/events/editUser.jsp?" + path,400,300,false);				
	
	return false;
}

function doObjectives(path){

	doWindow("ObjectivesWindow","/scripts/events/editObjectives.jsp?" + path,400,300,false);		
		
	return false;
}

function doOrders(path){
	
	doWindow("OrdersWindow","/scripts/events/editOrders.jsp?" + path,550,425,false);		
	
	return false;
}

function doMap(path){
	
	doWindow("MapWindow","/scripts/events/editMap.jsp?" + path,770,570,true);
		
	return false;
}

function createMission(path){
	
	doWindow("MissionWindow","/scripts/events/admin/mission.jsp?" + path,430,340,false);		
	
	return false;
}

function editMissions(path){
	
	doWindow("MissionWindow","/scripts/events/admin/frame_missions.jsp?" + path,650,500,true);		
	
	return false;
}

function editUnit(path){
	
	doWindow("UnitWindow","/scripts/events/admin/unit.jsp?" + path,430,340,false);		
	
	return false;
}

function editFrameUnit(path){
	
	doWindow("UnitWindow","/scripts/events/admin/frame_unit.jsp?" + path,650,500,true);		
	
	return false;
}

function callReserves(selector, path){
	
	var result = true;
	
	if(selector.options[selector.selectedIndex].value == "reserves")
		result = doWindow("ReservesWindow","/scripts/events/reserves.jsp?" + path,290,460,false);		
	
	return result;
}


function findParticipants(){
	
	doWindow("ParticipantsWindow","/scripts/events/admin/participants.jsp",350,500,false);		
	
	return false;
}

function checkSignup(cost){
	
	var missions	= document.signupForm.mission;
	var mid 		= 0;
	
	if(!missions.length){
		mid = missions.value;
	}
	else{
		
		for(var i = 0; i < missions.length; i++){
			
			if(missions[i].checked)
				mid = missions[i].value;
			
		}
		
	}
		
	if(mid > 0){
		
		if(cost == "Pay For Play")
			return confirm('IMPORTANT!\nARE YOU SURE YOU WANT TO SELECT THIS MISSION?\n\n\nTHIS IS A PAY FOR PLAY EVENT- In order to participate in this mission/frame/event you must have purchased an Event ticket by visiting your Account page. By clicking \'OK\' you authorize Playnet to assign an available Event ticket from your account in order to complete the sign-up process for this mission/frame/event.\n\n\nYou further agree to abide by Playnet\'s terms of service which include but are not limited to Playnet\'s \'No Refund\' policy for all charges including Special Events. Playnet may, at its own discretion re-run a frame and/or event for causes such as network failures, host errors or other circumstances. Events may be rescheduled without notice. Game play rules and environments may change without notice. Event frame tickets are non-refundable, non-redeemable and non-transferable for any reason. For a complete listing of Playnet\'s terms of service, visit http://www5.playnet.com/bv/tos.jsp');
		else if(cost == "Sponsored")
			return confirm('IMPORTANT!\nARE YOU SURE YOU WANT TO SELECT THIS MISSION?\n\nSpecial Notice- For this event only, the event frame ticket cost of $1.99 has been waived thanks to the publishers of \'World War II Magazine\'. Learn more by visiting www.historynet.com\n\nBy clicking \'OK\' you authorize Playnet to charge your account $1.99 for this event frame. You further agree to abide by Playnet\'s terms of service which include but are not limited to Playnet\'s \'No Refund\' policy for all charges including events. Playnet may, at its own discretion re-run a frame and/or event for causes such as network failures, host errors or other circumstances. Events may be rescheduled without notice. Game play rules and environments may change without notice. Event frame tickets are non-refundable, non-redeemable and non-transferable for any reason. For a complete listing of Playnet\'s terms of service, visit http://www5.playnet.com/bv/tos.jsp');
		else
			return confirm('IMPORTANT!\nARE YOU SURE YOU WANT TO SELECT THIS MISSION?\n\n\nYOUR EVENT TICKET IS COMPLIMENTARY- For this event only the ticket cost has been waived\n\n\nYou agree to abide by Playnet\'s terms of service which include but are not limited to Playnet\'s \'No Refund\' policy for all charges including Special Events. Playnet may, at its own discretion re-run a frame and/or event for causes such as network failures, host errors or other circumstances. Events may be rescheduled without notice. Game play rules and environments may change without notice. Event frame tickets are non-refundable, non-redeemable and non-transferable for any reason. For a complete listing of Playnet\'s terms of service, visit http://www5.playnet.com/bv/tos.jsp');
		
	}
	
	alert('You must select a mission to join.');
	
	return false;
	
}

/*
function checkReserves(selection){
	
	var result 		= false;
	var selected 	= -1;
	
	//alert("Mission Count is " + selection.checked);
	
	if(!selection.length){
		selected = 0;
	}
	else{
		for(var i = 0; i < selection.length; i++){
			if(selection[i].checked){
				selected = i;
				break;
			}
		}
	}
	
	if(selected < 0)
		alert('You must select a mission to join.');
	else if(selection[selected].value == "reserves")
		result = confirm('You have chosen a reserve unit. There is no guarantee that reserve unit members will be called up. Are you sure?\n\nBy selecting "OK" you agree to abide by Playnet Inc\'s terms of service which include but are not limited to our \'no refund\' policy for any event in which a fee is charged. Playnet may, at it\'s discretion re-run an event due to network failures, host errors or other circumstance. Events may be rescheduled without notice. The game play rules and game environments may change without notice. Event tickets are non-refundable and non-transferable for any reason at any time. For a complete listing of Playnet Inc.\'s terms of service, visit http://www5.playnet.com/bv/tos.jsp');
	else
		result = confirm('IMPORTANT!\nARE YOU SURE YOU WANT TO SELECT THIS MISSION?\n\n\nSpecial Notice- For this event only, the event frame ticket cost of $1.99 has been waived thanks to the publishers of \'World War II Magazine\'. Learn more by visiting www.historynet.com\n\n\nBy clicking \'OK\' you authorize Playnet to charge your account $1.99 for this event frame. You further agree to abide by Playnet\'s terms of service which include but are not limited to Playnet\'s \'No Refund\' policy for all charges including events. Playnet may, at its own discretion re-run a frame and/or event for causes such as network failures, host errors or other circumstances. Events may be rescheduled without notice. Game play rules and environments may change without notice. Event frame tickets are non-refundable, non-redeemable and non-transferable for any reason. For a complete listing of Playnet\'s terms of service, visit http://www5.playnet.com/bv/tos.jsp');
	
	return result;
}
*/

function addParticipant(name, value){

	var selector	= document.eventForm.participants;
	var slength 	= selector.length;
	var exists		= false;
	
	for(var i = 0; i < slength; i++){
		if(selector.options[i].value == value){
			exists = true;
			break;
		}
	}
	
	if(!exists){
		selector.options[slength] 			= new Option(name,value);
		selector.options[slength].selected 	= true;;
	}
}

function closeWindow(refresh){
	
	if(refresh && window.opener.refreshPage != null)
		window.opener.refreshPage();
	
	window.close();
}

function getPosition(width, height){
	
	var winTop 		= (screen.height - height) / 2;
	var	winLeft 	= (screen.width - width) / 2;
	
	return "screenX=" + winLeft + ",left=" + winLeft + ",screenY=" + winTop + ",top=" + winTop;
}

function refreshPage(){
	window.location.reload();
}

function doViewer(url,width,height){
	
	if(viewer != null)
		viewer.close();
	
	viewer = window.open(url, "viewer", 'width=' + width + ',height=' + height + ',' + getPosition(width, height) + ',resizable=yes,scrollbars=auto,status=0');
	
	return false;
}

function validateAAR(){
	
	var limit = 1000;
	
	if(document.aarForm.report.value.length > limit){
		
		alert("Your report is to long. Reports may only have 1000 characters in them. Please trim " + (document.aarForm.report.value.length - limit) + " characters from it and then re-submit.");
		
		return false;
		
	}
	
	return true;
}

function showMissionMenu(id){
		
       if(document.layers){
			eval("document.item" + id + ".visibility = \"visible\""); // NN4
       }
       else if(document.all){
			eval("document.all.item" + id + ".style.visibility= \"visible\""); // IE
       }
       else if(!document.all && document.getElementById){
			document.getElementById("item" + id).style.visibility = "visible"; // NN6
       }
	
}

function hideMissionMenu(id){
		
       if(document.layers){
			eval("document.item" + id + ".visibility = \"hidden\""); // NN4
       }
       else if(document.all){
			eval("document.all.item" + id + ".style.visibility= \"hidden\""); // IE
       }
       else if(!document.all && document.getElementById){
			document.getElementById("item" + id).style.visibility = "hidden"; // NN6
       }
	
}
