//// Get address variables
var form_name;
var addy_1_field;
var addy_2_field;
var town_field;
var county_field;
var post_code_field;
var use_lat_lng;
var lat_field;
var lng_field;
var returned_xml;
var user_send_string="";
var business_type_send_string="";
var company_postions_string="";

var ns4 = document.layers;
var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1)||(navigator.userAgent.indexOf("Opera/5")!=-1);
var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1);
var agt=navigator.userAgent.toLowerCase();
var mac = (agt.indexOf("mac")!=-1);
var ie = (agt.indexOf("msie") != -1); 
var mac_ie = mac && ie;

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = SetMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function SetMouseXY(e){

   if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
	//alert(tempY);
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  
  
}

/////////#############################################################################
/////////#############################################################################
function toggle_Nav(node_id)
{
	//alert(node_id);

  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById("" + node_id + "_subs");
  else if( document.all ) // this is the way old msie versions work
      elem = document.all["" + node_id + "_subs"];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers["" + node_id + "_subs"];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  
  
  //alert(Right(id.src,20));
  if(Right(document.images("" + node_id + "_toggle").src,19)=="/images/nav_off.png"){
  
	document.images("" + node_id + "_toggle").src="/images/nav_on.png";

	}
  else
  	{
  
  	document.images("" + node_id + "_toggle").src="/images/nav_off.png";
  
  	}
  
}
/////////#############################################################################
/////////#############################################################################
function internal_nav_link(nav_idx,page_title){

	//document.location="/index.asp?nav_idx="+nav_idx+"&page_idx=1";
	document.location="/pages/" + nav_idx + "/1/" + page_title;

}
/////////#############################################################################
/////////#############################################################################
function external_nav_link(link_url){

	if(Left(link_url,7)=="http://"||Right(link_url,3)=="pdf"){
	
	var Nav_win = window.open(link_url,'Nav_win');
	
	}
	else
	{
	
	document.location = link_url;
	
	}
	//Nav_win.moveTo(5,5);

}

/////////#############################################################################
/////////#############################################################################
function toggle_Nav_Admin(node_id,list_node_idx)
{
	//alert(node_id);

  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById("" + node_id + "_subs");
  else if( document.all ) // this is the way old msie versions work
      elem = document.all["" + node_id + "_subs"];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers["" + node_id + "_subs"];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  
  
  /*
  if(document.images){
  //alert(Right(id.src,20));
  if(Right(document.images("" + node_id + "_toggle").src,25)=="/images/folder_closed.png"){
  
	document.images("" + node_id + "_toggle").src="/admin/images/folder_open.png";

	}
  else
  	{
  
  	document.images("" + node_id + "_toggle").src="/admin/images/folder_closed.png";
  
  	}
	}
	*/
	
	Pgurl = "/admin/loading.htm";
	ID_Name = "available_pages"
	ajaxPage(Pgurl,ID_Name);

	Pgurl = "/admin/available_pages.asp?navigation_node_idx=" + list_node_idx ;
	ajaxPage(Pgurl,ID_Name);
	
	ID_Name = "unauthorised_pages"
	Pgurl = "/admin/unauthorised_pages.asp?navigation_node_idx=" + list_node_idx ;
	ajaxPage(Pgurl,ID_Name);
}

/////////#############################################################################
/////////##############################################################################
function ajaxPage(Pgurl,ID_Name)
  {  
  var xmlHttp;
  try
    {    // Firefox, Opera 8.0+, Safari    
	xmlHttp=new XMLHttpRequest();   
	 }
  catch (e)
    {    // Internet Explorer
	  try
      {      
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	   }
    catch (e)
      {
	       try
        {
		       xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			           }
      catch (e)
        {       
		 alert("Your browser does not support AJAX!");
		  return false; 
		   }
		 }
		}
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        //document.getElementById(ID_Name).innerHTML=xmlHttp.responseText;
        document.getElementById(ID_Name).innerHTML=xmlHttp.responseText;

        }
      }
    xmlHttp.open("GET",Pgurl,true);
    xmlHttp.send(null);  
	}
/////////#############################################################################
/////////#############################################################################
function Show_Section_Content(list_node_idx){


	Pgurl = "/admin/loading.htm";
	ID_Name = "available_pages"
	ajaxPage(Pgurl,ID_Name);
	Pgurl = "/admin/available_pages.asp?navigation_node_idx=" + list_node_idx ;
	ajaxPage(Pgurl,ID_Name);
	
	ID_Name = "unauthorised_pages"
	Pgurl = "/admin/unauthorised_pages.asp?navigation_node_idx=" + list_node_idx ;
	ajaxPage(Pgurl,ID_Name);

}
/////////#############################################################################
/////////#############################################################################
function Delete_content_page(page_idx,navigation_node_idx){

var conf = window.confirm("Are you sure you would like to remove this content page?");

if(conf){


	document.location = "/admin/site_layout.asp?remove_page=True&page_idx=" + page_idx + "&navigation_node_idx=" + navigation_node_idx;

}


}
/////////#############################################################################
/////////#############################################################################
function Show_Section_Admin(navigation_node_idx,Admin_Type){


	Pgurl = "/admin/loading.htm";
	ID_Name = "available_pages"
	ajaxPage(Pgurl,ID_Name);
	Pgurl = "/admin/navigation_nodes.asp?navigation_node_idx=" + navigation_node_idx + "&ACTION=" + Admin_Type ;
	ajaxPage(Pgurl,ID_Name);


}

/////////#############################################################################
/////////#############################################################################
function check_section_content(id){


	var nav_title = id.navigation_title.value;
	var nav_external_url = id.navigation_external_link.value;
	
	if(nav_title==""){
	
	alert("You must enter a section name.")
	return false;
	
	}
	
	if(nav_external_url!=""){
	
		// Have entered a link url
		if(Left(nav_external_url,4)=="www."){
		
			id.navigation_external_link.value = "http://" + nav_external_url
			//return false;
		
		}
	
	
	}
	
	
	
}
/////////#############################################################################
/////////#############################################################################
function Delete_Section(layer_idx){


	var conf=window.confirm("Are you sure you would like to delete this section?\nPlease note this will remove all sub sections and their content.");

	if(conf){
	
	
		document.location="/admin/site_layout.asp?navigation_node_idx=" + layer_idx + "&ACTION=DELETE_SECTION";
	
	}

}
/////////#############################################################################
/////////#############################################################################
function Reorder_Section(layer_idx,direction){


	var conf=window.confirm("Are you sure you would like to move this section " + direction + "?");

	if(conf){
	
	
		document.location="/admin/site_layout.asp?navigation_node_idx=" + layer_idx + "&ACTION=MOVE_SECTION&direction=" + direction;
	
	}

}

/////////#############################################################################
/////////#############################################################################
function Rem_news_Item(site_news_idx){

	var conf=window.confirm("Are you sure you want to remove this news item?");

	if(conf){
	
	
		document.location="/admin/list_news.asp?site_news_idx=" + site_news_idx + "&ACTION=REMOVE_NEWS";
	
	}


}
/////////#############################################################################
/////////#############################################################################
function Add_form_field(){

var conf=window.confirm("Are you sure you would like to add a new field to your form?");

if(conf){

	document.mailform.ACTION.value="ADD_FIELD";
	document.mailform.submit();
}

}
/////////#############################################################################
/////////#############################################################################
function Move_form_field(field_id,direction){

if(direction==0){

/// Move form fields upwards
	if(field_id!=1){
	current_field_name_value = document.mailform["mailform_field_name" + field_id].value;
	current_field_type = document.mailform["mailform_field_type" + field_id].value;
	current_field_validation_type = document.mailform["mailform_field_validation_type" + field_id].value;
	current_options_count = document.mailform["field_options_count" + field_id].value;
	var current_options = document.getElementById("field_options"+field_id).innerHTML;
	current_regexp = new RegExp('field_options' + field_id , "g");
	
	current_options = current_options.replace(current_regexp, "field_options" + (field_id-1))

	////
	move_field_name_value = document.mailform["mailform_field_name" + (field_id-1)].value;
	move_field_type = document.mailform["mailform_field_type" + (field_id-1)].value;
	move_field_validation_type = document.mailform["mailform_field_validation_type" + (field_id-1)].value;
	move_options_count = document.mailform["field_options_count" + (field_id-1)].value;
	var move_options = document.getElementById("field_options"+(field_id-1)).innerHTML;
	move_regexp = new RegExp('field_options' + (field_id-1) , "g");

	move_options = move_options.replace(move_regexp, "field_options" + field_id)
	
	document.mailform["mailform_field_name" + (field_id-1)].value = current_field_name_value;
	document.mailform["mailform_field_type" + (field_id-1)].value = current_field_type;
	document.mailform["mailform_field_validation_type" + (field_id-1)].value = current_field_validation_type;
	document.getElementById("field_options" + (field_id-1)).innerHTML = current_options;
	document.mailform["field_options_count" + (field_id-1)].value = current_options_count;
	////
	document.mailform["mailform_field_name" + field_id].value = move_field_name_value;
	document.mailform["mailform_field_type" + field_id].value = move_field_type;
	document.mailform["mailform_field_validation_type" + field_id].value = move_field_validation_type;
	document.getElementById("field_options" + field_id).innerHTML = move_options;
	document.mailform["field_options_count" + field_id].value = move_options_count;


	
	}
}	

if(direction==1){

var field_count = document.mailform["field_count"].value;
/// Move form fields downwards
	if(field_id!=field_count){
	current_field_name_value = document.mailform["mailform_field_name" + field_id].value;
	current_field_type = document.mailform["mailform_field_type" + field_id].value;
	current_field_validation_type = document.mailform["mailform_field_validation_type" + field_id].value;
	current_options_count = document.mailform["field_options_count" + field_id].value;
	var current_options = document.getElementById("field_options"+field_id).innerHTML;
	current_regexp = new RegExp('field_options' + field_id , "g");

	current_options = current_options.replace(current_regexp, "field_options" + (field_id+1))

	////
	move_field_name_value = document.mailform["mailform_field_name" + (field_id+1)].value;
	move_field_type = document.mailform["mailform_field_type" + (field_id+1)].value;
	move_field_validation_type = document.mailform["mailform_field_validation_type" + (field_id+1)].value;
	move_options_count = document.mailform["field_options_count" + (field_id+1)].value;
	var move_options = document.getElementById("field_options"+(field_id+1)).innerHTML;
	move_regexp = new RegExp('field_options' + (field_id+1) , "g");

	move_options = move_options.replace(move_regexp, "field_options" + field_id)


	document.mailform["mailform_field_name" + (field_id+1)].value = current_field_name_value;
	document.mailform["mailform_field_type" + (field_id+1)].value = current_field_type;
	document.mailform["mailform_field_validation_type" + (field_id+1)].value = current_field_validation_type;
	document.getElementById("field_options" + (field_id+1)).innerHTML = current_options;
	document.mailform["field_options_count" + (field_id+1)].value = current_options_count;

	////
	document.mailform["mailform_field_name" + field_id].value = move_field_name_value;
	document.mailform["mailform_field_type" + field_id].value = move_field_type;
	document.mailform["mailform_field_validation_type" + field_id].value = move_field_validation_type;
	document.getElementById("field_options" + field_id).innerHTML = move_options;
	document.mailform["field_options_count" + field_id].value = move_options_count;
	}
}	



}
/////////#############################################################################
/////////#############################################################################
function add_form_option(field_id){


var current_options = document.getElementById("field_options"+field_id).innerHTML;
var field_option_number =(document.mailform["field_options_count" + field_id].value*1) + 1


						new_option_string = "<div id='field_options" + field_id + "_" + field_option_number + "'>"
							
                        new_option_string = new_option_string + "<table width='700' border='0' cellspacing='1' cellpadding='3'>"
                        new_option_string = new_option_string+ "<tr>"
                        new_option_string = new_option_string+ "<td><b>Option name</b></td>"
                        new_option_string = new_option_string+ "<td>"
                        new_option_string = new_option_string+ "<input type='text' name='field_options" + field_id + "_" + field_option_number + "' value='' class='input_box' size='35'>"
                        new_option_string = new_option_string+ "</td>"
                        new_option_string = new_option_string+ "<td>"
                        new_option_string = new_option_string+ "<input type='button' name='Button' value='Move up' class='form_button' OnClick='Move_option_field(" + field_option_number + ","+ field_id +",0);'> <input type='button' name='Button' value='Move down' class='form_button' OnClick='Move_option_field(" + field_option_number + ","+ field_id +",1);'> <input type='button' name='Submit' value='Remove option' class='form_button' onClick='remove_form_option(" + field_id + "," + field_option_number + ");'>"
                        new_option_string = new_option_string+ "</td>"
                        new_option_string = new_option_string+ "</tr>"
                        new_option_string = new_option_string+ "<tr>"
                        new_option_string = new_option_string+ "<td colspan='3' bgcolor='#f1f1f1' height='1'></td>"
                        new_option_string = new_option_string+ "</tr>"
                        new_option_string = new_option_string+ "</table>"
						new_option_string = new_option_string+ "</div>"

 document.mailform["field_options_count" + field_id].value = field_option_number;
document.getElementById("field_options"+field_id).innerHTML = current_options + new_option_string;

}
/////////#############################################################################
/////////#############################################################################
function remove_form_option(field_id,option_id){

var conf=window.confirm("Are you sure you would like to remove this option?");

if(conf){
document.getElementById("field_options" + field_id + "_" + option_id).innerHTML="";
document.getElementById("field_options" + field_id + "_" + option_id).style.display = "none";
var d = document.getElementById("field_options" + field_id);
var olddiv = document.getElementById("field_options" + field_id + "_" + option_id);
d.removeChild(olddiv);
document.mailform["field_options_count" + field_id].value =(document.mailform["field_options_count" + field_id].value*1)-1
reOrder_Options(field_id,option_id);
}



}

/////////#############################################################################
/////////#############################################################################
function reOrder_Options(field_id,option_id){

		var option_removed = option_id;			
		var option_count = document.mailform["field_options_count" + field_id].value;
		var new_option_string = "";
		use_option = 1
		for (var x = 1; x <= option_count; x++){
	
							
							
							if(use_option==option_id){
							
							use_option= use_option +1
							
							}
							
							
							new_option_string = new_option_string + "<div id='field_options" + field_id + "_" + x + "'>"
								
							new_option_string = new_option_string + "<table width='700' border='0' cellspacing='1' cellpadding='3'>"
							new_option_string = new_option_string+ "<tr>"
							new_option_string = new_option_string+ "<td><b>Option name</b></td>"
							new_option_string = new_option_string+ "<td>"
							new_option_string = new_option_string+ "<input type='text' name='field_options" + field_id + "_" + x + "' value='" + document.mailform["field_options" + field_id + "_" + use_option].value + "' class='input_box' size='35'>"
							new_option_string = new_option_string+ "</td>"
							new_option_string = new_option_string+ "<td>"
							new_option_string = new_option_string+ "<input type='button' name='Button' value='Move up' class='form_button' OnClick='Move_option_field(" + x + ","+ field_id +",0);'> <input type='button' name='Button' value='Move down' class='form_button' OnClick='Move_option_field(" + x + ","+ field_id +",1);'> <input type='button' name='Submit' value='Remove option' class='form_button' onClick='remove_form_option(" + field_id + "," + x + ");'>"
							new_option_string = new_option_string+ "</td>"
							new_option_string = new_option_string+ "</tr>"
							new_option_string = new_option_string+ "<tr>"
							new_option_string = new_option_string+ "<td colspan='3' bgcolor='#f1f1f1' height='1'></td>"
							new_option_string = new_option_string+ "</tr>"
							new_option_string = new_option_string+ "</table>"
							new_option_string = new_option_string+ "</div>"
	
							use_option= use_option +1
		}
		
	document.getElementById("field_options"+field_id).innerHTML =new_option_string;

}
/////////#############################################################################
/////////#############################################################################
function Move_option_field(option_id,field_id,direction){


if(direction=="0"){

/// Move form fields upwards
	if(option_id!=1){

	current_field_name_value = document.mailform["field_options" + field_id + "_" + option_id].value;
	////
	move_field_name_value = document.mailform["field_options" + field_id + "_" + (option_id-1)].value;
	
	document.mailform["field_options" + field_id + "_" + (option_id-1)].value = current_field_name_value;
	////
	document.mailform["field_options" + field_id + "_" + option_id].value = move_field_name_value;


	
	}
}	

if(direction=="1"){

field_count = document.mailform["field_options_count" + field_id].value;

/// Move form fields downwards
	if(option_id!=field_count){
	current_field_name_value = document.mailform["field_options" + field_id + "_" + option_id].value;
	////
	move_field_name_value = document.mailform["field_options" + field_id + "_" + (option_id+1)].value;
	
	document.mailform["field_options" + field_id + "_" + (option_id+1)].value = current_field_name_value;
	////
	document.mailform["field_options" + field_id + "_" + option_id].value = move_field_name_value;
	}
}	





}
/////////#############################################################################
/////////#############################################################################
function Remove_form_field(field_id){

field_count = document.mailform["field_count"].value;


if(field_count*1>1){

		var conf=window.confirm("Are you sure you would like to remove the form field?\nPlease note all options for this form field will also be removed.")
		
		if(conf){
		
		var d = document.getElementById("Form_Fields");
		var olddiv = document.getElementById("FormField"+field_id);
		d.removeChild(olddiv);
		document.mailform["field_count"].value = document.mailform["field_count"].value -1
		reOrder_Fields(field_id);
		}

}
else
{

	alert("you cannot delete this field as it is the only field on your form.");

}


}
/////////#############################################################################
/////////#############################################################################
function reOrder_Fields(field_id){

	var field_removed = field_id;
	var field_count = document.mailform["field_count"].value;
	var fields_string = "";
	var use_option = 1

	for (var i = 1; i <= field_count; i++){
	
		if(use_option==field_id){
		
			use_option = use_option +1
		
		}
	

				fields_string = fields_string + "<div id='FormField" + i + "'>"
				   fields_string = fields_string + "<table width='100%' border='0' cellspacing='1' cellpadding='3'>"
                    fields_string = fields_string + "<tr>"
                      fields_string = fields_string + "<td><b>Field name</b></td>"
                      fields_string = fields_string + "<td><b>Field type</b></td>"
                      fields_string = fields_string + "<td><b>Form field validation type</b></td>"
                      fields_string = fields_string + "<td>&nbsp;</td>"
                    fields_string = fields_string + "</tr>"
                    fields_string = fields_string + "<tr>" 
                      fields_string = fields_string + "<td>"
                        fields_string = fields_string + "<input type='text' name='mailform_field_name" + i + "' size='35' class='input_box' value='" + document.mailform["mailform_field_name" + use_option].value + "'>"
                      fields_string = fields_string + "</td>"
                      fields_string = fields_string + "<td>"
                       fields_string = fields_string + " <select name='mailform_field_type" + i + "' class='input_box'>"
                          fields_string = fields_string + "<option value='0'>Header text</option>"
                         fields_string = fields_string + "<option value='1'>Single line text</option>"
                         fields_string = fields_string + "<option value='2'>Multiline text</option>"
                         fields_string = fields_string + "<option value='3'>Checkbox</option>"
                          fields_string = fields_string + "<option value='4'>Radio buttons</option>"
                         fields_string = fields_string + "<option value='5'>Drop down list</option>"
                       fields_string = fields_string + "</select>"
                      fields_string = fields_string + "</td>"
                      fields_string = fields_string + "<td >" 
                        fields_string = fields_string + "<select name='mailform_field_validation_type" + i + "' class='input_box'>"
                          fields_string = fields_string + "<option value='0'>No validation</option>"
                          fields_string = fields_string + "<option value='1'>Must have a value</option>"
                          fields_string = fields_string + "<option value='2'>Only letters</option>"
                          fields_string = fields_string + "<option value='3'>Only numbers</option>"
                          fields_string = fields_string + "<option value='4'>Email address</option>"
                        fields_string = fields_string + "</select>"
                      fields_string = fields_string + "</td>"
                      fields_string = fields_string + "<td align='right'>"
                        fields_string = fields_string + "<input type='button' name='Button' value='Add option' class='form_button' onClick='add_form_option("+ i + ");'> "
                        fields_string = fields_string + "<input type='button' name='Button' value='Move up' class='form_button' OnClick='Move_form_field("+ i +",0);'> "
                        fields_string = fields_string + "<input type='button' name='Button' value='Move down' class='form_button' OnClick='Move_form_field(" + i + ",1);'> "
                        fields_string = fields_string + "<input type='button' name='Button' value='Remove' class='form_button' OnClick='Remove_form_field("+ i + ");'>"
                      fields_string = fields_string + "</td>"
                    fields_string = fields_string + "</tr>"
                    fields_string = fields_string + "<tr>" 
                      fields_string = fields_string + "<td colspan='4' height='1'  bgcolor='#f1f1f1'></td>"
                    fields_string = fields_string + "</tr>"
				fields_string = fields_string + "</table>"
				fields_string = fields_string + "<input type='hidden' name='field_options_count" + i + "' value='" + document.mailform["field_options_count" + use_option].value + "'>"
				fields_string = fields_string + "<div id='field_options"+ i + "'>"		
		
					//////////// Reorder fields
					var option_count = document.mailform["field_options_count" + use_option].value;
					var new_option_string = "";
			
					for (var x = 1; x <= option_count; x++){
				
										
										
										new_option_string = new_option_string + "<div id='field_options" + i + "_" + x + "'>"
											
										new_option_string = new_option_string + "<table width='700' border='0' cellspacing='1' cellpadding='3'>"
										new_option_string = new_option_string+ "<tr>"
										new_option_string = new_option_string+ "<td><b>Option name</b></td>"
										new_option_string = new_option_string+ "<td>"
										new_option_string = new_option_string+ "<input type='text' name='field_options" + i + "_" + x + "' value='" + document.mailform["field_options" + use_option + "_" + x].value + "' class='input_box' size='35'>"
										new_option_string = new_option_string+ "</td>"
										new_option_string = new_option_string+ "<td>"
										new_option_string = new_option_string+ "<input type='button' name='Button' value='Move up' class='form_button' OnClick='Move_option_field(" + x + ","+ i +",0);'> <input type='button' name='Button' value='Move down' class='form_button' OnClick='Move_option_field(" + x + ","+ i +",1);'> <input type='button' name='Submit' value='Remove option' class='form_button' onClick='remove_form_option(" + i + "," + x + ");'>"
										new_option_string = new_option_string+ "</td>"
										new_option_string = new_option_string+ "</tr>"
										new_option_string = new_option_string+ "<tr>"
										new_option_string = new_option_string+ "<td colspan='3' bgcolor='#f1f1f1' height='1'></td>"
										new_option_string = new_option_string+ "</tr>"
										new_option_string = new_option_string+ "</table>"
										new_option_string = new_option_string+ "</div>"
				
					}
										
					////////////////
					
				fields_string = fields_string + new_option_string +  "</div>"
				fields_string = fields_string + "</div>"
				
				use_option = use_option +1	


	}

document.getElementById("Form_Fields").innerHTML = fields_string;


}

/////////#############################################################################
/////////#############################################################################
function create_mailform(){

// check form has a title
var form_title = document.mailform.mailform_name.value;
if(form_title==""){

	alert("You must enter a title for your form.");
	document.mailform.mailform_name.focus();
	return false;

}

// check form has email address to send to

var form_email_address = document.mailform.mailform_email_address.value;
if(form_email_address==""){

	alert("You must enter a email address to send your form to.");
	document.mailform.mailform_email_address.focus();
	return false;

}
else
{
var valid_email = validate_email(document.mailform.mailform_email_address);

	if(!valid_email){
	
		alert("The email address you have entered appears to be invalid.");
		document.mailform.mailform_email_address.focus();
		return false;
	
	}

}


	document.mailform.ACTION.value="CREATE_FORM";
	document.mailform.submit();



}
/////////#############################################################################
/////////#############################################################################
function Rem_mailform(mailform_idx){

	var conf = window.confirm("Are you sure you want to remove this mailform from your site?");
	
	if(conf){
	
		document.location="/admin/list_mailforms.asp?ACTION=REMOVE_FORM&mailform_idx=" + mailform_idx;
	
	}

}
/////////#############################################################################
/////////#############################################################################
function Show_Hide_Div(div_id)
{
	//alert(node_id);

  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById("" + div_id + "");
  else if( document.all ) // this is the way old msie versions work
      elem = document.all["" + div_id + ""];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers["" + div_id + ""];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  
  
}

/////////#############################################################################
/////////#############################################################################
function Rem_Admin_User(skin_admin_idx){

	var conf = window.confirm("Are you sure you want to remove this admin user from your site?");
	
	if(conf){
	
		document.location="/admin/admin_user_overview.asp?ACTION=DELETE_USER&skin_admin_idx=" + skin_admin_idx;
	
	}

}
/////////#############################################################################
/////////#############################################################################
function Set_Page_Editor_Toggles(){

if(document.page_editor.is_form.checked){

Show_Hide_Div('forms_div');

}

if(document.page_editor.is_file_manager.checked){

Show_Hide_Div('file_manager_div');

}

}
/////////#############################################################################
/////////#############################################################################
function unapproved_page_popup(unapproved_page_idx,navigation_node_idx){

var pop_win = window.open('preview_unapproved_page.asp?unapproved_page_idx='+ unapproved_page_idx +'&navigation_node_idx='+navigation_node_idx,'pop_win','width=750,height=600,scrollbars=yes');
pop_win.moveTo(10,10);

}
/////////#############################################################################
/////////#############################################################################
function approve_page_content(unapproved_page_idx,navigation_node_idx){

var conf=window.confirm("Are you sure you want to approve this page content?");

if(conf){

window.opener.document.location="/admin/site_layout.asp?ACTION=Approve_Page&unapproved_page_idx=" + unapproved_page_idx +'&navigation_node_idx='+navigation_node_idx;
window.close();

}

}
/////////#############################################################################
/////////#############################################################################
function reject_page_content(unapproved_page_idx,navigation_node_idx){

var conf=window.confirm("Are you sure you want to reject this page content?\nPlease note this content will be deleted from the system.");

if(conf){

window.opener.document.location="/admin/site_layout.asp?ACTION=Reject_Page&unapproved_page_idx=" + unapproved_page_idx +'&navigation_node_idx='+navigation_node_idx;
window.close();

}

}
/////////#############################################################################
/////////#############################################################################
function reorder_page(page_idx,direction,navigation_node_idx){


var conf=window.confirm("Are you sure you would like to move this page " + direction + "?");

if(conf){

	Pgurl = "/admin/loading.htm";
	ID_Name = "available_pages"
	ajaxPage(Pgurl,ID_Name);
	Pgurl = "/admin/available_pages.asp?ACTION=REORDER_PAGE&navigation_node_idx=" + navigation_node_idx + "&page_idx=" + page_idx + "&direction=" + direction ;
	ajaxPage(Pgurl,ID_Name);

}

}
/////////#############################################################################
/////////#############################################################################
/////////#############################################################################
/////////#############################################################################
/////////#############################################################################
/////////#############################################################################

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
/////////#############################################################################
/////////#############################################################################

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
/////////#############################################################################
/////////#############################################################################
function InStr(strSearch, charSearchFor)
{
            for (i=0; i < strSearch.length; i++)
            {
			//alert(Mid(strSearch, i, 1));
			
                  if (charSearchFor == Mid(strSearch, i, 1))
                  {
                        return i;
                  }
            }
            return 0;

}
/////////#############################################################################
/////////#############################################################################
function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }

/////////#############################################################################
/////////#############################################################################
function validate_email(field)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {return false}
else {return true}
}
}
/////////#############################################################################
/////////#############################################################################
function getaddress()
	{ 
	var req = null; 
	var post_code = document.getElementById("use_postcode").value.toUpperCase();

	var business_watch_address = document.getElementById("business_watch_address").value;

	if(business_watch_address=="true"){

		document[form_name][business_post_code_field].value=document.getElementById("use_postcode").value.toUpperCase();
	
	}
	else
	{
	
		document[form_name][post_code_field].value=document.getElementById("use_postcode").value.toUpperCase();
		
	}
	
  	var house_number = document.getElementById("house_number").value;
    
	
	if(post_code!=""){
	
			
				var google_maps = false;
			
	
					var ajax_time = new Date();
					var url="/functions/get_postcode_address.asp"
					url = url + "?post_code=" + post_code + "&ajax_time=" + ajax_time;
						
						if (window.XMLHttpRequest)
						{
							req = new XMLHttpRequest();
						} 
						else if (window.ActiveXObject) 
						{
							try {
								req = new ActiveXObject("Msxml2.XMLHTTP");
							} catch (e)
							{
								try {
									req = new ActiveXObject("Microsoft.XMLHTTP");
								} catch (e) {}
							}
					}
						
						req.onreadystatechange = function()
						{ 
							//document.ajax.dyn.value="Wait server...";
							//alert("ready");
							if(req.readyState == 4)
							{
							
							
							
								if(req.status == 200)
								{
									// Good state
									//document.ajax.dyn.value="Received:" + ;
									//alert("wait");	
									//alert("sgsdf");
									var doc = req.responseXML;
									//var doc = req.responseXML;
									var element = doc.getElementsByTagName('AFDPostcodeEverywhere');
									if (element.length > 0)
									{
										var addressElement = doc.getElementsByTagName('Address')
									if (addressElement.length > 0)
									{
										var postcodeElement = doc.getElementsByTagName('Postcode')
										//alert(postcodeElement.item(0).firstChild.data);		
											
											var strPostcode = postcodeElement.item(0).firstChild.data
											
											if ((strPostcode != "Error: Invalid Postcode") && (strPostcode != "Error: Postcode Not Found"))
											{
												//street
												var strStreet = doc.getElementsByTagName('Street').item(0).firstChild.data
												//alert(strStreet);
												document[form_name][addy_1_field].value="";
												if(house_number!=""){
													
													if(business_watch_address=="true"){
													
														document[form_name][business_addy_1_field].value = house_number + " " + strStreet;
													
													}
													else
													{
														
														document[form_name][addy_1_field].value = house_number + " " + strStreet;
												
													}
												}
												else
												{
												
													if(business_watch_address=="true"){

														document[form_name][business_addy_1_field].value = strStreet;
														
													}
													else
													{
														document[form_name][addy_1_field].value = strStreet;
													}	
												}
												//Town
												var strTown = doc.getElementsByTagName('Town').item(0).firstChild.data
												//alert(strTown);
												if(business_watch_address=="true"){

												document[form_name][business_town_field].value = "";
												document[form_name][business_town_field].value = strTown;

												}
												else
												{
												
												document[form_name][town_field].value = "";
												document[form_name][town_field].value = strTown;

												}
				
											//County
												var strCounty = doc.getElementsByTagName('County').item(0).firstChild.data;
												//alert(strCounty);
												if(business_watch_address=="true"){
												
												//Select county
												document[form_name][business_county_field].value = "";
												document[form_name][business_county_field].value = strCounty;
												
												}
												else
												{
												
												document[form_name][county_field].value = "";
												document[form_name][county_field].value = strCounty;
												
												}
												
											// Lat and long
												if(use_lat_lng){
												
												
												if(business_watch_address=="true"){
												
														var strLat = doc.getElementsByTagName('Latitude').item(0).firstChild.data;
														var strLng = doc.getElementsByTagName('Longitude').item(0).firstChild.data;
														document[form_name][business_lat_field].value = strLat;
														document[form_name][business_lng_field].value = strLng;
														
														if(google_maps){
														
														business_map.clearOverlays();
														var center = new GLatLng(strLat, strLng);
														business_map.setCenter(center, 17);
														var business_marker = new GMarker(center, {draggable: true});
														GEvent.addListener(business_marker, "dragstart", function() {  });
														GEvent.addListener(business_marker, "dragend", function() { 
																													
																var marker_location=business_marker.getPoint();
																														
																document[form_name][business_lat_field].value = marker_location.lat();
																document[form_name][business_lng_field].value = marker_location.lng();		
														 });
														business_map.addOverlay(business_marker);
												
														}
														else
														{
														business_map.Clear();
														var center = new VELatLong(strLat, strLng);
														business_map.SetCenterAndZoom(center, 17);
														pixel = business_map.GetCenter();
														business_shape = new VEShape(VEShapeType.Pushpin, business_map.GetCenter());
														icon = "<img src='/admin/images/user_icons/pin1.png'>" 
														business_shape.SetCustomIcon(icon);    
														business_map.AddShape(business_shape);
														}
														
												}
												else
												{
														var strLat = doc.getElementsByTagName('Latitude').item(0).firstChild.data;
														var strLng = doc.getElementsByTagName('Longitude').item(0).firstChild.data;
														document[form_name][lat_field].value = strLat;
														document[form_name][lng_field].value = strLng;
														
														if(google_maps){
														
														map.clearOverlays();
														var center = new GLatLng(strLat, strLng);
														map.setCenter(center, 17);
														var marker = new GMarker(center, {draggable: true});
														GEvent.addListener(marker, "dragstart", function() {  });
														GEvent.addListener(marker, "dragend", function() { 
																													
																var marker_location=marker.getPoint();
																														
																document[form_name][lat_field].value = marker_location.lat();
																document[form_name][lng_field].value = marker_location.lng();		
														 });
														map.addOverlay(marker);
														
														}
														else
														{
														map.Clear();
														var center = new VELatLong(strLat, strLng);
														map.SetCenterAndZoom(center, 17);
														pixel = map.GetCenter();
														shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());
														icon = "<img src='/admin/images/user_icons/pin1.png'>" 
														shape.SetCustomIcon(icon);    
														map.AddShape(shape);

														
														}
														
												}
														
												}
								}
								show_postcode_div(false);
											}
											else
											{
												alert("The Postcode you have entered is not valid please retry.")
												document[form_name][post_code_field].focus();
											}
											
											
									}
									
								}	
							} 
						}; 
						req.open("GET", url, true); 
						req.send(null); 
						
		}
		else
		{
		
			alert("You must enter a postcode to use this facility");
			show_postcode_div(false);
			
				if(business_watch_address=="true"){

						document[form_name][business_post_code_field].focus();
			
				}
				else
				{
					
						document[form_name][post_code_field].focus();
						
				}

			//document[form_name][post_code_field].focus();
		
		}				
	} 
/////////#############################################################################
/////////#############################################################################
function show_postcode_div(show,business_watch){

	 UseX=tempX;
	 UseY=tempY;

	  
	  
	  
	  // catch possible negative values in NS4
	  if (UseX < 0){UseX = 0}
	  if (UseY < 0){UseY = 0}  
	  
	var Postcode_Div = document.getElementById("postcode_div");
	document.getElementById("business_watch_address").value=business_watch;
	

	if(show){

		Postcode_Div.style.top=UseY - 20;
		Postcode_Div.style.left=UseX;
		document.getElementById("house_number").value="";
		
		if(business_watch){
		
		document.getElementById("use_postcode").value=document[form_name][business_post_code_field].value;
		
		}
		else
		{
		document.getElementById("use_postcode").value=document[form_name][post_code_field].value;
		
		}
			
		Postcode_Div.style.visibility = "visible";
		document.getElementById("house_number").focus();
	
	}
	else
	{
	
		Postcode_Div.style.visibility = "hidden";
	
	}
}

/////////#############################################################################
/////////#############################################################################
function show_hide_reg(id){

switch(id)
{
case 1:
	document.getElementById("report_div_0").style.display="none";
	document.getElementById("report_div_progress").style.display="block";
	document.getElementById("report_div_1").style.display="block";
	document.getElementById("report_div_2").style.display="none";
	document.getElementById("report_div_3").style.display="none";
	document.getElementById("report_div_4").style.display="none";

	document.getElementById("step_1").className="step_on";
	document.getElementById("step_2").className="step_off";
	document.getElementById("step_3").className="step_off";

  break;    
case 2:

	
	document.getElementById("report_div_0").style.display="none";
	document.getElementById("report_div_progress").style.display="block";
	document.getElementById("report_div_1").style.display="none";
	document.getElementById("report_div_2").style.display="block";
	document.getElementById("report_div_3").style.display="none";
	document.getElementById("report_div_4").style.display="none";
	
	document.getElementById("step_1").className="step_off";
	document.getElementById("step_2").className="step_on";
	document.getElementById("step_3").className="step_off";
	if(use_bing_maps){
	map.Resize(document.getElementById("map").style.width, document.getElementById("map").style.height)
	}
	else
	{
	
	load();
	
	}
	
  break;
case 3:
	document.getElementById("report_div_0").style.display="none";
	document.getElementById("report_div_progress").style.display="block";
	document.getElementById("report_div_1").style.display="none";
	document.getElementById("report_div_2").style.display="none";
	document.getElementById("report_div_3").style.display="block";
	document.getElementById("report_div_4").style.display="none";
	
	document.getElementById("step_1").className="step_off";
	document.getElementById("step_2").className="step_off";
	document.getElementById("step_3").className="step_on";

	break;
case 4:
	document.getElementById("report_div_0").style.display="none";
	document.getElementById("report_div_progress").style.display="none";
	document.getElementById("report_div_1").style.display="none";
	document.getElementById("report_div_2").style.display="none";
	document.getElementById("report_div_3").style.display="none";
	document.getElementById("report_div_4").style.display="block";
	
	document.getElementById("step_1").className="step_off";
	document.getElementById("step_2").className="step_off";
	document.getElementById("step_3").className="step_off";

	break;
default:
	alert("ERROR");
	break;
}

}
/////////#############################################################################
/////////#############################################################################
function show_sub_user_div(show){

if(show){
  	document.getElementById("sub_user_div").style.top=tempY;
  	document.getElementById("sub_user_div").style.left=tempX-300;
	document.getElementById("sub_user_div").style.display="block";
}
else
{
	document.getElementById("sub_user_div").style.display="none";
}


}
/////////#############################################################################
/////////#############################################################################
function add_sub_user(){

	var user_form = document.sub_user_form;
	var user_idx = user_form.user_idx.value;
	var user_name = user_form.sub_user_name.value;
	var user_address = user_form.sub_user_address.value;
	var user_tel = user_form.sub_user_tel.value;
	var user_email = user_form.sub_user_email.value;
	
	if(user_name==""){
	
		alert("You must enter a name for the person you are registering to your account.");
		document.sub_user_form.sub_user_name.focus();
	
	}
	else
	{
	
		Pgurl = "/functions/add_sub_user.asp?user_idx=" + user_idx + "&user_name=" + user_name + "&user_address=" + user_address + "&user_tel=" + user_tel + "&user_email=" + user_email;
		
		user_form.user_idx.value = "";
		user_form.sub_user_name.value = "";
		user_form.sub_user_address.value = "";
		user_form.sub_user_tel.value = "";
		user_form.sub_user_email.value = "";
		
		ID_Name = "sub_user_list"
		document.getElementById(ID_Name).innerHTML="Updating please wait";
		show_sub_user_div(false);
		ajaxPage(Pgurl,ID_Name);
	
	}

}
/////////#############################################################################
/////////#############################################################################
function noSubmit(e,id){

var keynum;

if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }

if(keynum==13){

	switch(id)
	{
	case 1:
	Find_address();
	return false;
	break;
	case 2:
	getaddress();
	return false;
	break;
	default:
	return false;
	break;
	
}	

}


}

/////////#############################################################################
/////////#############################################################################
function check_report(formObj){


var location_street_name = formObj.location_street_name;
var incident_description = formObj.incident_description;


if(location_street_name.value==""&&formObj.incident_Latitude.value==""&&formObj.incident_Longitude.value==""){
	show_hide_reg(2);
	alert("You must enter the location the incident / intelligence you are reporting occured, if you are unsure of the street name enter the town in which the incident / intelligence occured.");
	document.intelligence_form.location_street_name.focus();
	return false;
	
}

if(incident_description.value==""){
	show_hide_reg(3);
	alert("You must enter a description of the incident / intelligence you are reporting.");
	document.intelligence_form.incident_description.focus();
	return false;
	
}

if(formObj.show_site_owner.checked!=true&&formObj.show_police.checked!=true&&formObj.show_nw.checked!=true){
	
	alert("You must select at least one entity that can see your reported information.");
	return false;

}

}
/////////#############################################################################
/////////#############################################################################
function ajaxUpdate(Pgurl)
  {  
  var xmlHttp;
  try
    {    // Firefox, Opera 8.0+, Safari    
	xmlHttp=new XMLHttpRequest();   
	 }
  catch (e)
    {    // Internet Explorer
	  try
      {      
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	   }
    catch (e)
      {
	       try
        {
		       xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			           }
      catch (e)
        {       
		 alert("Your browser does not support AJAX!");
		  return false; 
		   }
		 }
		}
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        //document.getElementById(ID_Name).innerHTML=xmlHttp.responseText;
        //document.getElementById(ID_Name).innerHTML=xmlHttp.responseText;

        }
      }
    xmlHttp.open("GET",Pgurl,true);
    xmlHttp.send(null);  
	}
/////////#############################################################################
/////////#############################################################################
function conf_alert_remove(){

	var conf = window.confirm("Are you sure you would like to remove this alert?");
	
	if(!conf){
	
		return false;
	
	}

}
/////////#############################################################################
/////////#############################################################################
function update_user_roles(id,user_idx){

	var remove;
	
	if(id.checked){
	
		remove=false;
	
	}
	else
	{
	
		remove=true;
	
	}
	
	var Pgurl = "/functions/select_user_role.asp?company_postion_idx=" + id.value + "&user_idx=" +  user_idx + "&remove=" + remove;
	ajaxUpdate(Pgurl);
	

}

/////////#############################################################################
/////////#############################################################################
function list_user_roles(user_idx,show){


				var sDiv = document.getElementById("current_roles_div");

				sDiv.innerHTML="";

				if(show){

				sDiv.style.top=tempY;
				sDiv.style.left=tempX;
				var Pgurl = "/functions/current_user_roles.asp?user_idx=" + user_idx ;
				ajaxPage(Pgurl,"current_roles_div");

				sDiv.style.visibility = "visible";
			
				}
				else
				{
				sDiv.style.visibility = "hidden";
				}
				


}
/////////#############################################################################
/////////#############################################################################
function scheme_overview(scheme_idx,show){


				var sDiv = document.getElementById("overview_div");

				sDiv.innerHTML="";

				if(show){

				sDiv.style.top=tempY;
				sDiv.style.left=tempX;
				var Pgurl = "/functions/scheme_overview.asp?scheme_idx=" + scheme_idx ;
				ajaxPage(Pgurl,"overview_div");

				sDiv.style.visibility = "visible";
			
				}
				else
				{
				sDiv.style.visibility = "hidden";
				}
				


}
/////////#############################################################################
/////////#############################################################################
function join_scheme(){

	var conf=window.confirm("Are you sure you would like to join this scheme?");
	
	if(!conf){
	
		return false;
	
	}

}
/////////#############################################################################
/////////#############################################################################
function check_user_registration(id){

	var first_name = id.first_name;
	var surname = id.surname;
	var addy_1 = id.addy_1;
	var postcode = id.postcode;
	var work_number = id.work_number;
	var evening_number = id.evening_number;
	var tel = id.tel;
	var mobile = id.mobile;
	var email = id.email;
	var no_email = id.no_email;
	var username = id.username;
	if(eval(id.verify_code)){
	
	var do_verify = true;
	var verify_code = id.verify_code.value;
	var confirm_code = id.confirm_code.value;
	
	}
	else
	{
	var do_verify = false;
	}
	
	if(id.business_watch.value=="true"){
		var is_business_watch = true;
	}
	else
	{
		var is_business_watch = false;
	}

	if(id.password){
	
	var password = id.password;
	
	}
	
	var user_lat = id[lat_field].value;
	var user_lng = id[lng_field].value;
	var tncs = id.tncs;
	

	if(first_name.value==""){
	
		alert("You must enter your first name.");
		first_name.focus();
		return false;
	
	}
	
	if(surname.value==""){
	
		alert("You must enter your surname.");
		surname.focus();
		return false;
	
	}
	
	if(!is_business_watch||is_business_watch&&!id.use_business_address.checked){
	
			if(is_business_watch&&addy_1.value==""&&postcode.value==""){
			
				alert("You must enter your home address or tick the use business address box.");
				addy_1.focus();
				return false;
			
			}
	
			if(addy_1.value==""){
			
				alert("You must enter the first line of your address.");
				addy_1.focus();
				return false;
			
			}
			
			if(postcode.value==""){
			
				alert("You must enter your home postcode.");
				postcode.focus();
				return false;
			
			}
			else
			{
				if(user_lat==""||user_lng==""){
				
				
					alert("You must mark your location on the map to do this either move the red marker to the location of your home or clcik the Get address button the enter your house number and postcode and click Find my address.");
					postcode.focus();
					return false;
				
				}
			
			}
			
	}		
	
	if(work_number.value==""&&evening_number.value==""&&tel.value==""&&mobile.value==""){
	
			alert("You must enter at least one contact telephone number.");
			work_number.focus();
			return false;
	
	}
	else
	{
	
		if(check_phone_number_length(work_number)=="false"){
		
			return false;
		
		}
		
		if(check_phone_number_length(evening_number)=="false"){
		
			return false;
		
		}
		
		if(check_phone_number_length(tel)=="false"){
		
			return false;
		
		}
		
		if(check_phone_number_length(mobile)=="false"){
		
			return false;
		
		}
	
	}
	

	if(email.value==""&&!no_email.checked){
	
			alert("You must enter a email address or check the no email box.");
			email.focus();
			return false;
	
	}
	
	if(email.value!=""&&no_email.checked){
	
			alert("You have entered a email address but you have checked the no email box please review.");
			email.focus();
			return false;
	
	}
	
	if(email.value!=""&&!no_email.checked){
	
		if(!check_email(email)){
	
			alert("You appear to have entered an invalid email address please alter and retry.");
			email.focus();
			return false;
		
		}
		
	}
	
	if(username.value==""){
	
		alert("You must enter a username for your account.");
		username.focus();
		return false;
	
	}
	
	if(id.password){
	
	if(password.value==""){
	
		alert("You must enter a password for your account.");
		password.focus();
		return false;
	
	}
	
	}
	
	if(do_verify){
	
		if(verify_code!=confirm_code){
		
		alert("Please enter the verfication code as shown.");
		id.verify_code.focus();
		return false;
		
		}
	
	
	}
	
	var how_did_you_hear_about_us = id.how_did_you_hear_about_us;
	
	if(eval(how_did_you_hear_about_us)){
	
		if(how_did_you_hear_about_us.value==""){
		
			alert("Please select how you heard about us.");
			how_did_you_hear_about_us.focus();
			return false;
		
		
		}
	
	}
	
	if(tncs){
	
		if(!tncs.checked){
		
		alert("You must agree to the terms and conditions.");
		tncs.focus();
		return false;
		}
	
	}
	
	document.getElementById("submit_button").value="Please wait.."
	document.getElementById("submit_button").disabled = true;
	
	

}
/////////#############################################################################
/////////#############################################################################
function check_email(email_field)
{
	var x = email_field.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)){
	
		return true;
	
	}
	else
	{
	
		return false;
	
	}
}

/////////#############################################################################
/////////#############################################################################
function check_username_availabilty(field){

	var user_name = field.value;
	var user_idx = document[form_name].user_idx.value;
	
	if(user_name!=""){
	
		document.getElementById("user_name_available").className="user_available";
		document.getElementById("user_name_available").innerHTML="Checking user name";
		
		var Pgurl = "/functions/check_available_username.asp?user_idx=" + user_idx + "&user_name=" + user_name;
		
		var USERXML = Load_variable_Xml(Pgurl);
		
		//alert(USERXML.getElementsByTagName("is_available")[0].childNodes[0].nodeValue)
		
		var is_available = USERXML.getElementsByTagName("is_available")[0].childNodes[0].nodeValue;
		
		if(is_available=="False"||is_available=="false"){
		
			alert("User name already in use please alter and retry");
			document.getElementById("user_name_available").className="user_unavailable";
			document.getElementById("user_name_available").innerHTML="User name unavailable";
			field.focus();
			return false;
		
		}
		else
		{
			document.getElementById("user_name_available").className="user_available";
			document.getElementById("user_name_available").innerHTML="User name available";
		}
		
	
	}
	else
	{
		document.getElementById("user_name_available").innerHTML="";
	}
	


}
/////////#############################################################################
/////////#############################################################################
function Load_variable_Xml(Pgurl)
{			
			
	/*		
			try //Internet Explorer
			  {
			  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			  }
			catch(e)
			  {
			  try //Firefox, Mozilla, Opera, etc.
				{
				xmlDoc=document.implementation.createDocument("","",null);
				}
			  catch(e)
				{
				alert(e.message);
				return;
				}
			  }
			 
			xmlDoc.async=false;
			//xmlDoc.load("/functions/hot_spot_xml.asp?Use_Lat=52.98209787372527&Use_lng=-1.1454172432422638&Miles=3");
			xmlDoc.load(Pgurl);
			//if (xmlDoc.parseError.errorCode != 0){
			
			//alert(xmlDoc.parseError.errorCode);
			
			//}

		*/
		    if (window.XMLHttpRequest)
			  {
			  xhttp=new XMLHttpRequest();
			  }
			else // Internet Explorer 5/6
			  {
			  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xhttp.open("GET",Pgurl,false);
			xhttp.send("");
			xmlDoc=xhttp.responseXML; 	
			return xmlDoc;

}
/////////#############################################################################
/////////#############################################################################
function check_registered_email(field){

	var email = field.value;
	var user_idx = document[form_name].user_idx.value;
	var is_admin = document[form_name].admin_screen.value;
	
	if(email!=""&&is_admin!="true"){
	
		var Pgurl = "/functions/check_email_in_use.asp?user_idx=" + user_idx + "&email=" + email;
		
		var USERXML = Load_variable_Xml(Pgurl);
		
		//alert(USERXML.getElementsByTagName("is_available")[0].childNodes[0].nodeValue)
		
		var is_used = USERXML.getElementsByTagName("is_used")[0].childNodes[0].nodeValue;
	
		if(is_used=="True"||is_used=="true"){
		
			var conf = window.confirm("The email address that you have entered is already registered on the system would you like a email reminder of the registered user name and password?");
			
			if(conf){

				var email_user_idx = USERXML.getElementsByTagName("user_idx")[0].childNodes[0].nodeValue;

				//alert(email_user_idx);

				var Pgurl = "/functions/send_reminder_email.asp?user_idx=" + email_user_idx;
				ajaxUpdate(Pgurl);
				alert("An email reminder has been sent please login using the details inside of this email.");
				//document.location = "/"
				document.getElementById("login_username").focus();
			}
			
			return false;
		
		}
	
	}
	


}
/////////#############################################################################
/////////#############################################################################
function Control_chars(field){

	field.value = field.value.replace(/'/g,"");

}

/////////#############################################################################
/////////#############################################################################
function retrive_details(){

	var field = document.getElementById("email_address")
	var random_code = document.getElementById("random_code").value
	var random_code_enter = document.getElementById("random_code_enter")
	var email = field.value;
	var user_idx = 0;
	
	
	if(random_code==random_code_enter.value){
	
			if(email!=""){
			
				var Pgurl = "/functions/check_email_in_use.asp?user_idx=" + user_idx + "&email=" + email;
				
				var USERXML = Load_variable_Xml(Pgurl);
				
				//alert(USERXML.getElementsByTagName("is_available")[0].childNodes[0].nodeValue)
				
				var is_used = USERXML.getElementsByTagName("is_used")[0].childNodes[0].nodeValue;
			
				if(is_used=="True"||is_used=="true"){
				
					//var conf = window.confirm("The email address that you have entered is already registered on the system would you like a email reminder of the registered user name and password?");
					
					//if(conf){
		
						var email_user_idx = USERXML.getElementsByTagName("user_idx")[0].childNodes[0].nodeValue;
		
						//alert(email_user_idx);
		
						var Pgurl = "/functions/send_reminder_email.asp?user_idx=" + email_user_idx;
						ajaxUpdate(Pgurl);
						//alert("An email reminder has been sent please login using the details inside of this email.");
						//document.location = "/"
						//document.getElementById("login_username").focus();
					//}
					
					//return false;
						document.getElementById("recover_details_0").style.display="none";
						document.getElementById("recover_details_1").style.display="block";
				
				}
				else
				{
				
					alert("Email address cannot be found on the system please check and retry.");
					field.focus();
				}
			
			}
			else
			{
			
				alert("You must enter a email address to recover your account details.");
				field.focus();
			
			}
			
		}
		else
		{
		
				alert("Please enter the code as displayed.");
				random_code_enter.focus();
		
		}	
	


}
/////////#############################################################################
/////////#############################################################################
function Make_PDF(user_idx,letter_type){

window.open("/functions/to_pdf.asp?user_idx=" + user_idx + "&letter_type=" + letter_type,"NWIN","status=0,toolbar=0");

}
/////////#############################################################################
/////////#############################################################################
function Manual_activate(user_idx){

	var conf = window.confirm("Are you sure you would like to manually activate this user account?");
	
	if(conf){
	
		document.location="/admin/member_admin.asp?manual_activate=true&user_idx=" + user_idx;

	}
	
}
/////////#############################################################################
/////////#############################################################################
function Delete_user_account(user_idx){

	var conf = window.confirm("Are you sure you would like to delete this user account?");
	
	if(conf){
	
		document.location="/admin/member_admin.asp?delete_account=true&user_idx=" + user_idx + "&redirect_to=" + escape(document.user_form.redirect_to.value);

	}

}
/////////#############################################################################
/////////#############################################################################
function Show_Delivery(show,user_idx){


	var Delivery_Div = document.getElementById("activation_details_div");
	
	

	if(show){

		document.activation_form.user_idx.value=user_idx;
		Delivery_Div.style.top=tempY-170 ;
		Delivery_Div.style.left=tempX-300;
			
		Delivery_Div.style.visibility = "visible";
	
	}
	else
	{
	
		Delivery_Div.style.visibility = "hidden";
	
	}


}
/////////#############################################################################
/////////#############################################################################
function list_internal_pages(layer_idx){

	var DropList = document.getElementById("page_order")
	document.getElementById("navigation_node_idx").value=layer_idx;

	DropList.options.length = 0;

					var y=document.createElement('option');
				  	y.text='-- Updating page list --'
					y.value = '0'
					
				  try
					{
					DropList.add(y,null); // standards compliant
					}
				  catch(ex)
					{
					DropList.add(y); // IE only
					}

	var pgUrl = "/functions/list_site_pages.asp?navigation_node_idx=" + layer_idx;
	var page_list = Load_variable_Xml(pgUrl);
	
		var pages = page_list.getElementsByTagName("Page");
		DropList.options.length = 0;

			for (var i = 0; i < pages.length; i++) {
	
				page_name = pages[i].getElementsByTagName("page_name")[0].childNodes[0].nodeValue;
				list_order = pages[i].getElementsByTagName("list_order")[0].childNodes[0].nodeValue;
				
				//alert(page_name);
				//alert(list_order);
				
               	
					var y=document.createElement('option');
				  	y.text='' + page_name + ''
					y.value = '' + list_order + ''

					
				  try
					{
					DropList.add(y,null); // standards compliant
					}
				  catch(ex)
					{
					DropList.add(y); // IE only
					}


				
			}

}
/////////#############################################################################
/////////#############################################################################
function URLEncode (clearString) {
/*
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
*/

result = clearString.replace(/ /gi, "_");
result = result.replace(/&/gi, "and");
result = result.replace(/'/gi, "");
result = result.replace(/\?/gi, "");

  return result;
}

/////////#############################################################################
/////////#############################################################################
function set_link_type(link_type){

if(link_type=="internal_url"){

document.getElementById("internal_link").style.display = "block";
document.getElementById("external_link").style.display = "none";
document.getElementById("email_link").style.display = "none";
document.getElementById("file_link").style.display = "none";
}

if(link_type=="external_url"){

document.getElementById("internal_link").style.display = "none";
document.getElementById("external_link").style.display = "block";
document.getElementById("email_link").style.display = "none";
document.getElementById("file_link").style.display = "none";
}

if(link_type=="email"){

document.getElementById("internal_link").style.display = "none";
document.getElementById("external_link").style.display = "none";
document.getElementById("email_link").style.display = "block";
document.getElementById("file_link").style.display = "none";
}
if(link_type=="file"){

document.getElementById("internal_link").style.display = "none";
document.getElementById("external_link").style.display = "none";
document.getElementById("email_link").style.display = "none";
document.getElementById("file_link").style.display = "block";
}
}
/////////#############################################################################
/////////#############################################################################
function set_system_alerts_enabled(id,user_idx){

var system_alerts_enabled;

	if(id.checked){
	
		system_alerts_enabled = true;
	
	}
	else
	{
		system_alerts_enabled = false
	}

	var Pgurl = "/functions/set_system_alerts_enabled.asp?user_idx=" + user_idx + "&system_alerts_enabled=" + system_alerts_enabled;
	ajaxUpdate(Pgurl);

}
/////////#############################################################################
/////////#############################################################################
function set_intelligence_options(submit_command){

var conf;


switch(submit_command)
{
case 'REMOVE' :
conf = window.confirm("Are you sure you would like to remove this intelligence from the admin system?");
break;
case 'RELEASE' :
conf = window.confirm("Are you sure you would like to release this intelligence so other users can view it inside of the admin system?");
break;
case 'STORE' :
conf = window.confirm("Are you sure you would like to respond to this intelligence?");
break;
case 'RESERVE' :
conf = window.confirm("Are you sure you would like to reserve this intelligence so you are the only admin user that can view it?");
break;
}

if(conf){
document.response_form.action.value=submit_command;
document.response_form.submit();
}

}
/////////#############################################################################
/////////#############################################################################
function toggle_Schemes(association_id,node_id)
{
	//alert(node_id);

  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById(association_id + "_scheme_users_" + node_id);
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[association_id + "_scheme_users_" + node_id];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[association_id + "_scheme_users_" + node_id];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  
  
  //alert(Right(id.src,20));
  if(Right(document.images(association_id + "_" + node_id + "_toggle").src,19)=="/images/nav_off.png"){
  
	document.images(association_id + "_" + node_id + "_toggle").src="/images/nav_on.png";

	}
  else
  	{
  
  	document.images(association_id + "_" + node_id + "_toggle").src="/images/nav_off.png";
  
  	}
  
}
/////////#############################################################################
/////////#############################################################################
function cascade_update(id){

//alert(id.name);
var check_box;

		if(id.checked){
		
			check_box = true;
			//use_img = imgTrue;
		}
		else
		{
			check_box = false;
			//use_img = imgFalse;
		}
		
		//alert(id.name + " object name");
		
		inputs = document.getElementsByTagName('input'); 
	
		//cycle trough the input fields 
		for(var i=0; i < inputs.length; i++) { 
	
			//check if the input is a checkbox 
			if(inputs[i].getAttribute('type') == 'checkbox') { 
				 
				//alert(inputs[i].name);
				 
				//check if the checkbox is checked 
				if(Left(inputs[i].name,id.name.length+1) == id.name + "_"){ 
					inputs[i].checked=check_box;
					//document.getElementById('checkImage'+i).src=use_img;
					//alert(Left(inputs[i].name,id.name.length)+ " = " + id.name);
				} 
				
			} 
		} 

		

}
/////////#############################################################################
/////////#############################################################################
function Sending_getAllChecked(){

user_send_string = "";
business_type_send_string = "";
sending_list.length = 0;
Beats.length = 0;

var RegularExpression  =  /scheme_+[0-9]+_user/;
var BusinessTypeExpression = /business_type_+[0-9]/;
var have_user = false;
var have_business = false;

		inputs = document.getElementsByTagName('input'); 
	
		//cycle trough the input fields 
		for(var i=0; i < inputs.length; i++) { 
	
			//check if the input is a checkbox 
			if(inputs[i].getAttribute('type') == 'checkbox') { 
				 
				//alert(inputs[i].name);
				 
				//check if the checkbox is checked 
				if(inputs[i].checked){ 
					//alert("checked box");
					
						
						//Check users
						if (inputs[i].name.search(RegularExpression)!=-1)
						{ //if matched
						user_send_string= user_send_string + inputs[i].value + ",";
						have_user = true;
						}
						
						
						//Check business types if business watch
						if(business_watch){
						
							if (inputs[i].name.search(BusinessTypeExpression)!=-1)
							{ //if matched
							business_type_send_string = business_type_send_string + inputs[i].value + ",";
							have_business = true;
							}
						
						}
					
					
				} 
				
			} 
		} 

if(!have_user&&!have_business){

	if(!business_watch){
	
		alert("You must select at least one user to send to.");
		
	}
	else
	{
	
		alert("You must select at least one user or business type to send to.");
		
	}

}
else
{

/// New inclusion to set recipients into a session

var string_length = user_send_string.length;
var send_session_string="";

var x=1 


var ajax_time = new Date();
var Pgurl = "/admin/functions/store_sending_string.asp?clear_string=true&ajax_time" + ajax_time;
ajaxUpdate(Pgurl);


for(var i=0; i < string_length; i++) {

if(i+1>string_length){

endi = i

}
else
{

endi = i + 1

}

send_session_string = send_session_string + String(user_send_string).substring(i,endi);

//alert(send_session_string);

if(x==800){

///Send 1000 chars of a string into the session variable;


var Pgurl = "/admin/functions/store_sending_string.asp?msg_recipients=" + send_session_string + "&ajax_time" + ajax_time;
ajaxUpdate(Pgurl);

send_session_string = "";
x = 0;
}

x++;
				
} 

var Pgurl = "/admin/functions/store_sending_string.asp?msg_recipients=" + send_session_string + "&ajax_time" + ajax_time;
ajaxUpdate(Pgurl);


///////////////////
// User numbers
get_sending_numbers();

	if(have_business){

	Pgurl = "/admin/loading.htm";
	ID_Name = "company_postions"
	ajaxPage(Pgurl,ID_Name);

	show_hide_sending_div(2);

	Pgurl = "/functions/return_valid_company_postions.asp?business_types_string=" + escape(business_type_send_string);
	ajaxPage(Pgurl,ID_Name);
	
	//alert("Show business roles");
		
		
	
	}
	else
	{

		show_hide_sending_div(3);
	
	}
}

}

/////////#############################################################################
/////////#############################################################################
function select_users_in_list(){

var RegularExpression  = new RegExp("scheme_+[0-9]+_user_" + user_idx, "g");
		inputs = document.getElementsByTagName('input'); 
	
		//cycle trough the input fields 
		for(var i=0; i < inputs.length; i++) { 
	
			//check if the input is a checkbox 
			if(inputs[i].getAttribute('type') == 'checkbox') { 
				 
				//alert(inputs[i].name);
				 
				//check if the checkbox is checked 
				if(inputs[i].checked){ 
					//alert("checked box");
					
						
						//alert(inputs[i].name.search(RegularExpression));
						if (inputs[i].name.search(RegularExpression)!=-1)
						{ //if matched
						user_send_string= user_send_string + inputs[i].value + ",";
						have_user = true;
						}

					
					
				} 
				
			} 
		} 

}
/////////#############################################################################
/////////#############################################################################
function show_tncs(){

	window.open("/tncs.asp","tncs","width=400,height=540,scrollbars=yes");

}
/////////#############################################################################
/////////#############################################################################
function toggle_associations(association_id)
{
	//alert(node_id);

  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById("assocation_" + association_id + "_schemes");
  else if( document.all ) // this is the way old msie versions work
      elem = document.all["assocation_" + association_id + "_schemes"];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers["assocation_" + association_id + "_schemes"];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  
  
  //alert(Right(id.src,20));
  if(Right(document.images(association_id + "_toggle").src,19)=="/images/nav_off.png"){
  
	document.images(association_id + "_toggle").src="/images/nav_on.png";

	}
  else
  	{
  
  	document.images(association_id + "_toggle").src="/images/nav_off.png";
  
  	}
  
}

/////////#############################################################################
/////////#############################################################################
function sending_select_all_users(){

var RegularExpression  =  /scheme_+[0-9]+_user/;
var RegularExpression2  =  /[0-9]+_scheme_+[0-9]/;

		inputs = document.getElementsByTagName('input'); 
	
		//cycle trough the input fields 
		for(var i=0; i < inputs.length; i++) { 
	
			//check if the input is a checkbox 
			if(inputs[i].getAttribute('type') == 'checkbox') { 
				 
				//alert(inputs[i].name);
				 
				//check if the checkbox is checked 
				if(!inputs[i].checked){ 
					//alert("checked box");
					
						
						//alert(inputs[i].name.search(RegularExpression));
						if (inputs[i].name.search(RegularExpression)!=-1||inputs[i].name.search(RegularExpression2)!=-1)
						{ //if matched
							inputs[i].checked =  true;
						}

					
					
				} 
				
			} 
		} 

}
/////////#############################################################################
/////////#############################################################################
function sending_select_all_business_types(){

var RegularExpression  =  /business_type_+[0-9]/;

		inputs = document.getElementsByTagName('input'); 
	
		//cycle trough the input fields 
		for(var i=0; i < inputs.length; i++) { 
	
			//check if the input is a checkbox 
			if(inputs[i].getAttribute('type') == 'checkbox') { 
				 
				//alert(inputs[i].name);
				 
				//check if the checkbox is checked 
				if(!inputs[i].checked){ 
					//alert("checked box");
					
						
						//alert(inputs[i].name.search(RegularExpression));
						if (inputs[i].name.search(RegularExpression)!=-1)
						{ //if matched
							inputs[i].checked =  true;
						}

					
					
				} 
				
			} 
		} 

}
/////////#############################################################################
/////////#############################################################################
function select_all_checked_company_postions(){

company_postions_string = "";
var RegularExpression  =  /company_postion_+[0-9]/;
var have_postions=false;
		inputs = document.getElementsByTagName('input'); 
	
		//cycle trough the input fields 
		for(var i=0; i < inputs.length; i++) { 
	
			//check if the input is a checkbox 
			if(inputs[i].getAttribute('type') == 'checkbox') { 
				 
				if(inputs[i].checked){ 
					//alert("checked box");
					
						//Check users
						if (inputs[i].name.search(RegularExpression)!=-1)
						{ //if matched
						company_postions_string = company_postions_string + inputs[i].value + ",";
						have_postions = true;
						}
					
				} 
				
			} 
		} 
		
if(!have_postions){

	alert("You must select at least one company postion to send to.");

}
else
{

	//alert(user_send_string);
	//alert(company_postions_string);
	//alert(business_type_send_string);
	get_all_matching_business_users()
	show_hide_sending_div(3);

}		
		
}		
/////////#############################################################################
/////////#############################################################################
function sending_select_all_company_postions(){

var RegularExpression  =  /company_postion_+[0-9]/;
var have_postions=false;
		inputs = document.getElementsByTagName('input'); 
	
		//cycle trough the input fields 
		for(var i=0; i < inputs.length; i++) { 
	
			//check if the input is a checkbox 
			if(inputs[i].getAttribute('type') == 'checkbox') { 
				 
				if(!inputs[i].checked){ 
					//alert("checked box");
					
						//Check users
						if (inputs[i].name.search(RegularExpression)!=-1)
						{ 
						inputs[i].checked = true;
						}
					
				} 
				
			} 
		} 
}		
/////////#############################################################################
/////////#############################################################################
function confirm_users_to_send_to(){

//alert(user_send_string + " << start user string");
//alert(temp_user_send_string + " << Temp defined area users");

user_send_string = temp_user_send_string;

/// New inclusion to set recipients into a session

var string_length = user_send_string.length;
var send_session_string="";

var x=1 

var ajax_time = new Date();
var Pgurl = "/admin/functions/store_sending_string.asp?clear_string=true&ajax_time" + ajax_time;
ajaxUpdate(Pgurl);


for(var i=0; i < string_length; i++) {

if(i+1>string_length){

endi = i

}
else
{

endi = i + 1

}

send_session_string = send_session_string + String(user_send_string).substring(i,endi);

//alert(send_session_string);

if(x==800){

///Send 1000 chars of a string into the session variable;


var Pgurl = "/admin/functions/store_sending_string.asp?msg_recipients=" + send_session_string + "&ajax_time" + ajax_time;
ajaxUpdate(Pgurl);

send_session_string = "";
x = 0;
}

x++;
				
} 

var Pgurl = "/admin/functions/store_sending_string.asp?msg_recipients=" + send_session_string + "&ajax_time" + ajax_time;
ajaxUpdate(Pgurl);

//alert(user_send_string + " << final users");

show_hide_sending_div(5);

}
/////////#############################################################################
/////////#############################################################################
function voice_preview(word_to_say,use_phonetics){

window.open("/admin/message_functions/process_phonetics.asp?message=" + escape(word_to_say) + "&use_phonetics=" + use_phonetics ,"voice_win","width=1,height=1,scrollbars=no");
}

/////////#############################################################################
/////////#############################################################################
function send_login_reminder(user_idx){	


var conf = window.confirm("Send email login reminder of the registered user name and password?");
			
			if(conf){

				var Pgurl = "/functions/send_reminder_email.asp?user_idx=" + user_idx;
				ajaxUpdate(Pgurl);
				alert("An email reminder has been sent to the user containing their login details.");
				//document.location = "/"
			}
			
}			

/////////#############################################################################
/////////#############################################################################
function resend_activation_email(user_idx){

var conf = window.confirm("Resend email activation email to this user?");
			
			if(conf){

				var Pgurl = "/functions/send_activation_email.asp?user_idx=" + user_idx;
				ajaxUpdate(Pgurl);
				alert("Activation email sent.");
				//document.location = "/"
			}
			

}
/////////#############################################################################
/////////#############################################################################
function check_phone_numbers(id,is_mobile){

var re = new RegExp("^(07)");
  
  if (id.value.match(re)&&!is_mobile) {
  
    	alert("You have added a mobile number to a non mobile field.\nPlease only enter landline numbers.");
		id.value = "";
		id.focus();
  
  } 
  
  if (!id.value.match(re)&&is_mobile&&id.value.length > 1) {
    	alert("You have added non mobile number to a mobile number field.\nPlease only enter mobile numbers.");
		id.value = "";
		id.focus();
  }
  
if(!is_mobile&&id.value!=""){
var re = new RegExp("^(0)");

	/// Check area code
  if (!id.value.match(re)) {
  
    	alert("You must enter your area code when entering your phone number.");
		id.value = "";
		id.focus();
  
  }

}  


}
/////////#############################################################################
/////////#############################################################################
function check_phone_number_length(id){

if(id.value!=""){

	if(id.value.length<11){
    	alert("You appear to have entered an invalid phone number.\nPlease check and retry.");
		id.focus();
		return "false";
	}
	else
	{
	
		return "true";
	
	}

}

}
/////////#############################################################################
/////////#############################################################################
function move_registration_map(id){

	var user_lat = document.user_form[lat_field].value;
	var user_lng = document.user_form[lng_field].value;



	if(user_lat==""&&user_lng==""){
	
		document.getElementById("use_postcode").value = id.value;

					var ajax_time = new Date();
					var url="/functions/get_postcode_address.asp"
					url = url + "?post_code=" + id.value + "&ajax_time=" + ajax_time;
						
						if (window.XMLHttpRequest)
						{
							req = new XMLHttpRequest();
						} 
						else if (window.ActiveXObject) 
						{
							try {
								req = new ActiveXObject("Msxml2.XMLHTTP");
							} catch (e)
							{
								try {
									req = new ActiveXObject("Microsoft.XMLHTTP");
								} catch (e) {}
							}
					}
						
						req.onreadystatechange = function()
						{ 
							//document.ajax.dyn.value="Wait server...";
							//alert("ready");
							if(req.readyState == 4)
							{
							
							
							
								if(req.status == 200)
								{
									// Good state
									//document.ajax.dyn.value="Received:" + ;
									//alert("wait");	
									//alert("sgsdf");
									var doc = req.responseXML;
									//var doc = req.responseXML;
									var element = doc.getElementsByTagName('AFDPostcodeEverywhere');
									if (element.length > 0)
									{
										var addressElement = doc.getElementsByTagName('Address')
									if (addressElement.length > 0)
									{
										var postcodeElement = doc.getElementsByTagName('Postcode')
										//alert(postcodeElement.item(0).firstChild.data);		
											
											var strPostcode = postcodeElement.item(0).firstChild.data
											
											if ((strPostcode != "Error: Invalid Postcode") && (strPostcode != "Error: Postcode Not Found"))
											{
												
												
												
														var strLat = doc.getElementsByTagName('Latitude').item(0).firstChild.data;
														var strLng = doc.getElementsByTagName('Longitude').item(0).firstChild.data;
														document[form_name][lat_field].value = strLat;
														document[form_name][lng_field].value = strLng;
														
														map.clearOverlays();
														var center = new GLatLng(strLat, strLng);
														map.setCenter(center, 17);
														var marker = new GMarker(center, {draggable: true});
														GEvent.addListener(marker, "dragstart", function() {  });
														GEvent.addListener(marker, "dragend", function() { 
																													
																var marker_location=marker.getPoint();
																														
																document[form_name][lat_field].value = marker_location.lat();
																document[form_name][lng_field].value = marker_location.lng();		
														 });
														map.addOverlay(marker);
								}
											}
											else
											{
												alert("The Postcode you have entered is not valid please retry.")
												document[form_name][post_code_field].focus();
											}
											
											
									}
									
								}	
							} 
						}; 
						req.open("GET", url, true); 
						req.send(null); 
		
	}	


}
/////////#############################################################################
/////////#############################################################################
function Check_voice_to_mobile(id){


	if(document.message_settings_form.alert_setup_type.value=="2"&&id.value=="2"){
	
		alert("As calling a mobile number is more expensive, you may not receive some alerts if you request voice alerts to your mobile number.");
	
	}

}
/////////#############################################################################
/////////#############################################################################
function confirm_delete_response(scheme_discussion_idx){

var conf=window.confirm("Are you sure you want to delete this response?");

if(conf){

	document["delete_post_" + scheme_discussion_idx].submit();

}

}
/////////#############################################################################
/////////#############################################################################
function remove_business(business_idx){

	var conf = window.confirm("Are you sure you want to remove this business?\nPlease note this will set all users of this business to be unattached from any business.");

	if(conf){
	
		document.location = "/admin/business_overview.asp?remove_business=true&business_idx=" + business_idx;
	
	}

}
/////////#############################################################################
/////////#############################################################################
function add_intelligence_images(incident_idx){

var image_win = window.open("/functions/add_intelligence_images.asp?incident_idx=" + incident_idx,"image_win","width=500,height=250,scrollbars=false");
image_win.moveTo(5,5);

}
/////////#############################################################################
/////////#############################################################################
function do_business_search(search_text,hide){

if(!hide){

	if(search_text!=""){
	
		document.getElementById("search_div").style.visibility = "visible";
		
		x_pos = getElementLeft('business_name')
		y_pos = getElementTop('business_name')
		
		document.getElementById("search_div").style.top=y_pos + 20;
		document.getElementById("search_div").style.left=x_pos+1;
		
		var ajax_time = new Date()
		
		Pg_Url = "/functions/show_businesses.asp?search_word=" + search_text + "&ajax_time=" + ajax_time;
		ajaxPage(Pg_Url,"search_div");
		
		//alert(document.getElementById("search_div").innerHTML);
		
		//if(document.getElementById("search_div").innerHTML!=""){
		
			//document.getElementById("search_div").style.visibility = "visible";
		
		//}
	
	}
	else
	{
	
		document.getElementById("search_div").style.visibility = "hidden";
	
	}
	
}
else
{

	document.getElementById("search_div").style.visibility = "hidden";


}	

}
/////////#############################################################################
/////////#############################################################################
function getElementLeft(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageX;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}
/////////#############################################################################
/////////#############################################################################
function getElementTop(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageY;
	} else {
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}
}
/////////#############################################################################
/////////#############################################################################
function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

/////////#############################################################################
/////////#############################################################################
function set_business_idx(business_idx){

document.getElementById("search_div").style.visibility = "visible";

var conf = window.confirm("Are you sure you want to register as a employee of " + document.getElementById("business_"+ business_idx + "").innerHTML + "?");

if(conf){

	document.getElementById("search_div").style.visibility = "hidden";

	document.user_form.business_idx.value=business_idx;
	enter_user_details();
}

}
/////////#############################################################################
/////////#############################################################################
function enter_user_details(){



	
	
	if(document.user_form.business_idx.value=="0"||document.user_form.business_idx.value==""){
	
		document.getElementById("business_details").style.display = "block";
		
		if(check_business_details('user_form')){
		
		document.getElementById("business_div").style.display = "none";
		document.getElementById("user_reg_div").style.display = "block";
		

		}
	}
	else
	{
		document.getElementById("business_div").style.display = "none";
		document.getElementById("business_details").style.display = "none";
		document.getElementById("user_reg_div").style.display = "block";
		

	}
	map.Resize(document.getElementById("map").style.width, document.getElementById("map").style.height);
	


}
/////////#############################################################################
/////////#############################################################################
function enter_business_details(){

	document.getElementById("business_div").style.display = "block";
	
	business_map.Resize(document.getElementById("business_map").style.width, document.getElementById("business_map").style.height);

	document.getElementById("user_reg_div").style.display = "none";


}

/////////#############################################################################
/////////#############################################################################
function check_business_details(form_name){

var err = false;

	id = document["" + form_name + ""];
	
	if(id.business_name.value==""){
	
	alert("You must enter a business name.");
	id.business_name.focus();
	return false;
	err = true;
	
	}

	
	if(id.business_addy_1.value==""){
	
	alert("You must enter the first line of your business address.");
	id.business_addy_1.focus();
	return false;
	err = true;
	
	}
	
	if(id.business_postcode.value==""){
	
	alert("You must enter your business postcode.");
	id.business_postcode.focus();
	return false;
	err = true;
	
	}

	if(id.business_Longitude==""||id.business_Latitude==""){
	
	alert("You must mark the location of your business on the map please try to set the marker as close as possible, use the Get address button to initially place the marker.");
	id.business_postcode.focus();
	return false;
	err = true;
	
	}


	if(!err){
	return true;
	}

}
/////////#############################################################################
/////////#############################################################################
function check_unsubscribe_all(){

	var conf=window.confirm("Are you sure you would like to unsubscribe from all Neighbourhood Alert information providers?");

	if(!conf){
	
		return false;
	
	}

}
/////////#############################################################################
/////////#############################################################################
function toggle_association_visibilty(association_idx){


  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById("association_" + association_idx);
  else if( document.all ) // this is the way old msie versions work
      elem = document.all["association_" + association_idx];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers["association_" + association_idx];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';


}
/////////#############################################################################
/////////#############################################################################
function create_user_csv(){

	var conf = window.confirm("Are you sure you want to download a csv of all available users?")
	
	if(conf){
	
		window.open("/admin/functions/create_user_csv.asp","user","width=1,height=1,scrollbars=yes,resizable=yes");
	
	}


}
/////////#############################################################################
/////////#############################################################################
function leave_scheme(user_idx){



	var conf = window.confirm("Are you sure you want to leave this scheme?")
	
	if(conf){
	
		Pgurl="/" + user_idx + "/remove_scheme_member"
		ajaxUpdate(Pgurl);
		window.location.reload()
	
	}


}
/////////#############################################################################
/////////#############################################################################
function Capitalize_String(obj,all_chrs) {
        val = obj.value;
        
		
		if(all_chrs){
		
        	newVal = val.toUpperCase();
		
		}
		else
		{
		
        	newVal = val.substring(0,1).toUpperCase() + val.substring(1,val.length);
        
		}
		
        obj.value = newVal;
}
/////////#############################################################################
/////////#############################################################################
function clear_blur_event(clear){

var elm = document.getElementById("business_name")

if(clear){
elm.onblur = null;
}
else
{
	elm.onblur = function(){
	
	do_business_search('',true);
	
	}
}

}
/////////#############################################################################
/////////#############################################################################
function confirm_delete_beat_area(beat_idx){

	var conf = window.confirm("Are you sure you want to delete this beat area?");
	
	if(conf){
	
		document.location = "/admin/beat_overview.asp?DELETE=true&beat_idx=" + beat_idx;
	
	}

}
/////////#############################################################################
/////////#############################################################################
function sending_select_all_association_users(association_idx){

var RegularExpression  =  /[0-9]+_scheme_+[0-9]/;

		inputs = document.getElementsByTagName('input'); 
	
		//cycle trough the input fields 
		for(var i=0; i < inputs.length; i++) { 
	
			//check if the input is a checkbox 
			if(inputs[i].getAttribute('type') == 'checkbox') { 
				 
				//alert(inputs[i].name);
				 
				//check if the checkbox is checked 
				if(!inputs[i].checked){ 
					//alert("checked box");
					
						
						//alert(inputs[i].name.search(RegularExpression));
						if (inputs[i].name.search(RegularExpression)!=-1)
						{ //if matched
						
							var association_var = inputs[i].name.split("_");
							
							if(association_var[0]==association_idx){
								inputs[i].checked =  true;
							}
						}

					
					
				} 
				
			} 
		} 
		
		if(document.getElementById("assocation_" + association_idx + "_schemes").style.display!="block"){
		toggle_associations(association_idx);
		}

}
/////////#############################################################################
/////////#############################################################################
function get_all_matching_business_users(){

		//alert(company_postions_string);
		//alert(business_type_send_string);

	

		var ajax_time = new Date()

		var Pgurl = "/admin/functions/get_business_users_string.asp?business_type_send_string=" + business_type_send_string + "&company_postions_string=" + company_postions_string + "&ajax_time=" + ajax_time;
		
		ajaxUpdate(Pgurl);


///////////////////
// User numbers
get_sending_numbers();



}
/////////#############################################################################
/////////#############################################################################
function Map_Business_Postcode(business_postcode){

//alert(business_postcode);
if(document[form_name][business_lat_field].value==""&&document[form_name][business_lng_field].value==""&&business_postcode!=""){

document.getElementById("business_watch_address").value = true;
document.getElementById("use_postcode").value = business_postcode;
getaddress();

}	

}
/////////#############################################################################
/////////#############################################################################
function ch_police_team(id){

if(id.neighbourhood_police_team_name.value==""){

	alert("Please enter the name of the policing team.");
	id.neighbourhood_police_team_name.focus();
	return false;

}

if(id.neighbourhood_police_team_email.value==""){

	alert("Please enter an e-mail address for the policing team.");
	id.neighbourhood_police_team_email.focus();
	return false;

}


}
/////////#############################################################################
/////////#############################################################################
