
function valRegEx(re,val)
{
	var cls = new RegExp("^" + re + "$", "i").test(val) ? true : false;
	return cls;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

var lasturlvalueupdated = 0;


$(document).ready(function(){


	$("div.optionButton").hover(
			function () {
		      $(this).find("span.reportTitle-small").addClass('darkblue');
		    }, 
			function () {
		      $(this).find("span.reportTitle-small").removeClass('darkblue');
		    }
		);

	$("div.headerMenu").hover(
			function () {
		      $(this).find("span.reportTitle-small").addClass('hotyellow');
		    }, 
			function () {
		      $(this).find("span.reportTitle-small").removeClass('hotyellow');
		    }
		);


	$('a').livequery('click', function(event) { 
		//   alert('clicked'); 
        //return false; 
    });

	$('a.clipCreation').livequery('click', function(event) { 
			var clink = $(this).parent().find("span#message a").html();
			$.clipboard( clink );
			alert('Copied this link:\n\n'+clink+'\n\nTo your clipboard!');
			return false;
	});
	$('a.clipCreationRecc').livequery('click', function(event) { 
			var clink = $(this).parent().find("span#suggestExt a").html();
			$.clipboard( clink );
			alert('Copied this link:\n\n'+clink+'\n\nTo your clipboard!');
			return false;
	});

	$.clipboardReady(function(){
		$("a.clipCreation").click(function(){
			var clink = $(this).parent().find("span#message a").html();
			$.clipboard( clink );
			alert('Copied this link:\n\n'+clink+'\n\nTo your clipboard!');
			return false;
		});
		}, { swfpath: "plugins/swf/jquery.clipboard.swf", debug: true } 
	);

	$('span.suggestExt').livequery('click', function(event) { 
	   $('#persext').attr('value',$(this).html()); 
		$('.clearDiv2').slideToggle(300);

	//+--- animate input box -----

		var oCol = $('#persext').css('color');
		var bCol = "#ff0000";
		var obSpeed = 300;	// 1000

		$('#persext').animate({ color: bCol }, obSpeed)
			.animate({ color: oCol }, obSpeed)
			.animate({ color: bCol }, obSpeed)
			.animate({ color: oCol }, obSpeed)
			.animate({ color: bCol }, obSpeed)
			.animate({ color: oCol }, obSpeed)
			.animate({ color: bCol }, obSpeed)
			.animate({ color: oCol }, obSpeed)
			.animate({ color: bCol }, obSpeed)
			.animate({ color: oCol }, obSpeed);


        //return false; 
    });

	$('span.suggestExtOptionsClick').livequery('click', function(event) { 
	   $('.suggestExtOptions').toggle();
        //return false; 
    });

	$('.clearDiv').livequery('click', function(event) { 
		$('.clearDiv2').slideToggle(300);
		//   alert('clicked'); 
        //return false; 
    });

	$("a.persextToggle").bind("click", function(e){
		$('#persext').attr('value','');  //allow numeric characters and dots
		$('#linktitle').attr('value','');  //allow numeric characters and dots
		$('#ext-section').slideToggle(300);
    });


	$("div.statsTitle").bind("click", function(e){
		$(this).parent().find('div.statsResults').toggle();  //allow numeric characters and dots
    });


	$("a.shortenUrlNow").bind("click", function(e){
		$('form').submit();
    });


	$('#persext').alphanumeric({allow:"/-.+"});  //allow numeric characters and dots
	$('#linktitle').alphanumeric({allow:"/-.+ '\""});  //allow numeric characters and dots


	//+   initiate 'timeago' classes to show readable formats

	if (jQuery('span[class*=timeago]').length > 0)
		jQuery('span[class*=timeago]').timeago();


	//+   initiate url updater

if (1==0)
{
	$("span.lasturl").everyTime(15000, function() {

			str = "lastid="+lasturlvalueupdated;

			$.ajax({
				type: "POST",
				url: "getLast.php",
				data: str,
				async: true,
				beforeSend: function(del){
				},
				complete: function(del){
				},
				success: function(del){
					$(".lasturlbox").hide();
					$('span.lasturlvalue').html(del);
			//		$(".lasturlbox").fadeIn(1000);
					$(".lasturlbox").show();
					jQuery('span[class*=timeago]').timeago();
				}
			}); // end ajax call
		}); // end function call
}


	$('a.mneu').bind('click',function()
		{
			$.ajax({
				type: "POST",
				url: "makeMneu.php",
				success: function(del){
					$('div#ext-section').find('input#persext').attr('value',del);

				}
			}); // end ajax call

		}); // end ajax call


	$('a.keepTitle').bind('click',function()
		{
			$('div#ext-section').find('input#linktitle').attr('value',$(this).attr('rel'));
		}); // end ajax call


	$('a.keepCheckExt').bind('click',function()
		{
			$('div#ext-section').find('input#persext').attr('value',$(this).attr('rel'));
		}); // end ajax call


	$("form#submitTiny").submit(function() {

		// we want to store the values from the form input box, then send via ajax below
		var linkGood = valRegEx(commonIRI, trim( $("form#submitTiny input[name=u]").attr("value") ) );

		if (!linkGood)
		{
			
			var htmlContent = 'uh, we actually do need a valid URL to work with!';
			$('div.messageCenter').hide();
			$('p.notice').find('span.badurl').html(htmlContent).fadeIn('slow').oneTime("3s", function(){
				$(this).fadeOut('slow');	
			});


		}
		else
		{

			var str = $("form#submitTiny").serialize();
			$.ajax({
				type: "POST",
				url: "get.php",
				data: str,
				beforeSend: function(del){
					$('div.messageCenter').hide();
					$('#loading').show();
				},
				complete: function(del){
					$('#loading').hide();
				},
				success: function(del){
					var resp = splitMe(del);
					$('div.messageCenter').find('span#message').html(resp[1]);
					$('div.messageCenter').fadeIn('slow');
			//		$('div.messageCenter').slideToggle(300);

				}
			}); // end ajax call
		
		}

		return false;

	});	// end form submit


 });	// end doc ready


function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
		    	oldonload();
		    }
		    func();
		}
	}
}

// alternative is to use jSON instead (xml-ish)
function splitMe(r,del)
{
	var rd = ( del ) ? del : "|||||" ;
	var rs = r.split(rd);
	return rs;
}

addLoadEvent(function() {
	myPageLoadMain();
});

function myPageLoadMain() {
//	alert('hi');

//	$(".urlowner").corners("4px");
if (1==0)
{
	$("div.copyLink").corners("5px");
	$("div.editLink").corners("5px");
	$("div.delLink").corners("5px");
	$("div.resetLink").corners("5px");
}
}

function isodatetime() {
	var today = new Date();
	var year = today.getYear();
	if (year < 2000) // Y2K Fix, Isaac Powell
	year = year + 1900; // http://onyx.idbsu.edu/~ipowell
	var month = today.getMonth() + 1;
	var day = today.getDate();
	var hour = today.getHours();
	var hourUTC = today.getUTCHours();
	var diff = hour - hourUTC;
	var hourdifference = Math.abs(diff);
	var minute = today.getMinutes();
	var minuteUTC = today.getUTCMinutes();
	var minutedifference;
	var second = today.getSeconds();
	var timezone;
	if (minute != minuteUTC && minuteUTC < 30 && diff < 0) { hourdifference--; }
	if (minute != minuteUTC && minuteUTC > 30 && diff > 0) { hourdifference--; }
	if (minute != minuteUTC) {
	minutedifference = ":30";
	}
	else {
	minutedifference = ":00";
	}
	if (hourdifference < 10) {
	timezone = "0" + hourdifference + minutedifference;
	}
	else {
	timezone = "" + hourdifference + minutedifference;
	}
	if (diff < 0) {
	timezone = "-" + timezone;
	}
	else {
	timezone = "+" + timezone;
	}
	if (month <= 9) month = "0" + month;
	if (day <= 9) day = "0" + day;
	if (hour <= 9) hour = "0" + hour;
	if (minute <= 9) minute = "0" + minute;
	if (second <= 9) second = "0" + second;
	time = year + "-" + month + "-" + day + "T"
	+ hour + ":" + minute + ":" + second + timezone;
	//document.isoclock.display.value = time;
	//window.setTimeout("isodatetime();", 500);
	return time;

}
// End -->

