function empty(string) {
    return (string == null || string == "");
}

function isFieldEmpty(fieldName){
   var errors = false;

   if (jQuery(fieldName) ) {
       field = jQuery('#'+fieldName);
       if (field.val() != null && (field.val() == "" || field.val().replace(/^\s+|\s+$/g,"").length == 0)) {
        errors = true;
       }
   }
   if(errors){
       return true;
   }
   return false;
}

function copyToClipboard(inElement) {
	var flashcopier = 'flashcopier';
	if(!document.getElementById(flashcopier)) {
	  var divholder = document.createElement('div');
	  divholder.id = flashcopier;
	  document.body.appendChild(divholder);
	}
	document.getElementById(flashcopier).innerHTML = '';
	var divinfo = '<embed src="/js/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(jQuery(inElement).html())+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	document.getElementById(flashcopier).innerHTML = divinfo;
}

function showElement(element) {
    var box = document.getElementById(element);
    box.style.visibility = "visible";
    box.style.display = "inline";
}

function hideElement(element) {
	var box = document.getElementById(element);
    box.style.visibility = "hidden";
    box.style.display = "none";
}

function switchElements(e1, e2) {
	hideElement(e1);
	showElement(e2);
}

function isVisible(element) {
	var e = document.getElementById(element);
	if (e.style.visibility == 'visible')
		return true;
	else
		return false;
}
function deliciousLink() {
	window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title), 'delicious', 'toolbar=no,width=550,height=550');
}

function diggLink() {
	var title=document.title;
	var url = document.URL;

	// digg only accepts a 75 char title... if we're over that trim it down
	if (title.length>75) {
		title = title.substring(0,71);
		title += "...";
	}
	window.open("http://digg.com/submit?url="+url+"&title="+title+"&bodytext=&media=news&topic=software", 'digg', 'width=1000,height=700');
}

function twitterLink() {
	var title=document.title;
	var localUrl = document.URL;

	var url = jQuery.ajax({
		url: "/tinyurl.php?"+localUrl,
		async: false
	}).responseText;
	var status = title + " " + url;
	// twitter accepts a 140 char status... if we're over that trim it down
	if (status.length>140) {
		title = title.substring(0,(status.length-url.length+4)); // leave 3 spaces for ... and 1 for space
		title += "...";
		status = title + " " + url;
	}

	window.open('http://twitter.com/home?status='+encodeURIComponent(status), 'twitter', 'width=800,height=600');
}

		function clearErrorMessages(g){var e=g.getElementsByTagName("div");var c=g.getElementsByTagName("span");var a=new Array();if(e){for(var b=0;b<e.length;b++){var h=e[b];if(h.getAttribute("errorFor")){a.push(h)}}}if(c){for(var b=0;b<c.length;b++){var h=c[b];if(h.getAttribute("errorFor")){a.push(h)}}}for(var b=0;b<a.length;b++){var f=a[b];var d=f.parentNode;d.removeChild(f)}}
function clearErrorLabels(e){var g=e.getElementsByTagName("label");for(var c=0;c<g.length;c++){var b=g[c];if(b){if(b.getAttribute("class")=="error"){b.setAttribute("class","label");b.setAttribute("className","label")}}}var f=e.getElementsByTagName("strong");var d=f.length;for(var c=0;c<f.length;c++){var a=f[c];if(a){if((a.getAttribute("class")=="err")||a.getAttribute("errorFor")){a.parentNode.removeChild(a);if(d!=f.length){c--;d=f.length}}}}}
function addError(g,a){
	try{
		var d=g.parentNode;
		var c=d.getElementsByTagName("label")[0];
		if(c){
			c.setAttribute("class","error");
			c.setAttribute("className","error")
		}
		var b=document.createTextNode(a);
		var f=document.createElement("strong");
		f.setAttribute("class","err");
		f.setAttribute("className","err");
		f.setAttribute("errorFor",g.id);
		f.appendChild(b);
		d.appendChild(f)
	}	catch(g){
	}
}


function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

var newwindow;
function getdownload(url)
{
	newwindow=window.open(url,'name','height=680,width=520,scrollbars=no,toolbars=no,location=no,menubar=no,resizable=1');
	if (window.focus) {newwindow.focus()}
}


