var iconData = {};
var officeLayer = [  {} ];
var timed = "";
var filters = "";
var filterc = "";

var xmlHttp;
function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}


function showDIV(Country) {	

	document.getElementById("mapoverlay").style.height = "355px";
	document.getElementById("mapoverlay").innerHTML = "<div align=center><img src='/images/loading.gif' width=32 height=32 border=0 alt='loading...' style='margin:30px 0 50px 0'></div>";

	createXMLHttpRequest();	
	var url = "/distributor_display09.php?act=list&country=" + Country + "&ts="+ new Date().getTime();
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = callback1;
	xmlHttp.send(null);
	
}

function hideDIV(Country) {	

	document.getElementById("mapoverlay").style.height = "1px";
	document.getElementById("mapoverlay").innerHTML = "";

}


function showGoogle(country,lati,lngi,filterinc) {

	timed = "";
	filters = filterinc;
		
	getJS(country);

	lat = lati;
	lng = lngi;
	filterc = country;

	document.getElementById("googleOverlay").style.width = "751px";
	document.getElementById("googleOverlay").style.height = "460px";
	document.getElementById("googleOverlay").innerHTML = "<div class='map_container'><div class='map_topleft'>&nbsp;</div><div class='map_top'>&nbsp;</div><div class='map_topright'><a href='javascript:void();' onclick='hideGoogle();return false;'><img src='/images/map_close.png' width='26' height='26' alt='Close Map' border='0'></a></div><div class='map_center'><div class='map_sideleft'>&nbsp;</div><div class='map_middle'><div align=center><img src='/images/loading.gif' width=32 height=32 border=0 alt='loading...' style='margin:30px 0 50px 0'></div></div><div class='map_sideright'>&nbsp;</div></div><div class='map_botleft'>&nbsp;</div><div class='map_bot'>&nbsp;</div><div class='map_botright'>&nbsp;</div></div>";
	
	setTimeout('google_display()',1000);

}

function hub_display() {

	createXMLHttpRequest();	
	var url = "/distributor_hub09.php?country=" + filterc + "&filters=" + filters + "&ts="+ new Date().getTime();
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = callback1;
	xmlHttp.send(null);
	
}

function google_display() {

	if (timed != "Y") {
	createXMLHttpRequest();	
	var url = "/distributor_google09.php?country=" + filterc + "&filters=" + filters + "&ts="+ new Date().getTime();
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = callback2;
	xmlHttp.send(null);
	}
	
}

function hideGoogle() {	

	timed = "Y";
	document.getElementById("mapoverlay").style.width = "1px";
	document.getElementById("mapoverlay").style.height = "1px";
	document.getElementById("mapoverlay").innerHTML = "";
	document.getElementById("googleOverlay").style.width = "1px";
	document.getElementById("googleOverlay").style.height = "1px";
	document.getElementById("googleOverlay").innerHTML = "";
	
}

function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 


function callback1() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			document.getElementById("mapoverlay").innerHTML = xmlHttp.responseText;
		}
	}
}

function callback2() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
		
			var response = xmlHttp.responseText;
			document.getElementById("googleOverlay").innerHTML =  response;
			
			load_maps();
			
		}
	}
}

function getJS(country) {

	var mytag = document.getElementsByTagName('body')[0];//or 'head' 
	var script= document.createElement('script'); 
	script.type = 'text/javascript'; 
	script.setAttribute('language', 'javascript'); 
	var timestamp = new Date();             
	script.src = "/distributor_flags09.php?country=" + country + "&filters=" + filters + "&timestamp="+(timestamp*1); 
	mytag.appendChild(script); 
			
}

function filter_google(country) {

	timed = "";
	filters = "";

	filters = "H|";
	if (document.forms['filterform'].L.checked == true) {
	filters = filters + "L|";
	}
	if (document.forms['filterform'].C.checked == true) {
	filters = filters + "C|";
	}
	if (document.forms['filterform'].D.checked == true) {
	filters = filters + "D|";
	}
	if (document.forms['filterform'].M.checked == true) {
	filters = filters + "M|";
	}
	
	getJS(country);

	document.getElementById("googleOverlay").innerHTML = "<div class='map_container'><div class='map_topleft'>&nbsp;</div><div class='map_top'>&nbsp;</div><div class='map_topright'><a href='javascript:void();' onclick='hideGoogle();return false;'><img src='/images/map_close.png' width='26' height='26' alt='Close Map' border='0'></a></div><div class='map_center'><div class='map_sideleft'>&nbsp;</div><div class='map_middle'><div align=center><img src='/images/loading.gif' width=32 height=32 border=0 alt='loading...' style='margin:30px 0 50px 0'></div></div><div class='map_sideright'>&nbsp;</div></div><div class='map_botleft'>&nbsp;</div><div class='map_bot'>&nbsp;</div><div class='map_botright'>&nbsp;</div></div>";
	
	
	
	setTimeout('google_display()',1000);

}


function display_buy(country,lati,lngi) {

	timed = "";
	filters = "H|L|C|D|M|";

	getJS(country);

	lat = lati;
	lng = lngi;
	filterc = country;

	document.getElementById("googleOverlay").style.width = "751px";
	document.getElementById("googleOverlay").style.height = "460px";
	document.getElementById("googleOverlay").innerHTML = "<div class='map_container'><div class='map_topleft'>&nbsp;</div><div class='map_top'>&nbsp;</div><div class='map_topright'><a href='javascript:void();' onclick='hideGoogle();return false;'><img src='/images/map_close.png' width='26' height='26' alt='Close Map' border='0'></a></div><div class='map_center'><div class='map_sideleft'>&nbsp;</div><div class='map_middle'><div align=center><img src='/images/loading.gif' width=32 height=32 border=0 alt='loading...' style='margin:30px 0 50px 0'></div></div><div class='map_sideright'>&nbsp;</div></div><div class='map_botleft'>&nbsp;</div><div class='map_bot'>&nbsp;</div><div class='map_botright'>&nbsp;</div></div>";
	
	document.getElementById("mapoverlay").style.width = "220px";
	document.getElementById("mapoverlay").style.height = "800px";
	document.getElementById("mapoverlay").innerHTML = "<div align='center'><img src='/images/loading.gif' width=32 height=32 border=0 alt='loading...' style='margin:30px 0 50px 0'></div>";
	
	hub_display();
	setTimeout('google_display()',1000);

}


function email_form(country,cid) {

	createXMLHttpRequest();	
	var url = "/distributor_email09.php?cid=" + cid + "&country=" + country + "&ts="+ new Date().getTime();
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = callback1;
	xmlHttp.send(null);

}

function email_send(country,cid) {

   var errorflag;
   var errormsg;
   
  errormsg ="The following details were not supplied.\n";
  errormsg = errormsg +"Please enter: \n\n";
  if (document.forms['emailform'].contact.value =="") {
 errorflag = 1;
  errormsg = errormsg +"Your Name or Contact Name for any correspondence.\n";
  }
   if (document.forms['emailform'].email.value =="") {
 errorflag = 1;
  errormsg = errormsg +"The email address you could be contacted on should it be required.\n";
  }
   if (document.forms['emailform'].phone.value =="") {
 errorflag = 1;
  errormsg = errormsg +"The phone number(s) you could be contacted on should it be required.\n";
  }
  if (document.forms['emailform'].enquiry.value =="") {
 errorflag = 1;
  errormsg = errormsg +"Your comments or enquiry you wish to make to the stockist/distributor selected.\n";
  }
 if (errorflag == 1) {
 alert(errormsg);
  return false;
 } else {
 
 	company = document.forms['emailform'].company.value;
 	contact = document.forms['emailform'].contact.value;
 	email = document.forms['emailform'].email.value;
	phone = document.forms['emailform'].phone.value;
	enquiry = document.forms['emailform'].enquiry.value;
	IDS = document.forms['emailform'].ID.value;
	
	createXMLHttpRequest();	
	var url = "/distributor_email09.php?act=post&cid=" + cid + "&ID=" + IDS + "&country=" + country + "&contact=" + urlencode(contact) + "&company=" + urlencode(company) + "&phone=" + urlencode(phone) + "&email=" + urlencode(email) + "&enquiry=" + urlencode(enquiry) + "&ts="+ new Date().getTime();
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = callback1;
	xmlHttp.send(null);
 }

}


function urlencode(str) {
str = escape(str);
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}