 $(document).ready(function(){
	prepareLinks();
    socialmedia();
    qtip();
});


function prepareLinks()

{
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++)
	{
		if (links[i].getAttribute("className"))
		{
			if (links[i].getAttribute("classname") == "external")
			{
				if (links[i].getAttribute('title') == '')
					links[i].setAttribute("title","(opens in a new window)");
				links[i].onclick = function()
				{
					OpenNewWindow(this.getAttribute('href'));
					return false;
				}
			}
			else if (links[i].getAttribute('classname').substring(0,6) == 'popup_')
			{
				links[i].setAttribute('title','this is a popup');
				links[i].onclick = function()
				{
					popup(50,50,this.getAttribute('classname').split('_')[1],this.getAttribute('classname').split('_')[2],this.getAttribute('href'));
					return false;
				}
			}
			else
			{
	//			var linkText  = links[i].firstChild.nodeValue;
	//			links[i].setAttribute('title','this is a link to '+linkText);
			}
		}
		else if (links[i].getAttribute("class"))
		{
			if (links[i].getAttribute("class"))
			{
				if (links[i].getAttribute("class") == "external") 
				{
					if (links[i].getAttribute('title') == '')
						links[i].setAttribute("title","(opens in a new window)");
					links[i].onclick = function()
					{
						OpenNewWindow(this.getAttribute('href'));
						return false;
					}
				}
				else if (links[i].getAttribute('class').substring(0,6) == 'popup_')
				{
					links[i].setAttribute('title','this is a popup');
					links[i].onclick = function()
					{
						popup(50,50,this.getAttribute('class').split('_')[1],this.getAttribute('class').split('_')[2],this.getAttribute('href'));
						return false;
					}
				}
			}
		}
  	}
}

function popup(x,y,w,h,fn)
{
	NewWindow = window.open(fn,'descr','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=0,scrollbars=1,resizable=1,copyhistory=no,width='+w+',height='+h+', top='+y+',left='+x)
}


function OpenNewWindow(fn)
{
	NewWindow = window.open(fn)
}


function checkAnswerFields()
{
	var name = document.forms[0].name.value;
	var Title = document.forms[0].Title.value;
	var Charity = document.forms[0].Charity.value;
	var regNo = document.forms[0].regNo.value;
	var phone = document.forms[0].phone.value;
	var Email = document.forms[0].Email.value;
	var vf = true;
	var msg = '';
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (filter.test(Email))
		vf = true;
	else
	{
		msg = 'Sorry it looks like you have entered an invalid email address.\n';
		vf = false;
	}
	if (name.length == 0)
	{
		msg = msg + 'You have forgotten to fill in your name.\n';
		vf = false;
	}
	if (Title.length == 0)
	{
		msg = msg + 'You have forgotten to fill in your Title.\n';
		vf = false;
	}
	if (Charity.length == 0)
	{
		msg = msg + 'You have forgotten to fill in your Charity.\n';
		vf = false;
	}
	if (regNo.length == 0)
	{
		msg = msg + 'You have forgotten to fill in your regNo.\n';
		vf = false;
	}
	if (phone.length == 0)
	{
		msg = msg + 'You have forgotten to fill in your phone.\n';
		vf = false;
	}

	if (msg != '')
		alert(msg);
	return vf;
}

function removeSubMenux()
{
	//REMOVE THE SUB NAVIGATION FOR JAVASCRIPT ENABLED BROWSERS
	var javaContainer = document.getElementById('javaContainer');
	var noneJava = document.getElementById('noneJava');
	if (noneJava != null)
		javaContainer.removeChild(noneJava);
}

//adding social media thanks to http://www.hardcode.nl/archives_139/article_420-social-media-icon-script
function socialmedia(){
    drawSocialLinks = function(oContainers){

        	var l,i,socialList = [], socialHtm='';
        	var t = $('h1').eq(0).text();   /*  adjust this to select the title of your article */
        	var u = document.location.href;  /*  this selects the link to your article */
        	//var u = "WERWERWR";  /*  this selects the link to your article */
    		var iconDirectory = '/img/icons/socialmedia/'; /* this is the director containing your icons */

    		var socialMedia = [
    			{linkText: 'LinkedIn', icon:'linkedin.png',href:'http://www.linkedin.com/shareArticle?mini=true&url='+u+'&title='+t},
                {linkText: 'Digg', icon:'digg.png',href:'http://digg.com/submit?phase=2&url='+u+'&title='+t},
    			{linkText: 'Stumbleupon', icon:'stumbleupon.png',href:'http://www.stumbleupon.com/submit?url='+u},
    			{linkText: 'Google', icon:'google.png',href:'http://www.google.com/bookmarks/mark?op=edit&bkmk='+u},
    			{linkText: 'Twitter', icon:'twitter.png',href:'http://twitter.com/home?status='+u},
    			{linkText: 'Facebook', icon:'facebook.png',href:'http://www.facebook.com/share.php?u='+u}
    		];

    		l = socialMedia.length;
    		for (i=0; i<l;i++){
    		//	socialList.push('<li><a href="'+socialMedia[i].href+'" title="'+socialMedia[i].linkText+'"><img src ="'+this.webRoot+iconDirectory+socialMedia[i].icon+'" alt="'+socialMedia[i].linkText+'" /></a></li>');
    			socialList.push('<li><a href="'+socialMedia[i].href+'" title="'+socialMedia[i].linkText+'" class="external"><img src ="'+iconDirectory+socialMedia[i].icon+'" alt="'+socialMedia[i].linkText+'" width="26px" /></a></li>');
    		}
    		socialHtm = '<ul>'+socialList.join("\n")+'</ul>';
    		oContainers.append('<div id="share_this" class="gen_box"><h2>Share This Page:</h2>'+socialHtm+'<p title="These sites allow you to tag, share and store links across the internet." class="tool_tip_trigger_click">What is this?</p></div>');
        }
        drawSocialLinks($('#content_padding').not('#homepage #content_padding'));
};


function qtip(){

$('.tool_tip_trigger_hover[title]').qtip({
   show: 'mouseover',
   hide: 'mouseout',
     position: {
        corner: {
           target: 'topLeft',
           tooltip: 'bottomLeft'
        }
     },
     style: {
        name: 'dark', // Inherit from preset style
        //width: 340,
        //padding: 5,
        tip: 'bottomLeft',
        border: {
           width: 1,
           radius: 5
        }
     }
})

$('.tool_tip_trigger_click[title]').qtip({
    content: {
        title: {
          text: '&nbsp;',
          button: '<span onclick=\"return false\">Close this box</span>'
        }
      },
     style: {
        name: 'dark', // Inherit from preset style
        width: 340,
        padding: 5,
        tip: 'bottomLeft',
        border: {
           width: 1,
           radius: 5
        }
     },
     position: {
        corner: {
           target: 'topLeft',
           tooltip: 'bottomLeft'
        }
     },
     show: {
            when: { event: 'click' },
            solo: true
           },
     hide: { when: { event: 'unfocus' } }

})
};







