// JavaScript Document
function say_my_town(elem)
{
	//alert('this is my town ' + elem.value);
	var response = function(oXML){
		if(oXML.responseText){
	    	document.getElementById('whisper_town').style.display = 'block';
			document.getElementById('whisper_town').innerHTML = oXML.responseText;
		}else{
			document.getElementById('whisper_town').style.display = 'none';
		}
	}
	ax = new XHConn();
	ax.connect('components/com_comprofiler/say_my_town.php', 'POST', 'l=' + elem.value, response);
}
function say_my_province(elem)
{
	var response = function(oXML){
	    if(oXML.responseText){
	    	document.getElementById('whisper_prov').style.display = 'block';
			document.getElementById('whisper_prov').innerHTML = oXML.responseText;
		}else{
			document.getElementById('whisper_prov').style.display = 'none';
		}
	}
	ax = new XHConn();
	ax.connect('components/com_comprofiler/say_my_province.php', 'POST', 'l=' + elem.value, response);
}



var cbDefaultFieldBackground;
function submitbutton(mfrm) {
	var me = mfrm.elements;
	var errorMSG = '';
	var iserror=0;
	// loop through all input elements in form
	for (var i=0; i < me.length; i++) {
		// check if element is mandatory; here mosReq="1"
		if (me[i].getAttribute('mosReq') == 1) {
			if (me[i].type == 'radio' || me[i].type == 'checkbox') {
				var rOptions = me[me[i].getAttribute('name')];
				var rChecked = 0;
				if(rOptions.length > 1) {
					for (var r=0; r < rOptions.length; r++) {
						if (rOptions[r].checked) {
							rChecked=1;
						}
					}
				} else {
					if (me[i].checked) {
						rChecked=1;
					}
				}
				if(rChecked==0) {
					// add up all error messages
					errorMSG += me[i].getAttribute('mosLabel') + ' : <?php echo unhtmlentities(_UE_REQUIRED_ERROR); ?>\n';
					// notify user by changing background color, in this case to red
					if (cbDefaultFieldBackground === undefined) cbDefaultFieldBackground = ((me[i].style.getPropertyValue) ? me[i].style.getPropertyValue("background") : me[i].style.background);
					me[i].style.background = "red";
					iserror=1;
				} else if (me[i].style.background.slice(0,3)=="red") me[i].style.background = cbDefaultFieldBackground;
			}
			if (me[i].value == '') {
				// add up all error messages
				errorMSG += me[i].getAttribute('mosLabel') + ' : <?php echo unhtmlentities(_UE_REQUIRED_ERROR); ?>\n';
				// notify user by changing background color, in this case to red
				if (cbDefaultFieldBackground === undefined) cbDefaultFieldBackground = ((me[i].style.getPropertyValue) ? me[i].style.getPropertyValue("background") : me[i].style.background);
				me[i].style.background = "red";
				iserror=1;
			} else if ((me[i].getAttribute('mosLength')) && (me[i].value.length > me[i].getAttribute('mosLength'))) {
				errorMSG += me[i].getAttribute('mosLabel') + " <?php echo unhtmlentities(_UE_LENGTH_ERROR); ?> " + (me[i].value.length - me[i].getAttribute('mosLength')) + " <?php echo unhtmlentities(_UE_CHARACTERS); ?>\n";
				// notify user by changing background color, in this case to red
				if (cbDefaultFieldBackground === undefined) cbDefaultFieldBackground = ((me[i].style.getPropertyValue) ? me[i].style.getPropertyValue("background") : me[i].style.background);
				me[i].style.background = "red";
				iserror=1;
			} else if (me[i].style.background.slice(0,3)=="red") me[i].style.background = cbDefaultFieldBackground;
		}
	}	
	if(iserror==1) {
		alert(errorMSG);
		return false;
	} else {
		return true;
	}
}


	function createRequestObject() {
			var ro;
			var browser = navigator.appName;
			if(browser == "Microsoft Internet Explorer"){
				ro = new ActiveXObject("Microsoft.XMLHTTP");
			}else{
				ro = new XMLHttpRequest();
			}
			return ro;
		}
		
		var http = createRequestObject();
		var identity;
		function pop_town_profile(value,id) {	
			arr = value.split('|');
			codprov = arr[1]; 
				
			
			var action = "components/com_comprofiler/pop_town.php?prov=" + codprov;
			
			
			document.getElementById(id).innerHTML='Please wait';
			identity = id;
			http.open('GET', action, true);
			http.onreadystatechange = handleResponseToLoadComboBoxItem;
			http.send(null);
		}
		
		function pop_town_profile_multilpe(value,id) {	
			arr = value.split('|');
			codprov = arr[1]; 
				
			
			var action = "components/com_comprofiler/pop_town_multiple.php?prov=" + codprov;
			
			
			document.getElementById(id).innerHTML='Please wait';
			identity = id;
			http.open('GET', action, true);
			http.onreadystatechange = handleResponseToLoadComboBoxItem;
			http.send(null);
		}
		
		function handleResponseToLoadComboBoxItem() {
			if(http.readyState == 4){
				var response = http.responseText;
				if(http.status >= 400 && http.status <600)
					{
						 document.getElementById(identity).innerHTML =  '<span style="color:#FF0000">Item is Not Found</span>';			
					}	
				else{	
					 document.getElementById(identity).innerHTML = response;
				}
			}   
		}