///////////////// GENERAL /////////////////////////////
function saveScrollCoordinates() { 
	var hiddenY = document.getElementById('scrollY');
	var top = document.body.scrollTop;
 
	if (top == 0) {
		if (window.pageYOffset) {
			top = window.pageYOffset;
		}
		else {
			top = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
	}
	
	hiddenY.value = top;
} 

function scrollToCoordinates() { 
	var y = document.getElementById('scrollY').value;
	window.scrollTo(0, y); 
} 


function openDetailWindow(url,title){ 
	var ajaxwin = dhtmlwindow.open("ajaxbox", "ajax", url, title, "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1");
}


///////////////// HOME PAGE & CALENDAR PAGES //////////////////////////////
function clearLoadingMessage() {
	var div = document.getElementById('iframeMessage');
	if (div != null) {
	    div.innerHTML = "";
	}
}


///////////////// GROUPS PAGE ///////////////////////////
function clearCounties() {
	selectCounties(false);
}

function allCounties() {
	selectCounties(true);
}

function selectCounties(value) {
	var inputs = document.getElementsByTagName('input');
	for (i = 0; i < inputs.length; i++) {       
		if (inputs[i].type == 'checkbox') {    
			inputs[i].checked = value;
		}   
	}
}

//////////////// ADMIN PAGE ///////////////////////////
function confirmSubmit(type) {
	var agree = confirm("Are you sure you wish to " + type + "?");
	if (agree) {
		return true;
	}
	else {
		return false;
	}
}

function checkCity(txt) {
	var val = txt.value;
	var len = val.length;
	
	if (len > 0) {
	    var msg = "Please make sure that '" + val + "' is not already in the city dropdown, and that you have selected a county.";
	    alert(msg);
	}
}

///////////// ADMIN PAGE AJAX ///////////////////////////

// Get the HTTP Object
function getHTTPObject(){
	if (window.ActiveXObject) 
	{
		//return new ActiveXObject("Microsoft.XMLHTTP");
		//alert("window.ActiveXObject");
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) 
	{
		//return new XMLHttpRequest();
		alert("XMLHttpRequest()");
		return new XMLHttpRequest();
	}
	else 
	{
		alert("Your browser does not support AJAX.");
		return null;
	}
}

// Implement business logic
function getText(){
	var txt = document.getElementById('txtMain');
	alert(txt); //debug
	txt.value = 'whatever';
	/*httpObject = getHTTPObject();
	alert(httpObject); //debug
	if (httpObject != null) {
		alert("httpObject != null"); //debug
		var sel = document.getElementById('selPages');
		alert(sel); //debug
		var id = sel.options[sel.selectedIndex].value;
		alert(id); //debug
		httpObject.open("GET", "adminajax.php?getText="+id, true);
		httpObject.send(null); 
		httpObject.onreadystatechange = setOutput;
	}*/
}

// Change the value of the outputText field
function setOutput(){
	if(httpObject.readyState == 4){
		//alert(httpObject.responseText); //debug
		var txt = document.getElementById('txtMain');
		alert(txt); //debug
		txt.defaultValue = 'whatever';
		
	}
}
////////////////////////////////////////////////////////////////////////

//function checkinf(){
//	var name = document.forms.CPOF.FullName.value;	
//	var email = document.forms.CPOF.Email.value;
//	var msg = '';
	
//	if(!name) msg += "Please enter your name.\n";
//	if(!email) msg += "Please enter your email.\n";
	
//	if(msg){
//		alert("Error!\n\n"+msg);
//		return false;
//	}else{
//		return true;	
//	}
//}

