// JavaScript Document

$(function() {
	checkForShowingHidden();
	$('#addurl').bind('click', function() {
											$('#url_inputs').append('<div class="urlcontainer" style="display: block;"><input class="urlinput inputfield" type="text" maxlength="500" name="shareurl[]" value=""/></div>');
										});		
	
	$('input.urlinput').bind('keyup', checkForShowingHidden);
	if($('#caperr').length>0) {
		document.location.href = "#caperr";
	}
});

function checkForShowingHidden() {
	var count=0;
	$('input.urlinput').each( function() {
									   if($(this).val()!="") {
											count++;
											}
									   });  
	if(count>1) {
		$('#descBox').show();
		$('#published').show();
		$('#captcha').show();
	}
	else {
		$('#descBox').hide();
		$('#published').hide();
		$('#captcha').hide();
	}
}




function openBunch() {
		
 var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
 if(mine)
    var popUpsBlocked = false
 else
    var popUpsBlocked = true
 mine.close()


if(popUpsBlocked)
  alert('We have detected that you are using popup blocking software.\n');
  
	  var bunch = document.getElementById('links').getElementsByTagName('a'); var i; var l;
	  for (i=0; l = bunch[i]; i++) {
		  //if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
			//var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
			//if (ieversion>=7) {
				//window.open(l.href,'dd'+i,'left=0,top=0' );				
			//}
			//else if (ieversion>=6)
				//alert("You're using IE6.x")
		//}
		//else {
		  if (l.className == 'noBunchOpen') {
			  continue;
		  }
		  open(l.href);
		//}
		
      }
    }


function copyToClipboard(text) {
		// Code is Based on http://www.jeffothy.com/weblog/clipboard-copy/
		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="/public/js/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(text)+'" width="10" height="10" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}

	function copyBunch() {
      var bunch = document.getElementById('links').getElementsByTagName('a'); var i; var l;
	  var bunchList;
	  for (i=0; l = bunch[i]; i++) {
		bunchList = bunchList + l.href + '\n';
      }
	  bunchList = bunchList.substring(9);
		copy(bunchList);
	  //copyToClipboard(bunchList);
	}

function ClipBoard()
{
	holdtext.innerText = copytext.innerText;
	Copied = holdtext.createTextRange();
	Copied.execCommand("Copy");
}

function copy(inElement) { alert(inElement);
  if (inElement.createTextRange) {
    var range = inElement.createTextRange();
    if (range && BodyLoaded==1)
      range.execCommand('Copy');
  } else {
    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="/public/js/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="10" height="10" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}
