function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}

function trimFields()
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z][a-z0-9_\.\-]*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*\.[a-z]+$/i;
	return(email_pat.test(tmpStr));
}
//===============================================
//==========  Refresh Captcha  ==================
//===============================================
function refreshCaptcha(imgid)
{
	var newimg = new Image();
	newimg.src = 'inc/captcha/captcha.php?hash='+parseInt(Math.random() * 10000000000);
	//alert(newimg.src);
	newimg.onload = function(){document.getElementById(imgid).src = newimg.src;}
}
function chkYoutubeURL(tmpStr)
{
	var url_pat = /^(http:\/\/www\.youtube\.com\/watch\?v=)?[a-z0-9]{11,11}$/i;
	return(url_pat.test(tmpStr));
}
//------------------------------------------------------------------------------------
// Function to open in a new window
//------------------------------------------------------------------------------------
function newWindow(pageName, w, h)
{
	w = w || '570';
	h = h || '550';
	window.open(pageName, '', 'width='+w+',height='+h+',toolbar=0,menubar=0,location=0,left=25,top=25');
}
// Open a popup window at center of screen
function popWin(page, win_width, win_height)
{
	var scr_width = screen.width;
	var scr_height = screen.height;
	var coord_left = Math.floor((scr_width - win_width) / 2);
	var coord_top = Math.floor((scr_height - win_height) / 2);
	window.open(page, 'popwin', "width="+win_width+",height="+win_height+",toolbar=0,menubar=0,toolbar=0,menubar=0,location=0,left="+coord_left+",top="+coord_top+",scrollbars=1");
}
function slideSearch()
{
	$('#search_slide').animate({height: '72px'}, 100);
}
$(document).click(function() {
	$('#search_slide').animate({height: '0px'}, 100);
});

$(document).ready(function(){
	$('#search_slide').animate({height: '0px'}, 100);
	$('#frmSearch').submit(function(){
		return false;
	});
	$('#enquiry_text').keypress(function(e)
	{
		// if the key pressed is the enter key
		if (e.keyCode == 13)
		{
			submitForm();
			return false;
		}
	});
	$('#img_send').click(function()
	{
		submitForm();
	});

	$('#search_slide').click(function(e) {
		e.stopPropagation();
	});
	$('#send_service').click(function(e) {
		e.stopPropagation();
	});

});

function submitForm()
{
	if($('#enquiry_text').val() == ''|| $('#enquiry_text').val()=='Enter Enquiry')
	{
		alert('Please enter  enquiry field.');
		$('#enquiry_text')[0].focus();
		return false;
	}else if($('#phone_text').val()==""||$('#phone_text').val()=='Enter Mobile Phone Number'){
		alert('Please Enter your mobile phone number');
		$('#phone_text')[0].focus();
		return false;
	}
	else
	{
		$.ajax({
			type: 'POST',
			url: 'send_enquiry.php',
			data: 'text='+$('#enquiry_text').val()+'&phone='+$('#phone_text').val(),
			success: function(retVal) {
				alert('Your QuickTexts has been sent!');
				//$('#enquiry_text')[0].value = 'Enter enquiry';
				$('#search_slide').animate({height: '0px'}, 100);
				return false;
			}
		});
	}
}
