var myDocument = window.document;
var tmpWin = "";
var activeField = null;
var catchup = "";

function MailPage(){
	var MyList=myDocument.frmList.List.options[myDocument.frmList.List.selectedIndex].value;
	if (MyList!="none"){
		myDocument.frmList.ListAction.value="ViewList";
		myDocument.frmList.action = "/4DACTION/Web_Send_EmailPage";
		var w = 500;
		var h = 350;
		var myleft=(screen.width)?(screen.width-w)/2:100;
		var mytop=(screen.height)?(screen.height-h)/2:100;
		settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
		win=window.open('','maillist',settings);
		myDocument.frmList.target = 'maillist';
		myDocument.frmList.submit();
	}else{
		var msg;
		msg=alert("Please select a list");
	}
}

function CreateList(){
	var ListName = window.prompt("Please enter the name of your list","");
	if (ListName!=null){
		isBad = fix_data(ListName);
		isDuplicate = false;
		for(var i = 0;i<myDocument.frmList.List.options.length;i++){
			test = myDocument.frmList.List.options[i].value.toLowerCase();
			if(test.indexOf(ListName.toLowerCase())>-1){
				isDuplicate = true;
				break;
			}
		}
		if(!isBad && !isDuplicate){
			url = "/4DACTION/Web_Lists";
			data = "Listaction=CreateList&List="+ListName
			send_ajax_post(url,data,true);
			myDocument.frmList.List[myDocument.frmList.List.length]=new Option(ListName,ListName,false,true);
			set_list(ListName);
		} else if(isDuplicate) {
			alert('List names cannot be duplicated. Please choose another name.');
			CreateList();
		} else {
			alert('List names can only contain Letters, Numbers, or underscores. Please choose another name.');
			CreateList();
		}
//		myDocument.frmList.ListAction.value="CreateList";
//		myDocument.frmList.action = "/4DACTION/Web_Lists";
//		myDocument.frmList.target = '';
//		myDocument.frmList.submit();
	}
}

function DeleteList(){
	var MyList = myDocument.frmList.List.options[myDocument.frmList.List.selectedIndex].value;
	if (MyList!="none"){
		var agree = confirm('Are you sure you want to delete your list?');
		if (agree){
			myDocument.frmList.ListAction.value="DeleteList";
			myDocument.frmList.Page.value='SR';
			myDocument.frmList.action = "/4DACTION/Web_Lists";
			myDocument.frmList.target = '';
			myDocument.frmList.submit();
		}
	}else{
		alert("Please select a list");
	}
}

function AddList(){
	var MyList=myDocument.frmList.List.options[myDocument.frmList.List.selectedIndex].value;
	if (MyList!="none"){
		myDocument.frmList.ListAction.value="AddList";
		myDocument.frmList.action = "/4DACTION/Web_Lists";
		myDocument.frmList.target = '';
		myDocument.frmList.submit();
	}else{
		alert("Please select a list");
	}
}

function ViewList(){
	var MyList = myDocument.frmList.List.options[myDocument.frmList.List.selectedIndex].value;
	if (MyList!="none"){
		myDocument.frmList.ListAction.value="ViewList";
		myDocument.frmList.target='';
		myDocument.frmList.action = "/4DACTION/Web_Lists";
		myDocument.frmList.submit();
	}else{
		alert("Please select a list");
	}
}

function EditList(){
	var MyList = myDocument.frmList.List.options[myDocument.frmList.List.selectedIndex].value;
	if (MyList != "none"){
		myDocument.frmList.ListAction.value="EditList";
		myDocument.frmList.action = "/4DACTION/Web_Lists";
		myDocument.frmList.target = '';
		myDocument.frmList.submit();
	}else{
		alert("Please select a list");
	}
}

function newwin(mypage){
	var w = 500;
	var h = screen.height - 80;
	myleft=(screen.width)?(screen.width-w)/2:100;
	settings="width=" + w + ",height=" + h + ",top=0,left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	win=window.open(mypage,'reel',settings);
}
function newwin2(mypage,h,w){
	var myleft=(screen.width)?(screen.width-w)/2:100;
	var mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	win=window.open(mypage,'pop',settings);
}
function newwin3(mypage,h,w){
	var myleft=(screen.width)?(screen.width-w)/2:100;
	var mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	win=window.open(mypage,'pop',settings);
}
function winhide(mypage){
	settings="width=1,height=1,top=1,left=1,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	win=window.open(mypage,'pop',settings);
	self.focus();
}
function change_cookie(list){
	var cookie = document.cookie;
	cookie_start = cookie.indexOf('SC_cookie=');
	if(document.cookie.length>0){
		var cookie_value_end = cookie.indexOf("~MyListName=") + 12;
		var prior_value = cookie.substring(cookie_start,cookie_value_end);
		var new_value = prior_value+list.options[list.selectedIndex].value+"~SC_cookieEND;path=/";
		document.cookie = new_value;
	}	
}

function set_list(name){
	var cookie = document.cookie;
	cookie_start = cookie.indexOf('SC_cookie=');
	if(document.cookie.length>0){
		var cookie_value_end = cookie.indexOf("~MyListName=") + 12;
		var prior_value = cookie.substring(cookie_start,cookie_value_end);
		var new_value = prior_value+name+"~SC_cookieEND;path=/";
		document.cookie = new_value;
	}	
}
function destroy_session(location){
		//var today = new Date();
		var cookieExpires = 'Thu, 01-Jan-70 00:00:01 GMT';
		document.cookie = "SC_cookie=~SC_cookieEND;path=/;expires="+cookieExpires+";;";
		window.location="http://" + location;
}

//ES Added 12/09/2010
/*
var logoutTimer = "";
var autoLogoutCheck = 0;
function preLogout(location){
	if(!document.getElementById('logoutMSG')){
		var msg = '<div id="titlebar" class="subtitle" style=line-height:2em;text-align:center;">Session Timeout</div> \n';
		msg += '<div style="width:280px;" class="p">Your session is about to time out. To extend your session, click the Extend button below.</div>';
		msg += '<div style="width:280px;text-align:center;position:relative;padding-bottom:6px;"><a class="btn_Link" style="margin-left:7%;" href="javascript:extend(\''+location+'\');">Extend</a></div>';
		var logoutMsgWin = document.createElement('div');
		logoutMsgWin.setAttribute('id','logoutMSG');
		logoutMsgWin.className = 'blue';
		logoutMsgWin.style.height='100px';
		logoutMsgWin.style.width='300px';
		logoutMsgWin.style.top='250px';
		logoutMsgWin.style.left='350px';
		logoutMsgWin.style.position="absolute";
		logoutMsgWin.style.zIndex="1000";
		logoutMsgWin.style.border="1px solid #102143";
		logoutMsgWin.style.textAlign="center";
		logoutMsgWin.style.backgroundColor="#FFFFFF";
		logoutMsgWin.innerHTML = msg;
		document.getElementById('maindiv').appendChild(logoutMsgWin);
	} else {
		document.getElementById('logoutMSG').style.display='';
	}
	logoutTimer = setTimeout(function(){destroy_session(location)},300000);
}

function extend(location){
	clearTimeout(logoutTimer);
	document.getElementById('logoutMSG').style.display='none';
	logoutTimer = setInterval(function(){sessionManager(location)},600000);
}

function sessionManager(location){
	autoLogoutCheck++;
	if(autoLogoutCheck == 2){
		preLogout(location);
	}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent (function() {
	logoutTimer = setInterval(function(){sessionManager('www.sourceecreative.com')},60000);
})
*/
//END 12/09/2010 Additions

function fix_data(text){
	//finds non-alpha characters and lets user know
	//Rewite ES 1/30/09 now returns true or false
	pattern = new RegExp(/[^a-zA-Z_0-9\s]/g);
	return pattern.test(text);
}

/*
function show_Survey_pop(){
	surveyWin = document.getElementById('SurveyPop');
	var myleft=250;
	var mytop=225;
	surveyWin.style.position="absolute";
	surveyWin.style.zIndex="1000";
	surveyWin.style.top=mytop+"px";
	surveyWin.style.left=myleft+"px";
	surveyWin.style.border="1px solid #102143";
	surveyWin.style.textAlign="center";
	surveyWin.style.backgroundColor="#E1E8F0";
	surveyWin.style.boxShadow="0px 0px 10px #000";
	surveyWin.style.color="#FFF";
	surveyWin.style.display="";
	msg = '<div id="titlebar" class="subtitle" style=line-height:2em;text-align:center;width:300px;">Your Opinion Counts!</div> \n';
	msg += '<div style="width:280px;text-align:center;height:12px;" class="t pl pr"></div> \n';
	msg += '<p class="blue">Please take our survey!';
	msg += '<br /><img src="/special/survey.jpg" /></p>';
	msg += '<div style="width:280px;background-color:#FFFFFF;text-align:center;height:12px;" class="t pl pr"></div><div style="text-align:center;background-color:#FFFFFF;position:relative;padding-bottom:12px;"><a class="btn_Link" style="margin-right:7%;" href="javascript:window.location=\'/4DACTION/TakeSurvey?SurveyName=update_2011\';close_survey_win();">Yes</a><a style="margin-left:7%;" class="btn_Link" href="javascript:close_survey_win();">No</a></div>';
	surveyWin.innerHTML=msg;
}
*/

function close_survey_win() {
	surveyWin = document.getElementById('SurveyPop');
	surveyWin.style.display="none";
	surveyWin.innerHTML = "";
	surveyWin.position="";
	surveyWin.style.top="";
	surveyWin.style.left="";
	surveyWin.style.border="";
	surveyWin.style.textAlign="";
	surveyWin.style.zIndex="";
	surveyWin.style.border="";
	surveyWin.style.backgroundColor="";
	surveyWin.style.padding="";
}

function show_win(msg){
	if (tmpWin!=""){
		close_win();
	}
	tmpWin = document.getElementById('MsgDiv');
	set_win_msg(msg);
}

function close_win() {
	if (tmpWin!=""){
		tmpWin.style.display="none";
		tmpWin.innerHTML = "";
		tmpWin.position="";
		tmpWin.style.top="";
		tmpWin.style.left="";
		tmpWin.style.border="";
		tmpWin.style.textAlign="";
		tmpWin.style.zIndex="";
		tmpWin.style.border="";
		tmpWin.style.backgroundColor="";
		tmpWin.style.padding="";
	}
}

function set_win_msg(msg){
	var w = 500;
	var h = 550;
	var myleft=(screen.width)?(screen.width-w)/2:100;
	var mytop=(screen.height)?(screen.height-h)/2:100;
	tmpWin.innerHTML = '<div class="content blue">'+msg+'</div><br><div style="width:280px;text-align:center;" class="t pl pr"><a class="lbb" href="javascript:close_win();">Close</a></div>';
	tmpWin.style.position="absolute";
	tmpWin.style.zIndex="1000";
	tmpWin.style.top=mytop+"px";
	tmpWin.style.left=myleft+"px";
	tmpWin.style.border="1px solid #102143";
	tmpWin.style.textAlign="justify";
	tmpWin.style.backgroundColor="#FFFFFF";
	tmpWin.style.display="";
}

function display_requirements(){
msg = '<div id="titlebar" class="subtitle" style=line-height:2em;text-align:center;">Minimum Requirement to View QuickTime Videos</div> \n';
msg += '<div style="width:280px;text-align:center;" class="t pl pr"></div> \n';
msg += '<div style="width:280px;" class="p">If you are experiencing difficulty viewing videos on our site, please update your browser, flash and/or quicktime by clicking on one of the links below.</div><br /> \n';
msg += '<div id="titlebar" style="width:280px;" class="graytitle pl pr">PC:</div><ul type="disc"> \n';
msg += '	<li><a class="lbb" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9ae91ebe-3385-447c-8a30-081805b2f90b&amp;displaylang=en" target="_blank">Internet Explorer 7</a> or Higher</li> \n';
msg += '	<li><a class="lbb" href="http://www.mozilla.com/en-US/firefox/" target="_blank">FireFox 4.0</a> or Higher</li> \n';
msg += '	<li><a class="lbb" href="http://www.apple.com/safari/download/" target="_blank">Safari 4.0</a> or Higher</li> \n';
msg += '</ul> \n';
msg += '<div id="titlebar" style="width:280px;" class="graytitle pl pr">Mac:</div> \n';
msg += '<ul type="disc"> \n';
msg += '	<li><a class="lbb" href="http://www.mozilla.com/en-US/firefox/" target="_blank">FireFox 4.0</a> or Higher</li> \n';
msg += '	<li><a class="lbb" href="http://www.apple.com/safari/download/" target="_blank">Safari 4.0</a> or Higher</li> \n';
msg += '</ul> \n';
msg += '<br /><div style="width:280px;" class="pl pr">Please Note: If you are using Mac OS X Panther (10.3), there is no way to upgrade to Safari 3.0. You must use <a class="lbb" href="http://www.mozilla.com/en-US/firefox/" target="_blank">FireFox 4.0</a> or higher.</div><br /> \n';
msg += '<div id="titlebar" style="width:280px;" class="graytitle pl pr">Quicktime:</div> \n';
msg += '<ul type="disc"> \n';
msg += '	<li><a class="lbb" href="http://www.apple.com/quicktime/download/" target="_blank">Quicktime 6.5</a> or Higher</li> \n';
msg += '</ul> \n';
msg += '<div id="titlebar" style="width:280px;" class="graytitle pl pr">Flash:</div> \n';
msg += '<ul type="disc"> \n';
msg += '	<li><a class="lbb" href="http://get.adobe.com/flashplayer/" target="_blank">Flash 9.0.115</a> or Higher</li> \n';
msg += '</ul> \n';
show_win(msg);
}
// ********************************************************************************************************
//ES - NEW functions 4/22/09
//send search to find list for this field
// code from line 255-517 removed since it is not longer needed.   date: 08/03/2010  
//**************************************************************************************************************

function adjust_ads(same){
	var ads = document.getElementById('ads');
	var contentContainer = document.getElementById(same);
	var tabs = document.getElementById('tabs3');
	if(!tabs){
		tabs = document.getElementById('tabs3K');
	}
	var newHeight = (contentContainer.offsetHeight - tabs.offsetHeight)+'px';
	ads.style.height = newHeight;
}

//IE needs this
//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license

if (!Array.prototype.filter)
{
  Array.prototype.filter = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
      {
        var val = this[i]; // in case fun mutates this
        if (fun.call(thisp, val, i, this))
          res.push(val);
      }
    }

    return res;
  };
}

//  Use jquery's .clone() instead.  date: 08/02/2010     
// Object.prototype.clone = function() {
//   var newObj = (this instanceof Array) ? [] : {};
//   for (i in this) {
//     if (i == 'clone') continue;
//     if (this[i] && typeof this[i] == "object") {
//      newObj[i] = this[i].clone();
//     } else newObj[i] = this[i]
//   } return newObj;
//  };

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length >>> 0;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}



function RenameList(){

    
// save List Name	
 	var oldListName = myDocument.frmList.List.options[myDocument.frmList.List.selectedIndex].value;
// save selected index
var currSelected = myDocument.frmList.List.selectedIndex
	
	if (oldListName!="none"){
	
// Ask for new name	
	
	var newListName = window.prompt("Please enter the new name","");
	if (newListName!=null){
		isBad = fix_data(newListName);
		if(!isBad){
			url = "/4DACTION/Web_Lists";
			data = "Listaction=RenameList&List="+newListName+"&OldList="+oldListName;
			send_ajax_post(url,data,true);
		// remove old list name 
           myDocument.frmList.List.options[currSelected] = null;
			
        // add renamed list  			
			myDocument.frmList.List[myDocument.frmList.List.length]=new Option(newListName,newListName,false,true);
			set_list(newListName);
		 	
			
		} else {
			alert('List names can only contain Letters, Numbers, or underscores. Please choose another name.');
			RenameList();
		}

	}
	
	
	
  }	
	
	
}

function reelwin(mypage){
// Expand width of Reels page to accomodate playlist.   Date: 03/17/2011
	var w = 750;
	var h = screen.height - 80;
	myleft=(screen.width)?(screen.width-w)/2:100;
	settings="width=" + w + ",height=" + h + ",top=0,left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	win=window.open(mypage,'reel',settings);
}




