// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
function doIt(what)
{
	window.open(what,'location','width=520,height=350,toolbar=no,statusbar=no');
}
// Checking data fields
function sendMail(mainUrl) 
{

	var qstr;
	var response;
	var ajaxUrl = mainUrl+"send_mail.php";
	
	var name = document.getElementById('contactFormName');
	var email = document.getElementById('contactFormMail');
	// var phone = document.getElementById('phone');
	//var type = document.getElementById('type');
	var securityCode = document.getElementById('contactFormChanclas');
	var message = document.getElementById('contactFormQuery');
			
	qstr = 'email=' + escape(email.value);
	qstr = qstr + '&name=' + escape(name.value);
	//qstr = qstr + '&phone=' + escape(phone.value);
	//qstr = qstr + '&type=' + escape(type.value);
	qstr = qstr + '&securityCode=' + escape(securityCode.value);
	qstr = qstr + '&message=' + escape(message.value);
	
	response = Ajax.post(ajaxUrl,qstr);
	
	
	document.getElementById('error').innerHTML = response;
	
	return true;	
}

function places(mainUrl)
{
	var selCity		= escape(document.getElementById('locations').value);
	var ajaxUrl 	= mainUrl+"get_locations.php";
	var selIndex,selValue,selBox,selText,postText;
		selBox 		= document.getElementById('locations');
		selIndex	= selBox.selectedIndex;
		
		//selBox.selectedIndex = 0;
		if(selIndex != 0) {
			selValue	= selBox.options[selIndex].value;
			selText	= selBox.options[selIndex].text;

			// get form data
			postText = "locations="+selValue;
		
		
			// send to validation
			document.getElementById('locationData').innerHTML = 'Obradjujem podatke ...';
			
			response = Ajax.post(ajaxUrl,postText);
            
			document.getElementById('locationData').innerHTML = response;
				
		} 
	return true;	
}
function changePicture(where,what)
{
	document.getElementById(where).src = what;
}
