var xmlHttp

function toggle(id, trigger) {
	var el = eval('document.getElementById("'+id+'")');
	var el2 = eval('document.getElementById("'+ trigger + '")');
	el.disabled = !(el2.checked);
}
	
function highLight(id, color) {
	var fields = document.getElementById(id);
	fields.bgColor = color;
}

function checkForm(fields, h_color, n_color) {
	var errors = false;
	for (el in fields) {
		var val = document.getElementById(el);
		val.style.backgroundColor = h_color;
	}
	return FALSE;
}


function viewLink(p, id) {
	if (id != '') {	
		html = "<a href='http://"+p+".farmersandfleamarkets.ca/market/?city="+id+"' style='padding:3px 20px;";
		html = html + "background:#0a1870;color:#FFF;text-decoration:none'> Click here to view list of markets</a>";
	} else {
		html = "<a href='http://"+p+".farmersandfleamarkets.ca/market/' style='padding:3px 20px;";
		html = html + "background:#0a1870;color:#FFF;text-decoration:none'> Click here to view list of markets</a>";
	}
	document.getElementById('viewDiv').innerHTML=html;
}

function dynLoad(str, id) {
	//alert(str+ ", "+ id);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	if (id == '') {
		document.getElementById('cityDiv').innerHTML=" ";	
		document.getElementById('viewDiv').innerHTML=" ";
		return;
	}
	
	if (str == 'city') {
		var url="cities.php";
		url=url+"?id="+id;
		url=url+"&str="+str;
		url=url+"&sid="+Math.random();
		
		html = "<a href='http://"+id+".farmersandfleamarkets.ca/market/' style='padding:3px 20px;background:#0a1870;color:#FFF;text-decoration:none'> Click here to view list of markets</a>";
		
		xmlHttp.onreadystatechange=function() {
			if (xmlHttp.readyState==4) {
				document.getElementById('cityDiv').innerHTML=xmlHttp.responseText;
				document.getElementById('viewDiv').innerHTML=html;
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function stateChanged() { 
	if (xmlHttp.readyState==4) { 
		document.getElementById("dynamicContent").innerHTML=xmlHttp.responseText;
	}
}


function GetXmlHttpObject() {
var xmlHttp=null;
try {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



