var video_cells_current = Array();
var nav_cells_current = Array();

function swap_nav_cell_feature(CELLID,PID) {
	Element.hide('nav_cell_'+CELLID+'_'+eval(nav_cells_current[CELLID]));
	Element.show('nav_cell_'+CELLID+'_'+PID);
	nav_cells_current[CELLID] = PID;
	return false;
}

function swap_video(CELLID,VID_ID) {
	var i;
	var CURRENT = video_cells_current[CELLID];
	if (VID_ID !== CURRENT) {
		Element.hide('video_'+CELLID+'_'+CURRENT+'_video');
		Effect.SlideUp('video_'+CELLID+'_'+CURRENT);
		Effect.SlideDown('video_'+CELLID+'_'+VID_ID);
		Element.show('video_'+CELLID+'_'+VID_ID+'_video');
		video_cells_current[CELLID] = VID_ID;
	}
	$('video_'+CELLID+'_'+VID_ID+'_link').blur();
	return false;
}

// Array.unique( strict ) - Remove duplicate values
Array.prototype.unique = function( b ) {
 var a = [], i, l = this.length;
 for( i=0; i<l; i++ ) {
  if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
 }
 return a;
};

Array.prototype.in_array = function ( obj ) {
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		if ( this[x] == obj ) return true;
	}
	return false;
}


function inArray(ARRAY,VALUE) {
	var i;
	for (i=0;i<ARRAY.length;i++) {
		if (ARRAY[i] === VALUE) {
			return true;
		}
	}
	return false;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function swap_toggle(name) { // Used for hiding one field and showing it's partner element (along with a hide link)
	if ($(name).visible()) { // Target field is currently shown
		[name,name+'_hide'].each(Element.hide);
		Element.show(name+'_show');
		
	} else { // If the target field is already hidden...
		[name,name+'_hide'].each(Element.show);
		Element.hide(name+'_show');
	}
	return false;
}

function toolTip(tiptitle,content) {
	
	if (tiptitle !== '') { // Hover Help
		content = '<b style="color: #FF6600; margin-bottom: 5px; display: block;">'+tiptitle+'</b>'+content;
		Tip('<span style="line-height: 16px;">'+content+'</span>',
		ABOVE,true,
		CENTERMOUSE,true,
		BGCOLOR,'#000000',
		BORDERCOLOR,'#666666',
		DELAY,400,
		FADEIN,false,
		FADEOUT,false,
		FONTCOLOR,'#666666',
		FONTFACE,'Trebuchet MS, Arial, Verdana, sans-serif',
		FONTSIZE,'11px',
		PADDING,15,
		SHADOW,false,
		TEXTALIGN,'left',
		WIDTH, 200);
	} else { // True ToolTip
		Tip('<div style="line-height: 16px;" align="center">'+content+'</div>',
		ABOVE,true,
		CENTERMOUSE,true,
		BGCOLOR,'#000000',
		BORDERCOLOR,'#666666',
		DELAY,400,
		FADEIN,false,
		FADEOUT,false,
		FONTCOLOR,'#666666',
		FONTFACE,'Trebuchet MS, Arial, Verdana, sans-serif',
		FONTSIZE,'11px',
		PADDING,5,
		SHADOW,false,
		TEXTALIGN,'center',
		WIDTH, 100);
	}
}

function fixFileName(filename, field_id) {
	Newfilename = cleanupFileName(filename);
	document.getElementById(field_id).value = Newfilename;
	if (Newfilename !== filename) {
		show(field_id+'_warning');
	} else {
		hide(field_id+'_warning');
	}
}
function validateAttachment(fieldID) {
  	var valid_formats = new Array("doc","xls","pdf","ppt"); 
  	var URL = document.getElementById(fieldID).value;
	if (URL !== '') {
		var FILE_TYPE = URL.split('.');
		FILE_TYPE = FILE_TYPE[FILE_TYPE.length - 1].toLowerCase();
		if (!inArray(valid_formats,FILE_TYPE)) {
			alert("The file you're attempting to upload does not appear to be an allowed file type.");
			document.getElementById(fieldID).value = '';
		}
	}
  }
function validatePhotoURL(fieldID) {
  	var valid_formats = new Array('jpg','gif','jpeg','png');
  	var URL = document.getElementById(fieldID).value;
	if (URL !== '') {
		var FILE_TYPE = URL.split('.');
		FILE_TYPE = FILE_TYPE[FILE_TYPE.length - 1].toLowerCase();
		if (!inArray(valid_formats,FILE_TYPE)) {
			alert('The URL you entered for this image does not appear to be a valid image link. Please make sure the link ends in .jpg, .gif or .png and try again.');
			document.getElementById(fieldID).value = '';
		}
	}
  }
function trim(string) {
	string = string.replace(/^\s+|\s+$/g, '');
	return string;
}

//Custom JavaScript Functions by Shawn Olson
//Copyright 2006-2008
//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
//*******************************************

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-2007
	//Updated on August 12, 2007
	//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.type){
	    if (theItem.type=='checkbox') {
	    	theItem.checked=theController.checked;
	    }
	  } else {
	  	  theInputs = theItem.getElementsByTagName('input');
	  for(var y=0; y<theInputs.length; y++){
	  if(theInputs[y].type == 'checkbox' && theInputs[y].id != theController.id){
	     theInputs[y].checked = theController.checked;
	    }
	  }
	  }
    }
}

function isNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function emailCheck(str){
 var filter=/^.+@.+\..{2,3}$/;

 if (filter.test(str))
 	return true;
 else {
    return false;
 }
}