var map = null;
    var geocoder = null;

    /*var localSearch = new GlocalSearch();   */
    var title_array = new Array();
    var marker_array = new Array();
    var k=0;
    var j=0;
    
    function setFontSize(i){
    setCookie("fontsize", i, 30);
    location.reload(true);
    }
    
    function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

    function initialize(addr) {
     // if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.setMapType(G_NORMAL_MAP);
        map.setUIToDefault();
        geocoder = new GClientGeocoder();
         geocoder.getLatLng(
          addr,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {map.setCenter(point, 9); } } );
  //  }
   }


   
    function showAddress(lat, long, mytitle) {
  /*usePointFromPostcode(address, placeMarkerAtPoint, mytitle); */

    var point = new GLatLng(lat, long);

              var marker = new GMarker(point);
              map.addOverlay(marker);
              GEvent.addListener(marker, "click", function() {
  marker.openInfoWindowHtml(mytitle);
  });


    }

function copyDetails(){

	document.myform.delivery_name.value=document.myform.forename.value+" "+document.myform.surname.value;
	document.myform.delivery_telephone.value=document.myform.telephone.value;
	document.myform.delivery_address_1.value=document.myform.address_1.value;
	document.myform.delivery_address_2.value=document.myform.address_2.value;
	document.myform.delivery_city.value=document.myform.city.value;
	document.myform.delivery_county.value=document.myform.county.value;
	document.myform.delivery_postcode.value=document.myform.postcode.value;
	document.myform.delivery_country.value=document.myform.country.value;
	
}

function submitForm(theform){
	if(validateForm(theform))
	eval("document."+theform+".submit()");
}


//check that all fields with classname 'required' are filled in
function validateForm(formname){
var elems=eval("document."+formname+".elements"); 
var valid=true;
for(var i=0;i<elems.length;i++){
	if(elems[i].className=='required'){
	switch(elems[i].type) {
			case "text" :
				if(elems[i].name=='email_address'){
					valid=isEmail(elems[i].value);
				}
			case "password" :
				if(elems[i].value==""){
					valid=false;
					alert("Please fill in all required fields");
				}
				break;
			case "select-one" :
				if(elems[i].value==''){
					alert("Please select an option from the dropdowns");
					valid=false;
				}
				break;
			case "radio" :
				valid = isSelected(formname, elems[i].name);
				break;
		}
		if(!valid){
			return valid;
		}
	}
}
return true;
}


/** isChecked
 * returns true if at least one of a group of checkboxes is checked
 **/
function isChecked(formname, checkboxname){
	var isChecked = false;
	var chkbx=eval('document.'+formname+'.'+checkboxname);
	for (var i = 0; i < chkbx.length; i++) {
  	 	if (chkbx[i].checked) {
   	   	isChecked = true;
   		}
	}
	if(!isChecked)
		alert("Please tick all required checkboxes");
	return isChecked;
}

/** isSelected()
 * Returns true if one of a group of radio buttons is selected
 **/
function isSelected(formname, radioname){
	var isChecked = false;
	var chkbx=eval('document.'+formname+'.'+radioname);
	if(!chkbx.length){
		if(chkbx.checked)
			isChecked=true;
	}
	else{
		for (var i = 0; i < chkbx.length; i++) {
			if (chkbx[i].checked) {
			isChecked = true;
			}
		}
	}
	if(!isChecked)
		alert("Please tick all required Radio buttons");
	return isChecked;
}


function isEmail(str){
	if((str.indexOf('@')==-1)||(str.indexOf('.')==-1)){
		alert("Invalid email address");
		return false;
	}
	else
		return true;
}

/*** This validation function checks that an email address contains both '@' and '.' **/
function validateEmailAddress(email_address){
var email = document.getElementById(email_address).value;
	if((email.indexOf('@')==-1)||(email.indexOf('.')==-1)){
		alert("Invalid email address");
		return false;
	}
	else
		return true;
}

//Check that two fields have the same values, useful for password changes etc
function validateSame(type, retype){
if(document.getElementById(type).value == document.getElementById(retype).value)
	return true;
else{
	return false;
}
}



function setAttendees(id, num){
document.getElementById('number_'+id).value=num;	
eval("document.theform_"+id+".submit()");

}


/**************** AJAX STUFF **************/

/*** Updating subtopic when topic selected **/

function handleUpdateSubSectionMenu() {
  if (http.readyState == 4) {
    // Split the comma delimited response into an array
    results = http.responseText;
    document.getElementById('subsection_menu').innerHTML = results;

  }
  
}
function updateSubSectionMenu(root_dir, type) {
	document.getElementById('subsection_menu').innerHTML = 'Updating......';
 	var a_f = document.getElementById('section').value;
	var url=root_dir+'ajax/subsectionMenu.php?check=suscms&type='+type+'&section='+a_f+'';
	http.open("GET", url, true);
	http.onreadystatechange = handleUpdateSubSectionMenu;
	http.send(null);

}

function setSectionID(value){
	document.getElementByID('section_id').value=value;
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object




