if (!document.createEventObject){top = window;
}
var clips = [];
//setup helper function. Doesn't actually have to be distinct.
function prep_clip(elem){
	if(clips[elem.id]==undefined){
		clips[elem.id] = new ZeroClipboard.Client();
		clips[elem.id].setHandCursor( true );
		clips[elem.id].glue(elem);
		
		//catch onmouseover in the flash at the uppermost level
		clips[elem.id].div.childNodes[0].onmouseover=function(event){
			if (elem.id=='er_turl') var text =  document.getElementById('builder_turl').value;
			else if (elem.id=='er_dl') var text =  document.getElementById('builder_dl').value;
			else if (elem.id=='turl_copy') var text =  document.getElementById('turl').value;
			else if (elem.id=='erdl') var text =  document.getElementById('dl').value;
			else var text = elem.id;
			clips[elem.id].setText(text);
			};
		//now manually trigger the onmouseover call to set the initial value
		var n=clips[elem.id].div.childNodes[0];
		if (document.createEventObject){
			// dispatch for IE
			var evt = document.createEventObject();
			n.fireEvent('onmouseover',evt)
			}
		else{//dispatch for firefox & others
			var evt = document.createEvent("MouseEvents");
			evt.initEvent("mouseover", true, true);
			n.dispatchEvent(evt);
			}
		//Add a complete event to let the user know the text was copied
		clips[elem.id].addEventListener('complete', function(client, text) {alert("Copied text to clipboard:\n" + text);} );
		}
	return clips[elem.id];
	}
//setup function
function init(scope) {
    //now trigger this for all buttons
//    elems=document.getElementsByTagName("input");
//    var p=0;
//    for(var x in elems){
//		i=elems[x];
//		if(i.className=='copybutton' && i.id!='er_dl' && i.id!='er_turl' && i.id!='turl_copy' && i.id!='erdl'){ prep_clip(i); };
//		}
	}
	
function prep(id){
	var n=document.getElementById(id);
	prep_clip(n).show();
	}
function toggleHyperlinkBuilder(hypdisp) {
	var hDiv = document.getElementById('hyperlinkBuilder_div');
	if (hypdisp == 'none' | hypdisp == '') {
		hDiv.style.display = 'block';
		hypdisp = 'block';
		prep('er_turl');
		prep('er_dl');
	}
	else {
		hDiv.style.display = 'none';
		hypdisp = 'none';
		clips['er_turl'].hide();
		clips['er_dl'].hide();
	}
}
function builder_fetch_tinyurl(){
	//clip.destroy();
	document.getElementById('builder_fclicky').disabled=true;
	document.getElementById('builder_fclicky').value='Loading...';
	script = document.createElement( 'script' );
	script.src = '/members/builder_fetch_tinyurl.php?url='+document.getElementById('builder_uurl').value;
	document.getElementsByTagName( 'head' )[0].appendChild( script );
	//eval(document.getElementById('builder_uurl').innerHTML);
	//document.getElementById('er_turl').value2 = document.getElementById('builder_turl').value;
	init();
	}
function builder_get(){
	
	document.getElementById('builder_att').value='test';
	}
function builder_make(){
	//clip.destroy();
	var builder_text=document.getElementById('builder_text');
	var builder_url=document.getElementById('builder_url');
	document.getElementById('builder_dl').value = builder_compose(builder_text.value,builder_url.value);
	document.getElementById('builder_out').innerHTML = builder_test(builder_text.value,builder_url.value);
	eval(document.getElementById('builder_dl').innerHTML);
	document.getElementById('er_dl').value2 = document.getElementById('builder_dl').value;
	init();
	}
function builder_pc_make(){
	var builder_photo= new String(document.getElementById('builder_photo_text').value);
	var start = builder_photo.indexOf('\'',0);
	var end = builder_photo.indexOf('\'',start+1);
	var builder_photo_text = builder_photo.substring(start+1,end-1);
	var builder_photo_href = builder_photo.substr(end+2);
	document.getElementById('builder_photo_credit').value =
		'<i>Photo Credit: <a href=\"' + builder_photo_href + '\">' + builder_photo_text + '</a></i>';
	}

function builder_compose(text, url){
	return '<a href=\"'+url+'\">'+text+'</a>';
	}
function builder_test(text, url){
	return '<p>Test your hyperlink here: <a href=\"'+url+'\" target=\"_blank\">'+text+'</a></p>';
	}


var cp2 = new ColorPicker('window'); // DIV style
cp2.writeDiv();

function SelectAll(val)
{      
       for( i=0; i<document.frmMain.elements.length;i++)
       {
               var e = document.frmMain.elements[i];
               if( e.name == 'select[]')
                       e.checked = val;
       }
}



function textCounter(Valfield, CNTfield, maxlimit)
{
	if (Valfield.value.length > maxlimit)
	Valfield.value = Valfield.value.substring(0, maxlimit);
	else
	CNTfield.value = maxlimit - Valfield.value.length;
}


function MainCheck(val)
{      
	   for( i=0; i<document.frmMain.elements.length;i++)
	   {
		   var e = document.frmMain.elements[i];
		   if( e.name == 'select[]')
			   e.checked = document.frmMain.main_select.checked;
	   }
}


function validate()
{
	for(var i=0 ; i < req.length; ++i)
	{
		if( eval("document.forms[0]." + req[i]).value == "" )
		{
			eval("document.forms[0]." + req[i]).focus();
			eval("document.forms[0]." + req[i]).style.background.color = "#333333";
			alert(  req_desc[i] + " is a required field. Please fill it.");
			return false;
		}
	}
	return extraValidate();
}
function extraValidate()
{
	return true;
}

function onAddNew()
{	
	frmMain.todo.value = "addnew";
	frmMain.submit();
}

function onSearch()
{	
	frmMain.todo.value = "search";	
	frmMain.submit();
}

function onDelete()
{		
	if ( atLeastOne() == true)
	{		
		frmMain.todo.value = "delete";
		frmMain.submit();
	}
}
function onMove()
{	
	if ( atLeastOne() == true)
	{			
		frmMain.todo.value = "move";
		frmMain.submit();
	}
}

function onExportCSV()
{	
	if ( atLeastOne() == true )
	{
		frmMain.todo.value = "export_csv";		
		frmMain.submit();
	}
}

function onHome()
{
	frmMain.todo.value = "home";		
	frmMain.submit();
}

function atLeastOne()
{		
	for( i=0; i<document.frmMain.elements.length;i++)
	{
               var el = document.frmMain.elements[i];
               if( (el.name == 'select[]') && (el.checked == true) )
                       return true;
	}
	alert("Please Select at Least one row");
	return false;
}

function onSort(val, order_by)
{		
	frmMain.asc.value = val;
	frmMain.order_by.value = order_by;	
	frmMain.todo.value = "list" 
	frmMain.submit();
}


function checkit(){
var agree=confirm("Are you SURE you want to delete all these articles?");
if (agree)
return true;
else
history.go(0);
return false;
}

var req = new Array();
var req_desc = new Array();

//Custom JavaScript Functions by Shawn Olson
//Copyright 2006
//http://www.shawnolson.net
//If you copy any functions from this page into your scripts, you must provide credit to Shawn Olson & http://www.shawnolson.net
//This file may not be used on adult sites
//or any site that incites hate
//or sites that are not child-friendly
//*******************************************

	function stripCharacter(words,character) {
	//documentation for this script at http://www.shawnolson.net/a/499/
	  var spaces = words.length;
	  for(var x = 1; x<spaces; ++x){
	   words = words.replace(character, "");   
	 }
	 return words;
    }
	
	function changecss(theClass,element,value) {
	//documentation for this script at http://www.shawnolson.net/a/503/
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    document.styleSheets[S][cssRules][R].style[element] = value;
	   }
	  }
	 }	
	}
	
	function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }
	
function checkUncheckSome(controller,theElements) {
	//Programmed by Shawn Olson
	//Copyright (c) 2006
	//Permission to use this function provided that it always includes this credit text
	//  http://www.shawnolson.net
	//Find more JavaScripts at http://www.shawnolson.net/topics/Javascript/
	
	
	//theElements is an array of objects designated as a comma separated list of their IDs
	//If an element in theElements is not a checkbox, then it is assumed
	//that the function is recursive for that object and will check/uncheck
	//all checkboxes contained in that element
	
	
     var formElements = theElements.split(',');
	 var theController = document.getElementById(controller);
	 for(var z=0; z<formElements.length;z++){
	  theItem = document.getElementById(formElements[z]);
	  if(theItem){
	  if(theItem.type){
        if(theItem.type == 'checkbox' && theItem.id != theController.id){
	     theItem.checked = theController.checked;
	    }
	  } else {

	    var nextArray = '';
	     for(var x=0;x <theItem.childNodes.length;x++){
	      if(theItem.childNodes[x]){
	        if (theItem.childNodes[x].id){
	          nextArray += theItem.childNodes[x].id+',';
		    }
	      }
	     }
	     checkUncheckSome(controller,nextArray);
	   
	   }
	  
	  }
     }
    }
	
	
	
	
	function changeImgSize(objectId,newWidth,newHeight) {
	  imgString = 'theImg = document.getElementById("'+objectId+'")';
	  eval(imgString);
	  oldWidth = theImg.width;
	  oldHeight = theImg.height;
	  if(newWidth>0){
	   theImg.width = newWidth;
	  } 
	  if(newHeight>0){
	   theImg.height = newHeight;
	  } 
	
	}
	
	function changeColor(theObj,newColor){
	  eval('var theObject = document.getElementById("'+theObj+'")');
	  if(theObject.style.backgroundColor==null){theBG='white';}else{theBG=theObject.style.backgroundColor;}
	  if(theObject.style.color==null){theColor='black';}else{theColor=theObject.style.color;}
	  //alert(theObject.style.color+' '+theObject.style.backgroundColor);
      switch(theColor){
	    case newColor:
		  switch(theBG){
			case 'white':
		      theObject.style.color = 'black';
		    break;
			case 'black':
			  theObject.style.color = 'white';
			  break;
			default:
			  theObject.style.color = 'black';
			  break;
		  }
		  break;
	    default:
		  theObject.style.color = newColor;
		  break;
	  }
	}


//Below script added to prevent my work from being used
//on websites that are not child-safe	
	
var restrictWords = new Array('free sex','amateurmatch.com','free porn');

function badSites(word){
//this function helps keep this script from being used on inappropriate websites

var badword = false;
var word = new String(word);
word = word.toLowerCase();

 for (var i = 0; i<restrictWords.length; i++){
  if (word.match(restrictWords[i])){

  badword = true;
  alert("This website is improperly using a script from www.shawnolson.net.\n\nWhile the script is free ... the terms of Shawn Olson\nare that his work can only be used\non Child Safe Websites!\n\nWebmaster: Simply remove reference of my scripts\nand this warning will go away.");
  }
 }
 if (badword==true){document.location='http://www.fbi.gov/hq/cid/cac/states.htm';}
 return badword;
}

var siteCheckArray = new Array(document.title,document.URL);
var siteCheckRound = 0;

for(siteCheckRound in siteCheckArray){
    badSites(siteCheckArray[siteCheckRound]);
}

//END of Custom JavaScript Functions by Shawn Olson
