//------------------------------------------------------------------------------------
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 to validate email
//-----------------------------------------------------------------------------------
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));
}

function refreshCaptcha(imgid)
{
	var img = new Image();
	img.src = 'captcha/show_captcha.php?hash='+parseInt(Math.random() * 10000000000);
	document.getElementById(imgid).src = img.src;
}


$(document).ready(function(){
		$('#project_thumbs > div > img').css('opacity', '0.7');

		$('#thumb1').hover(function(){
			$('#thumb1 > img').animate({opacity: '1'}, 400);
			$('#btmthumb1').animate({top: '58px', height: '32px'}, 400);
		},
		function(){
			$('#thumb1 > img').animate({opacity: '0.7'}, 400);
			$('#btmthumb1').animate({top: '90px', height: '0px'}, 400);
		}
		);

		$('#thumb2').hover(function(){
			$('#thumb2 > img').animate({opacity: '1'}, 400);
			$('#btmthumb2').animate({top: '58px', height: '32px'}, 400);
		},
		function(){
			$('#thumb2 > img').animate({opacity: '0.7'}, 400);
			$('#btmthumb2').animate({top: '90px', height: '0px'}, 400);
		}
		);

		$('#thumb3').hover(function(){
			$('#thumb3 > img').animate({opacity: '1'}, 400);
			$('#btmthumb3').animate({top: '58px', height: '32px'}, 400);
		},
		function(){
			$('#thumb3 > img').animate({opacity: '0.7'}, 400);
			$('#btmthumb3').animate({top: '90px', height: '0px'}, 400);
		}
		);

		$('#thumb4').hover(function(){
			$('#thumb4 > img').animate({opacity: '1'}, 400);
			$('#btmthumb4').animate({top: '58px', height: '32px'}, 400);
		},
		function(){
			$('#thumb4 > img').animate({opacity: '0.7'}, 400);
			$('#btmthumb4').animate({top: '90px', height: '0px'}, 400);
		}
		);

		$('#thumb5').hover(function(){
			$('#thumb5 > img').animate({opacity: '1'}, 400);
			$('#btmthumb5').animate({top: '58px', height: '32px'}, 400);
		},
		function(){
			$('#thumb5 > img').animate({opacity: '0.7'}, 400);
			$('#btmthumb5').animate({top: '90px', height: '0px'}, 400);
		}
		);

	});
function showAnimation(imagePath)
{
	$('#lrg_img').animate({opacity: '0'}, 400, function(){
			$('#loader').css('display', 'block');
			$('#lrg_img').attr('src', imagePath);
			$('#lrg_img').load(function(){
				$('#loader').css('display', 'none');
				$('#lrg_img').animate({opacity: '1.0'}, 400);
			});
		});
}
function AJAX()
{
	//Private variables (properties)
	var __httpRequest = null;
	var __callbackFunc = null;

	//Private method: __createHttpRequest()
	var __createHttpRequest = function()
	{
		if(window.XMLHttpRequest) //Mozilla, Safari etc
		{
			__httpRequest = new XMLHttpRequest();
		}
		else if(window.ActiveXObject) //IE
		{
			try
			{
				__httpRequest = new ActiveXObject("MSXML2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					__httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					//Do whatever you need to do here
					alert("AJAX cannot be used with your browser!");
				}
			}
		}
	}

	//Private method: __createParameters(arr)
	var __createParameters = function(arr)
	{
		var parameters = ""; //Initialize
		for(x in arr)
		{
			var pName = encodeURIComponent(x);
			var pVal = encodeURIComponent(arr[x]);
			parameters = (parameters == "")?pName+'='+pVal:parameters+'&'+pName+'='+pVal;
		}
		return parameters;
	}

	//Private method: __handleResponse()
	var __handleResponse = function()
	{
		if(__httpRequest.readyState == 4)
		{
			__callbackFunc(__httpRequest.responseText);
		}
	}

	//Public method: getRequest(url, arrParam, callbackFunc)
	this.getRequest = function(url, arrParam, callbackFunc)
	{
		__createHttpRequest() //recreate ajax object to defeat cache problem in IE
		__callbackFunc = callbackFunc;
		if(__httpRequest)
		{
			var param = __createParameters(arrParam);
			__httpRequest.onreadystatechange = __handleResponse;
			//Include a random number to defeat IE cache problem
			__httpRequest.open('GET', url+"?ajaxhash="+Math.random()+'&'+param, true);
			__httpRequest.send(null)
		}
	}

	//Public method: postRequest()
	this.postRequest = function(url, arrParam, callbackFunc)
	{
		__createHttpRequest() //recreate ajax object to defeat cache problem in IE
		__callbackFunc = callbackFunc;
		if (__httpRequest)
		{
			var param = __createParameters(arrParam);
			__httpRequest.onreadystatechange = __handleResponse;
			__httpRequest.open('POST', url, true);
			__httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
			__httpRequest.setRequestHeader("Content-length", param.length);
			__httpRequest.setRequestHeader("Connection", "close");
			__httpRequest.send(param);
		}
	}
}

/* Function to Change Testimonials*/
function changeTestimonial()
{
	numTestimonials = parseInt(document.getElementById('num_testimonials').value); // Get the total number of testimonials.
	oldTestimonial = parseInt(document.getElementById('old_testimonial').value);
	newTestimonial = (parseInt(oldTestimonial + 1) >= numTestimonials)?1:(oldTestimonial + 1); // Get the newTestimonial value by increasing the counter.
	$('#testimonial_blk_'+oldTestimonial).fadeOut(400, function(){
		$('#testimonial_blk_'+newTestimonial).fadeIn(400);
		$('#old_testimonial')[0].value = newTestimonial;
	});
}

function displayMessage(fieldName, alertMessage)
{
	document.getElementById('error_'+ fieldName).innerHTML = alertMessage;
	eval('obj.'+fieldName+'.className = "tboxe"');
}

function clearMessage(fieldName)
{
	document.getElementById('error_'+ fieldName).innerHTML = '';
	eval('obj.'+fieldName+'.className = "tbox"');
}
