function clickInput()
{
	$("#search").focus(
		function(){
		if($(this).attr("value")=="Enter Keyword")
		{
			$(this).attr("value","");
		}
	});

	$("#search").blur(
		function(){
		if($(this).attr("value")=="")
		{
			$(this).attr("value","Enter Keyword");
		}
	});
}
$(document).ready(function() {clickInput();});


$(document).ready(function() {

	$('#btnSearch').click(function() {
	var searchLink="/Search/searchresults.aspx?k=" + $('#search').attr("value");
	window.location.href=searchLink;
	});
  
	$("#search").keypress(function(event) { 
		if ( event.which == 13 && $('#search').attr("value")!="" )
	 		 $("#btnSearch").click(); 
	 	else
	 		$('#search').focus();
	});
     
  });
  
  
  
  function HideBlankFields() 
	{ 
		var sectorText = document.getElementById('SectorsValue');
		if(trim(sectorText.innerHTML) == "" || sectorText.innerHTML == null)
		{
			document.getElementById('SectorsArea').style.visibility = "hidden";
			document.getElementById('SectorsArea').style.height = 0;
		}
		
		var sectorText = document.getElementById('CapabilitiesValue');
		if(trim(sectorText.innerHTML) == "" || sectorText.innerHTML == null)
		{
			document.getElementById('CapabilitiesArea').style.visibility = "hidden";
			document.getElementById('CapabilitiesArea').style.height = 0;
		}

		var sectorText = document.getElementById('ProjectValue');
		if(trim(sectorText.innerHTML) == "" || sectorText.innerHTML == null)
		{
			document.getElementById('ValueArea').style.visibility = "hidden";
			document.getElementById('ValueArea').style.height = 0;
		}

		var sectorText = document.getElementById('ClientValue');
		if(trim(sectorText.innerHTML) == "" || sectorText.innerHTML == null)
		{
			document.getElementById('ClientArea').style.visibility = "hidden";
			document.getElementById('ClientArea').style.height = 0;
		}

		var sectorText = document.getElementById('PartnersValue');
		if(trim(sectorText.innerHTML) == "" || sectorText.innerHTML == null)
		{
			document.getElementById('PartnersArea').style.visibility = "hidden";
			document.getElementById('PartnersArea').style.height = 0;
		}

		var sectorText = document.getElementById('LocationsValue');
		if(trim(sectorText.innerHTML) == "" || sectorText.innerHTML == null)
		{
			document.getElementById('LocationsArea').style.visibility = "hidden";
			document.getElementById('LocationsArea').style.height = 0;
		}
	}
	
	function trim(stringToTrim) 
	{
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}

	function ltrim(stringToTrim) 
	{
		return stringToTrim.replace(/^\s+/,"");
	}

	function rtrim(stringToTrim) 
	{
		return stringToTrim.replace(/\s+$/,"");
	}

	function getURLParam(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  
	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (
	        aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        break;
	      }
	    }
	  }
	  
	  return unescape(strReturn);
	}

 function makeLNCollapsible()
{ 
/* Make Collapsable Left Navigation and Retain state on redirect */
	$("div.menu-vertical>ul.root>li.static>ul.static").css("display", "none");
    
     var leftnav = $("#sidebar ul li");

	  leftnav.hover(
	  				function(){$(this).children('ul').stop(true, true).slideDown(0);}
	  				,function(){$(this).children('ul').stop(true, true).slideUp(2000);}
	  				);
    
    $("div.menu-vertical>ul.root>li.static>ul").css("display", "none");
    $("div.menu-vertical>ul.root>li.static>ul.static>li.selected").parent().css("display", "block");
}

function ResolutionNavigation()
{ 
	$("ul.dynamic li").mouseover(function(){
	
	if($(this).children("ul").length == 1) {
    var parent = $(this);
    var child_menu = $(this).children("ul");

	  if( $(parent).offset().left + $(parent).width() + $(child_menu).width() > $(window).width() ){
	  		$(child_menu).css("left", "-" + $(child_menu).width() + "px");
          } 
      else{        
         	$(child_menu).css("left", $(parent).width() + "px");      
      	  }    
         }
	});
}


$(document).ready(function() {ResolutionNavigation();});
	
$(document).ready(function() {makeLNCollapsible();});



	function AddEnquiryDetails()
	{
		/*if( $("#contactname").val() == "" ||  $("#contactemail").val() == "" || 
			 $("#contactphone").val() == "" ||  $("#enquirymessage").val() == "")
		{
			alert("Please provide the details");
			return;
		}*/
		//validateCaptcha();
		/*
		if(!CompareRecaptcha("#recaptcha_challenge_field", "#recaptcha_response_field", "The text entered does not match with the shown picture."))
			return;
			*/
		
		if(!BlankFieldValidation("#contactname", "Please provide contact name."))
			return;
		
		if(!BlankFieldValidation("#contactemail", "Please provide email address"))
			return;

		if(!EmailFieldValidation("#contactemail", "Please provide valid email address"))
			return;

		if(!BlankFieldValidation("#contactphone", "Please provide phone number."))
			return;
			
		if(!BlankFieldValidation("#enquirymessage", "Please provide message."))
			return;
		
	    var batch =
	        "<Batch > \
	            <Method ID=\"1\" Cmd=\"New\"> \
	                <Field Name=\"ContactName\">" + $("#contactname").val() + "</Field> \
	                <Field Name=\"ContactPhone\">" + $("#contactemail").val() + "</Field> \
	                <Field Name=\"ContactEmail\">" + $("#contactphone").val() + "</Field> \
			<Field Name=\"EnquiryMessage\">" + $("#enquirymessage").val() + "</Field> \
	            </Method> \
	        </Batch>";
	
	    var soapEnv = " \
			<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:soap='http://schemas.microsoft.com/sharepoint/soap/'> \
	          <soapenv:Body> \
	            <soap:UpdateListItems> \
	              <soap:listName>Enquiry List</soap:listName> \
	              <soap:updates>" + batch + "</soap:updates> \
	            </soap:UpdateListItems> \
	          </soapenv:Body> \
	        </soapenv:Envelope>";
	
	    $.ajax({
	        url: "/_vti_bin/lists.asmx",
	        beforeSend: function(xhr) {
	xhr.setRequestHeader("SOAPAction",
	"http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
	        },
	        type: "POST",
	        dataType: "xml",
	        data: soapEnv,
	        complete: SuccessMessage,
	        contentType: "text/xml; charset=\"utf-8\""
	    });
	}
	
	
	function validateCaptcha()
{

	challengeField = $("input#recaptcha_challenge_field").val();
	responseField = $("input#recaptcha_response_field").val();
	//console.log(challengeField);
	//console.log(responseField);
	//return false;
	alert('hi');
	var urlString = "http://www.google.com/recaptcha/api/verify";
	var var_private_key="6LcdEckSAAAAAJEflbmEb946n1QQBhCi0uykymJM";
	var params = encodeURI("remoteip=" + $("#userIp").val() +"&privatekey=" + var_private_key + "&challenge=" + Recaptcha.get_challenge() + "&response=" + Recaptcha.get_response());
	alert($("#userIp").val());
	params = encodeURI(params);
	
  						
  						
	$.getJSON(urlString + "?" + params,function(data){
     //really no need to do anything here, we're just posting data
     //but this will output success
     alert(data);
    });
	
	alert( html );
	if(html == "success") {
		//Add the Action to the Form
		$("form").attr("action", "http://action/to/the/form_handler");
		//Indicate a Successful Captcha
		$("#captchaStatus").html("Success!");
		// Uncomment the following line in your application
		return true;
	} else {
		$("#captchaStatus").html("The security code you entered did not match. Please try again.");
		Recaptcha.reload();
		return false;
	}
}
	
	
	function SuccessMessage()
	{
		alert("Thank you " + $("#contactname").val() + ". Our executive will contact you shortly.")
	        $("#contactname").val("");
	        $("#contactemail").val("");
	        $("#contactphone").val("");
	        $("#enquirymessage").val("");
	}
	
	function BlankFieldValidation(field, msg)
	{
		if( $(field).val() == "")
		{
			alert(msg);
			$(field).focus();
			return false;
		}
		else
			return true;
	}
	
	function CompareRecaptcha(challange_field,response_filed, msg)
	{
	var ch=Recaptcha.get_challenge();
	var res=Recaptcha.get_response();

		alert(ch);
		alert(res);
		if( $(challange_field).val() != $(response_filed).val())
		{
			alert(msg);
			Recaptcha.reload();
			$(response_filed).focus();
			return false;
		}
		else
			return true;
	}
	
	function EmailFieldValidation(field, msg)
	{
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; 
		var emailaddressVal = $(field).val();
		if(!emailReg.test(emailaddressVal))
		{
			alert(msg);
			$(field).focus();
			return false;
		}
		else
			return true;
	}

 
 function GetNewsHref()
 {
 	var d = new Date();
	var href="/News/Pages/default.aspx?my=" + d.getFullYear();
	window.location.href=href;
}

 function GetAllNewsHref()
 {
	var my=	getURLParam("my");
	var myhref=window.location.href;
	var href="";
	if(myhref.indexOf("Didactic")>0)
	{
		href="/Training/Didactic/News/Pages/allnews.aspx?my=" + my;
	}
	else
	{
		href="/News/Pages/allnews.aspx?my=" + my;
	}
	window.location.href=href;
}

 function GetAllCaseStudiesHref()
 {
 	var t1=	getURLParam("t1");
 	var t2=	getURLParam("t2");
 	var t3=	getURLParam("t3");
 		
	var href="/SuccessStories/Pages/allcasestudies.aspx";
	window.location.href=href;
}

  
