window.onload = prepareLinks;

function prepareLinks()
{
	$('a.external').click(function()
	{
	     window.open(this.href);
    	 return false;
    });
    
	$("a[class^='popup_']").click(function(event)
	{
    	var prop = event.target.className;
        var w = prop.split('_')[1];
        var h = prop.split('_')[2];
        window.open(this.href,'','menubar=0,location=0,scrollbars=1,toolbar=0,status=0,directories=0,titlebar=0,width='+w+',height='+h);
        return false;
    });
    socialmedia();
}

function createRequest() 
{ 
	try {request = new XMLHttpRequest();} 
    catch (trymicrosoft) 
    { 
       try{request = new ActiveXObject("Msxml2.XMLHTTP");} 
       catch (othermicrosoft) 
       { 
    		try{request = new ActiveXObject("Microsoft.XMLHTTP");} 
            catch (failed) 
            { 
            	request = null; 
            } 
        } 
     } 
     if (request == null) 
        alert("Error creating request object!"); 
     else 
     	return request; 
} 

function confirmSubmit(fl)
{
	if (fl == 'reset')
		var agree = confirm('Are you sure you wish to reset the system for a new election');
	else
		var agree = confirm('Are you sure you wish to delete '+fl+'?');
	if (agree)
		return true ;
	else
		return false ;
}

//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 */
        if (u.indexOf('#') > -1) {
            u = u.substring(1,u.indexOf('#'))
        }
        //var u = "WERWERWR";  /*  this selects the link to your article */
        var iconDirectory = '/img/icons/'; /* 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 class="none"><a class="external" href="' + socialMedia[i].href + '" title="' + socialMedia[i].linkText + '"><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($('#sp_socialMedia'));
};
