	function ClearSearchForm(txtSearch)
	{
		if ( txtSearch.value != null && txtSearch.value == 'Keyword search')
		{
			txtSearch.value = '';
		}
		
	}

   function CheckKey(event) {
      if (event.keyCode == 13) {
         return ActNowSearch();
      }
   }


   function CheckKeyLogin(event) {
      if (event.keyCode == 13) {
         return fn_login();
      }
   }

	
	function ActNowSearch()
	{
	   var txtSearch = document.getElementById('searchtxt').value;
   
	   if( txtSearch != null && txtSearch != 'Keyword search')
	   {
	      top.location.href='/Find.aspx?searchtxt=' + txtSearch;
	   }
	   return false;
	}
	
	function PrintFormat()
	{
      var url = location.href;
      var seperator = url.indexOf('?') > -1 ? '&' : '?';
      window.open(url + seperator + "print=true", "print", "", "");
      return false;
	}
	
   function searchFilter(filter_value)
   {
      var args = parseQueryString();
      var searchtxt = args['searchtxt'];
      if(searchtxt.length > 0) {
         var seperator = filter_value.indexOf('?') > -1 ? '&' : '?';
         location.href = filter_value + seperator + "searchtxt=" + searchtxt;
      }
   }
   
   function relationPopup(id, type, client_id)
   {
      var relation_list = document.getElementById(client_id).value;
      window.open('/Admin/Relations.aspx?id=' + id + '&type=' + type + '&popup=true&client_id=' + client_id + '&relation_list=' + relation_list, 'rel' + id, 'height=600,width=400,resizable=yes,scrollbars=yes,toolbar=no,status=no');

      //Open New Window for popup, adding 'popup=true' to querystring will use the simpler HeaderPrint.ascx template.
      //window.open('/Admin/Relations.aspx?id=' + id + '&type=' + type + '&popup=true&client_id=' + client_id, 'rel' + id, 'height=600,width=400,resizable=yes,scrollbars=yes,toolbar=no,status=no');
   }
   
   function textFormattingPopup()
   {
      //Open New Window for popup, adding 'popup=true' to querystring will use the simpler HeaderPrint.ascx template.
      window.open('/TextFormatting.aspx?popup=true', 'textFormatting', 'height=600,width=500,resizable=yes,scrollbars=yes,toolbar=no,status=no');
   }

   function emailPopup(sMemberName)
   {
		var url = '/EmailMember.aspx?popup=true&member=' + sMemberName;
		window.open(url, 'emailMember', 'height=600,width=500,resizable=yes,scrollbars=yes,toolbar=no,status=no');
   }
   
	function calculatAge(ddlDay, ddlMonth, ddlYear)
	{
		try
		{
			var strDOB		= "";
			var dtDOB		= new Date();
			var	dtNow		= new Date();
			var intDiff		= 0;
			
			strDOB	+= document.getElementById(ddlDay).options[document.getElementById(ddlDay).selectedIndex].value;
			strDOB	+= "/";
			strDOB	+= document.getElementById(ddlMonth).options[document.getElementById(ddlMonth).selectedIndex].value;
			strDOB	+= "/";
			strDOB	+= document.getElementById(ddlYear).options[document.getElementById(ddlYear).selectedIndex].value;
			
			if(validateSetDateFormat(strDOB))
			{
				var DOBDateFormat = "d/M/yyyy";
				
				dtDOB.setTime(Date.parse(strDOB));

				dtDOB.setTime(getDateFromFormat(strDOB, DOBDateFormat));
				
				var intDiff  = dtNow.getUTCFullYear() - dtDOB.getUTCFullYear();
				
				if	(
						(dtNow.getUTCMonth() == dtDOB.getUTCMonth() && dtNow.getDate() < dtDOB.getDate())
					||	(dtNow.getUTCMonth() < dtDOB.getUTCMonth())
					)
				{
					intDiff -= 1
				}
				
				intDiff = (intDiff < 0) ? 0 : intDiff;
				
				return confirm("So you're " + intDiff + " years old?");
			}
		}
		catch(e)
		{
			alert(e.message);
			return true;
		}
	}
	
///will validate if a date string is in format dd/MM/yyyy
function validateSetDateFormat(strDate)
{
	try
	{
		var isDebugMode = true;
	
		if(strDate.split("/").length == 3)
		{
			var dateNow = new Date();
			var s = strDate.split("/")
			
			///will remove any start 0 value
			s[0] = (s[0].substring(0,1) == "0") ? s[0].substring(1) : s[0];
			s[1] = (s[1].substring(0,1) == "0") ? s[1].substring(1) : s[1];
			s[2] = (s[2].substring(0,1) == "0") ? s[2].substring(1) : s[2];
			
			
			if	(
					!isNaN(parseInt(s[0])) 
				&&	parseInt(s[0])			> 0
				&&	parseInt(s[0])			<= 31
				&&	!isNaN(parseInt(s[1]))
				&&	parseInt(s[1])			> 0 
				&&	parseInt(s[1])			<= 12 
				&&	!isNaN(parseInt(s[2]))
				)
			{
				var d = parseInt(s[0]); 
				var m = parseInt(s[1]);
				var y = parseInt(s[2]);
				///Month doesn't have 31 days!
				if ((m == 4 || m == 6 || m == 9 || m == 11) && d == 31) 
				{if(isDebugMode){alert("error 4")}; return false;}
				/// check for february 29th
				if (m == 2) 
				{ 
					var isleap = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));
					if (d> 29 || (d == 29 && !isleap)) 
					{if(isDebugMode){alert("error 3")}; return false;}
				}
				///VALID DATE
				return true;
			}
			else
			{if(isDebugMode){alert("error 2")}; return false;}
		}
		else
		{if(isDebugMode){alert("error 1")}; return false;}
	}
	catch(e)
	{alert(e.message); return false;}
}


function fn_login()
{
	try
	{	
		///get a deal by id
		
		var strUserName = document.getElementById("txtQLUserName").value;
		var strPassword = document.getElementById("txtQLPassword").value;
		
		var url = "/service/actnow.asmx/login?strUserName="+ strUserName +"&strPassword="+ strPassword +"";
		var conn = new initHTTPXML();
		var fn_action = function()
		{
			if(conn.getXmlHttp.readyState == conn.ReadyState.Complete)
			{
				if(conn.getXmlHttp.status ==  conn.HttpStatus.OK)
				{
					var XMLdoc = conn.getXmlHttp.responseXML.documentElement;
					
					if(XMLdoc.firstChild.nodeValue == "true")
					{
						document.location = "/Members/" + strUserName.split(" ").join("_") + ".aspx";
					}
					else
					{
						alert("Invalid Login");
					}
				}
			}
		}		

		///load request
		requestHTTPXML(fn_action, conn.getXmlHttp, url); 

	}
	catch(e)
	{
		alert(e.message);
	}

}

function fn_ToggleActNow(elementToShow)
{
	try
	{
		///get obj from id
		var objTarget = document.getElementById(elementToShow);
		///check so obj and parent obj exists
		if	(
				objTarget								!= null
			&&	objTarget.parentNode					!= null
			&&	objTarget.parentNode.parentNode			!= null
			&&	objTarget.parentNode.parentNode.tagName	== "UL"
			)
		{
			var objUL = objTarget.parentNode.parentNode;
			///loop all ul in parent ul container
			for(var i = 0; objUL.getElementsByTagName("UL").length > i; i++)
			{
				///is element equal to target id
				if(objUL.getElementsByTagName("UL")[i].id == objTarget.id)
				{
					///open but only if there in any child in it
					if(objUL.getElementsByTagName("UL")[i].getElementsByTagName("LI").length > 0)
					{
						objUL.getElementsByTagName("UL")[i].style.display = "block";
					}
					else
					{
						objUL.getElementsByTagName("UL")[i].style.display = "none";
					}
				}
				else
				{
					///close
					objUL.getElementsByTagName("UL")[i].style.display = "none";
				}
			}
		}
	}
	catch(e)
	{
		///error
		alert(e.message);
	}
}

   function newsletterPopup()
   {
      //Open New Window for popup, adding 'popup=true' to querystring will use the simpler HeaderPrint.ascx template.
      window.open('/NewsletterSubscriber.aspx', 'NewsletterSubscriber', 'height=415,width=375,resizable=no,scrollbars=no,toolbar=no,status=no');
   }
   
   
function fn_userBlogScrollPos()
{
	try
	{
		var oForm = document.getElementById("Form1")
		if(oForm != null)
		{
			if(oForm.action.indexOf("#blog") == -1)
			{
				oForm.action += "#blog";
			}
		}
	}
	catch(e)
	{
		alert(e.message)
	}
}
