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));
}
function NewWindow(pageName)
{
	window.open(pageName, '', 'width=520,height=550,toolbar=0,menubar=0,location=0,left=25,top=25');
}

//------------------------------------------------------------------------------------
//Checks URL against pattern
//------------------------------------------------------------------------------------
function chkURL(tmpStr)
{
	var url_pat = /^(http|https|ftp):\/\/([\w-]+\.)+[\w-]+(\/[\w-\.\/?%&amp;,=#@\/:]*)?/;
	return(url_pat.test(tmpStr));
}


$(document).ready(function(){
  $('#social_link_small li').css("opacity", "0.35");
  $('#social_link_small li').hover(function(){
	   $(this).css("opacity", "0.99");
	  },
	  function () {
		  $(this).css("opacity", "0.35");
		  });

  $('.project_blk img').css("opacity", "0.65");
  $('.project_blk img').hover(function(){
	   $(this).css("opacity", "0.99");
	  },
	  function () {
		  $(this).css("opacity", "0.65");
		  });

  $('#project_thumb_block img').css("opacity", "0.65");
  $('#project_thumb_block img').hover(function(){
	   $(this).css("opacity", "0.99");
	  },
	  function () {
		  $(this).css("opacity", "0.65");
		  });
});

//------------------------------------------------------------------//
//Generic AJAX object for all types of HTTP get/post work			//
//Author: Debabrata Kar (dk.webtenet@gmail.com)						//
//Usage:															//
//	var ajax = new AJAX();											//
//	var arrParam = new Array();										//
//	arrParam['name1'] = 'value1';									//
//	arrParam['name2'] = 'value2';									//
//	arrParam['name3'] = 'value3';									//
//	ajax.getRequest(url, arrParam, responseHandler);				//
//	OR																//
//	ajax.postRequest(url, arrParam, responseHandler);				//
//																	//
//	NOTE: You do not need to escape() or encodeURIComponent() the	//
//	parameter names or values. AJAX will do it on its own.			//
//	You need to define responseHandler() function that will handle	//
//	response back from the server, be it XML or anything else		//
//------------------------------------------------------------------//
//The AJAX object
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 validateSubscribe()
{
	var obj = document.getElementById('frmSubscriber');
	if(obj.subscriber_email.value == '' || obj.subscriber_email.value == 'Enter your email address here')
	{
		alert("Please enter your Email Address.");
		obj.subscriber_email.focus();
		return;
	}
	if(!chkEmail(obj.subscriber_email.value))
	{
		alert("Please enter a valid Email Address.");
		obj.subscriber_email.focus();
		obj.subscriber_email.select();
		return;
	}
	params = 'email='+ obj.subscriber_email.value;
	params+= '&hash='+Math.floor(Math.random()*11);
	 $.ajax({
	   type: "GET",
	   data: params,
	   url: "subscribe_newsletter.php",
	   success: function(retVal){
			switch(retVal)
			{

				case "SUCCESS":
					subscribeMsg = 'Thank you for subscribing to the 9Synergy Monthly Newsletter.\nPlease check your email and click the link given in your mail to confirm your subscription.';
					break;
				case "EXISTING":
					subscribeMsg = 'You are already subscribed for the 9Synergy Monthly Newsletter.';
					break;
				case "NEED_ACTIVATION":
					subscribeMsg = 'You need to activate your subscription.\nWe are sending you another mail incase you have deleted our mail received earlier.\nPlease click on the link specified in your mail to activate your subscription.';
					break;
				default:
					subscribeMsg = "You have been disabled for Newsletter Subscription. Please contact Administator";
					break;
			}
			alert(subscribeMsg);
			obj.subscriber_email.value = "Enter your email address here";
	   }
   });
}
