var ROOT = "";
var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);


	
$(function() {
	
	
	// open external links in new window
	$('a[rel*=external]').click( function() {
        window.open(this.href);
        return false;
    });
	
	isSkypeInstalled();
	
	$("#searchlibrarypanel form .keyword, #search .keyword, .editprofile #description").conditionalClear();

	
});

function newWindow(pageURL, name, w, h)
{
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	var targetWin = window.open (pageURL, name, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 

function lightboxDoc(href)
{
	if(href == "close")
	{
		$("#lightbox_doc").hide();
		$("#overlay").fadeOut("fast");
		
		return false;
	}
	
	if(!$("#overlay").length)
	{
		var overlay = '<div id="overlay"></div><div id="lightbox_doc"><a class="closeb" href="#" onclick="return lightboxDoc(\'close\');"><span>Close</span></a>' +
				'<h2 class="h">Warning and indicators to accompany a financial promotion</h2>' +
				'<p class="h">(including a financial promotion about a fund)</p>' +
				'<div class="scroll">' +
				'	<div class="content">' +
				'<p>You have requested access to private documents containing information of a confidential nature belonging to the Entrepreneur relating to the Project (Confidential Information).  In order to proceed, you must accept this confidentiality agreement.  You agree:</p>' +
				'<ul>' +
				'<li>(a) to hold the Confidential Information in confidence and not to disclose or permit it to be made available to any person, firm or company (except your professional advisers, other potential equity or finance providers and any other person to whom the Entrepreneur has granted access) without the Entrepreneur\'s prior consent;</li>' +
				'<li>(b) only to use the Confidential Information for the purpose of considering making an investment in the Entrepreneur\'s company ;</li>' +
				'<li>(c) to ensure that each person to whom disclosure of Confidential Information is made by you is fully aware in advance of the confidential nature of the information and your obligations under this agreement and that in the case of other potential equity or finance providers, each such person gives an undertaking in respect of the Confidential Information, in the terms of this agreement;</li>' +
				'<li>(d) upon written demand from the Entrepreneur or FiSMA either to return the Confidential Information and any copies of it or to confirm in writing that, save as required by law, regulation, professional standards or compliance requirements, it has been destroyed.  You may keep your own notes on the Confidential Information.</li>' +
				'</ul>' +
				'<p>The obligations above shall not apply to any information or Confidential Information:</p>' +
				'<ul>' +
				'<li>(a) which at the time of its disclosure is in the public domain;</li>' +
				'<li>(b) which after disclosure comes into the public domain for any reason except your failure to comply with the terms of this agreement;</li>' +
				'<li>(c) which is disclosed by the Entrepreneur or the Entrepreneur\'s directors, employees or advisers on a non-confidential basis;</li>' +
				'<li>(d) which was lawfully in your possession prior to such disclosure;</li>' +
				'<li>(e) which is subsequently received by you from a third party without obligations of confidentiality;  or</li>' +
				'<li>(f) which you are required to disclose by law or any regulatory or government authority.</li>' +
				'</ul>' +
				'<p>This agreement shall be governed by and construed in accordance with English law and the parties irrevocably submit to the exclusive jurisdiction of the Courts of England and Wales.</p>' +				
				'	</div>' +
				'</div>' +
				'<p class="dl"><a class="button accept" href="#"><span>Accept</span></a> <a class="button decline" href="#" onclick="return lightboxDoc(\'close\');"><span>Decline</span></a></p>' +
				'</div>';
				
		$("body").append(overlay);
	}
	
	$("#overlay").fadeIn("slow");
	$("#lightbox_doc a.accept").attr("href", href);	
	$("#lightbox_doc").show();
	
	return false;
	
}

function isSkypeInstalled()
{
	if ($.browser.safari || $.browser.opera) {
		return true;
	} else if ($.browser.msie) {
		try {
			if (new ActiveXObject("Skype.Detection")) return true;
		} catch(e) { }
	} else {
		if (typeof(navigator.mimeTypes["application/x-skype"]) == "object") {
			return true;
		}
	}

	/*$('a[href^="skype:"]').click(function() {
		return false;
	});*/

	return false;
}

function updateSkypeStatus()
{
  var ids = "";
  $(".skypestatus").each(function() {
	if(this.id)
	    ids = ids + this.id + ",";  
  });
                  
					
  $.get(ROOT + "/admin/ajax/skype/status.php", {username:ids}, function(data){	
  		if(data)
  		{
  		  $.each(data.usernames, function(i, n){	
					$("#" + i).removeClass("online offline");
					$("#" + i).addClass(n);
				});          
  		}
  	}, "json");
    
}

(function($)
{
	$.fn.conditionalClear = function()
	{
		var elements = this;
		return(
			elements.each(function() {				
				var el = $(this);
				var def = el.attr("title");
				if(def)
				{
					el.val(def).focus(function()
					{
						if(el.val().replace(' (*)','') == def)
						{
							el.val("");
						}
						el.blur(function()
						{
							if(el.val() == "")
							{
								el.val(def);
							}
						});
					});
				}
			})
		);
	}
})(jQuery)
