/* Resolution Interactive Media */
/* Developed By: Jonathan Kochis And Brendan Farr-Gaynor */
/* jonathan@teamresolution.com / brendan@teamresolution.com */

var zKeeper = new Array();
var topzKeeper = new Array();
var vTopOff
var vTopOn
var topvTopOff
var topvTopOn
var runningWin


var storePathToFilePathField = null;

function resCustomFileBrowser(field_name, url, type, win) {
	// Custom browser logic
	//alert('field_name: ' + field_name + '\n url: ' + url + '\n type: ' + type + '\n win: ' + win);
	//use the following to reference the field
	//win.document.forms[0].elements[field_name].value = 'my browser value';
	//loaderPopup(type);
	storePathToFilePathField = win.document.forms[0].elements[field_name];
	loaderPopupWin = window.open("/inc/tinyLoader.php?uploadType="+ type, "loaderPopup", "scrollbars=no,width=330,height=150");
}


function prepNavBatch() {
	
	winTest = navigator.platform.indexOf("Win");
	  if(winTest > -1) {
		runningWin = true;
	  } else {
		runningWin = false
	  }
	
	
	
	
	if((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.indexOf("MSIE 7.") < 1))  {
		vTopOff = 4;
		vTopOn = 4;
		topvTopOff = -10;
		topvTopOn = -10;
		
		
	} else {
		vTopOff = -1;
		vTopOn = -1;
		topvTopOff = -11;
		topvTopOn = -11;
	}
	

	
	for(i = 0; i < 4; i++) {
		currentEval = 'M' + (i+1);
		zKeeper[i] = document.getElementById(currentEval).style.zIndex;
	}
	
	for(i = 0; i < 2; i++) {
		currentEval = 'topM' + (i+1);
		topzKeeper[i] = document.getElementById(currentEval).style.zIndex;
	}
	//alert('getting here');

}


 function pushMeOut(whoAmI, userPress) {
	if(whoAmI < 99) {
		currentEval = 'M' + whoAmI;
		currentTextEval = 'T' + whoAmI;
		lessMe = whoAmI - 1;
		//move this tab above all others in the array 
		zKeeper[lessMe] = 4;
	
	
		for(var i = 0; i < zKeeper.length; i++) {
			if((zKeeper[i] > document.getElementById(currentEval).style.zIndex) && ((i+1) != whoAmI)) {
			//if this level is higher then the one being switched (but not this one), move it down one 
			zKeeper[i] = zKeeper[i] - 1;
			}
		}
	}

	if((navigator.appName == "Microsoft Internet Explorer") && runningWin  && (navigator.appVersion.indexOf("MSIE 7.") < 1)) { pusher = 2; } else {pusher = 0;}

//set the tabs
for(var i = 0; i < zKeeper.length; i++) {
myEval = 'M' + (i+1);
myTextEval = 'T' + (i+1);
document.getElementById(myEval).style.zIndex = zKeeper[i];
		document.getElementById(myEval).style.top = vTopOff + "px";
		
		document.getElementById(myTextEval).style.top = (vTopOff + pusher) + "px";
//document.getElementById(myEval).style.borderBottomColor = "#999966"; /*not selected */

	if((navigator.appName == "Microsoft Internet Explorer") && runningWin  && (navigator.appVersion.indexOf("MSIE 7.") < 1)) {
	document.getElementById(myEval).className = "normTabAlpha";
	if(document.getElementById(myTextEval).style.left || (document.getElementById(myTextEval).style.left != "-10px;")) {

		document.getElementById("T1").style.marginLeft = "-6px";
		document.getElementById("T2").style.marginLeft = "-7px";
		document.getElementById("T3").style.marginLeft = "-13px";
		document.getElementById("T4").style.marginLeft = "6px";
		}
	} else {
	document.getElementById(myEval).className = "normTab"; 
		document.getElementById("T1").style.marginLeft = "-7px";
		document.getElementById("T2").style.marginLeft = "-7px";
		document.getElementById("T3").style.marginLeft = "-13px";
		document.getElementById("T4").style.marginLeft = "13px";
	}

}

	if(whoAmI < 99) {
		document.getElementById(currentEval).style.top = vTopOn + "px";
		document.getElementById(currentTextEval).style.top = (vTopOn + pusher) + "px";
		//document.getElementById(currentEval).style.borderBottomColor = "#FFFFFF"; 



		if((navigator.appName == "Microsoft Internet Explorer") && runningWin  && (navigator.appVersion.indexOf("MSIE 7.") < 1)) {
			document.getElementById(currentEval).className = "overTabAlpha";
			} else {
			document.getElementById(currentEval).className = "overTab"; 
			//alert("GETTING HERE AND eval is: " + currentEval + " CURRENT CLASS IS: " + document.getElementById(currentEval).className);
			}
	}


	//set all of the sub's to none
	for(var i = 1; i <= zKeeper.length; i++) {
		//myEval = 'S' + i;
		overEval = 'L' + i;
		//document.getElementById(myEval).style.display = 'none';
		document.getElementById(overEval).className = "menuText";
	}
	
	if(whoAmI < 99) {
		//currentEval = 'S' + whoAmI;
		//document.getElementById(currentEval).style.display = 'block';
		overEval = 'L' + whoAmI;
		document.getElementById(overEval).className = "menuTextOn";
	}

}

 function topPushMeOut(whoAmI, userPress) {

		if(whoAmI < 99) {
				currentEval = 'topM' + whoAmI;
				currentTextEval = 'topT' + whoAmI;
				lessMe = whoAmI - 1;
				//move this tab above all others in the array 
				topzKeeper[lessMe] = 2;
			
			
				for(var i = 0; i <= topzKeeper.length; i++) {
						if((topzKeeper[i] > document.getElementById(currentEval).style.zIndex) && ((i+1) != whoAmI)) {
						//if this level is higher then the one being switched (but not this one), move it down one 
						topzKeeper[i] = topzKeeper[i] - 1;
						}
				}
		}
		

		if((navigator.appName == "Microsoft Internet Explorer") && runningWin && (navigator.appVersion.indexOf("MSIE 7.") < 1)) { pusher = -3; } else {pusher = -2;}
		
		//set the tabs
		for(var i = 0; i < topzKeeper.length; i++) {
		myEval = 'topM' + (i+1);
		myTextEval = 'topT' + (i+1);
		document.getElementById(myEval).style.zIndex = topzKeeper[i];
		document.getElementById(myEval).style.top = topvTopOff + "px";
		document.getElementById(myTextEval).style.top = (topvTopOff + pusher) + "px";
		
			if((navigator.appName == "Microsoft Internet Explorer") && runningWin && (navigator.appVersion.indexOf("MSIE 7.") < 1)) {
				document.getElementById(myEval).className = "topNormTabAlpha";
						
						if(document.getElementById(myTextEval).style.left || (document.getElementById(myTextEval).style.left != "-10px;")) {
						document.getElementById("topT1").style.marginLeft = "-13px";
							document.getElementById("topT2").style.marginLeft = "9px";
						}
						
			} else {
				document.getElementById(myEval).className = "topNormTab"; 
				document.getElementById("topT1").style.marginLeft = "-14px";
				document.getElementById("topT2").style.marginLeft = "19px";
				//alert("GETTING HERE (2) AND eval is: " + myEval + " CURRENT CLASS IS: " + document.getElementById(myEval).className);
				//alert(topzKeeper.length);
			}
		
		}

	if(whoAmI < 99) {
		document.getElementById(currentEval).style.top = topvTopOn + "px";
		document.getElementById(currentTextEval).style.top = (topvTopOn + pusher) + "px";
		//document.getElementById(currentEval).style.borderBottomColor = "#FFFFFF"; 



		if((navigator.appName == "Microsoft Internet Explorer") && runningWin  && (navigator.appVersion.indexOf("MSIE 7.") < 1)) {
			document.getElementById(currentEval).className = "topOverTabAlpha";
			} else {
			document.getElementById(currentEval).className = "topOverTab"; 
			//alert("GETTING HERE AND eval is: " + currentEval + " CURRENT CLASS IS: " + document.getElementById(currentEval).className);
			}
	}


	//set all of the sub's to none
	for(var i = 1; i <= topzKeeper.length; i++) {
		//myEval = 'S' + i;
		overEval = 'topL' + i;
		//document.getElementById(myEval).style.display = 'none';
		document.getElementById(overEval).className = "topMenuText";
	}
	
	if(whoAmI < 99) {
		//currentEval = 'S' + whoAmI;
		//document.getElementById(currentEval).style.display = 'block';
		overEval = 'topL' + whoAmI;
		document.getElementById(overEval).className = "topMenuTextOn";
	}
	

}


/* Resolution Interactive Media */
/* Developed By: Jonathan Kochis And Brendan Farr-Gaynor */
/* jonathan@teamresolution.com / brendan@teamresolution.com */



//Resolution WYSIWYG functions


function confirmDelete(loc) {
		if(confirm("Are you sure you would like to delete this listing?")) {
			window.location = loc;
		}
	}
	

var x = null;
var xSet = false;


function setActiveName(nameToSet) { //switches X var to the active
	
	if(navigator.appName == "Netscape") {
		x = document.getElementById(nameToSet).contentDocument;
	
	} else { //damn IE why can't you be standards compliant
	//alert("I must be IE");
		
		x = eval(nameToSet + ".document"); //iView.document;
	}	
	
}


function Init(myName) { //turns on designMode and sets the first X
	
	setActiveName(myName);
	x.designMode = 'On'; //turns them all on
	xSet = true;
}

function setContent(theContent, myName) {
	
		setActiveName(myName);
		//alert(x.name);
		
		x.body.style.fontFamily = "Verdana"
		x.body.style.fontSize = "11px"
		x.body.bgColor = "";	
		x.body.text = '#000000';
		
		
		x.body.innerHTML = theContent;

}


function postIt(textareaName, myName) {   //ADD MY_NAME TO THIS!
//alert("getting here: " + textareaName);
setActiveName(myName);
document.getElementById(textareaName).value = x.body.innerHTML;

}




/// specific action functions

	function boldIt(myName) { 
	  setActiveName(myName);
	  x.execCommand('bold', false, null);
	}
	
	function italIt(myName) {
	  setActiveName(myName);
	  x.execCommand('italic', false, null); 
	}


	function ordListIt(myName) {
	 setActiveName(myName);
	 x.execCommand('insertorderedlist', false, null); 
	}

	function bulListIt(myName) {
     setActiveName(myName);
	 x.execCommand('insertunorderedlist', false, null); 
	}

	function linkIt(myName) { 
	 setActiveName(myName);
	
		if(navigator.appName == "Netscape") {
			var szURL = prompt("URL (ex. http://www.google.com)", ""); //Mozilla doensn't support new interface rendering and does not work with safari yet (as of 1.3)
			x.execCommand('createlink',false,szURL); 
		 } else {
			x.execCommand('CreateLink');
		 }
	}

 function selOn(ctrl) {
	ctrl.style.borderColor = '#000000';
	ctrl.style.backgroundColor = '#B5BED6';
	ctrl.style.cursor = 'hand';	
  }
  
  function selOff(ctrl) {
	ctrl.style.borderColor = '#ECE9D8';  
	ctrl.style.backgroundColor = '#ECE9D8';
  }
  
  function selDown(ctrl) {
	ctrl.style.backgroundColor = '#8492B5';
  }
  
  function selUp(ctrl) {
    ctrl.style.backgroundColor = '#B5BED6';
  }


//END OF WY FUNCTIONS



/* Resolution Interactive Media */
/* Developed By: Jonathan Kochis And Brendan Farr-Gaynor */
/* jonathan@teamresolution.com / brendan@teamresolution.com */



//Resolution Multi-Selector functions

function addToList(listField, newText, newValue) {
if ( ( newValue == "" ) || ( newText == "" ) ) {
alert("You cannot add blank values!");
} else {
var len = listField.length++; // Increase the size of list and return the size
listField.options[len].value = newValue;
listField.options[len].text = newText;

listField.selectedIndex = len; // Highlight the one just entered (shows the user that it was entered) //BUG FIX
} // Ends the check to see if the value entered on the form is empty
}	

function removeFromList(listField) {
if ( listField.length == -1) { // If the list is empty
alert("There are no values which can be removed!");
} else if (listField.options[listField.selectedIndex].text == "") { //If no value is selected
alert("You cannot remove blank values!"); 
} else {
var selected = listField.selectedIndex;
if (selected == -1) {
alert("You must select an entry to be removed!");
} else { // Build arrays with the text and values to remain
var replaceTextArray = new Array(listField.length-1);
var replaceValueArray = new Array(listField.length-1);
for (var i = 0; i < listField.length; i++) {
// Put everything except the selected one into the array
if ( i < selected) { replaceTextArray[i] = listField.options[i].text; }
if ( i > selected ) { replaceTextArray[i-1] = listField.options[i].text; }
if ( i < selected) { replaceValueArray[i] = listField.options[i].value; }
if ( i > selected ) { replaceValueArray[i-1] = listField.options[i].value; }
}
listField.length = replaceTextArray.length; // Shorten the input list
for (i = 0; i < replaceTextArray.length; i++) { // Put the array back into the list
listField.options[i].value = replaceValueArray[i];
listField.options[i].text = replaceTextArray[i];
}
} // Ends the check to make sure something was selected
} // Ends the check for there being none in the list
}


function moveUpList(listField) {
if ( listField.length == -1) { // If the list is empty
alert("There are no values which can be moved!");
} else {
var selected = listField.selectedIndex;
if (selected == -1) {
alert("You must select an entry to be moved!");
} else { // Something is selected 
if ( listField.length == 0 ) { // If there's only one in the list
alert("There is only one entry!\nThe one entry will remain in place.");
} else { // There's more than one in the list, rearrange the list order
if ( selected == 0 ) {
alert("The first entry in the list cannot be moved up.");
} else {
// Get the text/value of the one directly above the hightlighted entry as
// well as the highlighted entry; then flip them
var moveText1 = listField[selected-1].text;
var moveText2 = listField[selected].text;
var moveValue1 = listField[selected-1].value;
var moveValue2 = listField[selected].value;
listField[selected].text = moveText1;
listField[selected].value = moveValue1;
listField[selected-1].text = moveText2;
listField[selected-1].value = moveValue2;
listField.selectedIndex = selected-1; // Select the one that was selected before  //BUG FIX
} // Ends the check for selecting one which can be moved
} // Ends the check for there only being one in the list to begin with
} // Ends the check for there being something selected
} // Ends the check for there being none in the list
}


function moveDownList(listField) {
if ( listField.length == -1) { // If the list is empty
alert("There are no values which can be moved!");
} else {
var selected = listField.selectedIndex;
if (selected == -1) {
alert("You must select an entry to be moved!");
} else { // Something is selected 
if ( listField.length == 0 ) { // If there's only one in the list
alert("There is only one entry!\nThe one entry will remain in place.");
} else { // There's more than one in the list, rearrange the list order
if ( selected == listField.length-1 ) {
alert("The last entry in the list cannot be moved down.");
} else {
// Get the text/value of the one directly below the hightlighted entry as
// well as the highlighted entry; then flip them
var moveText1 = listField[selected+1].text;
var moveText2 = listField[selected].text;
var moveValue1 = listField[selected+1].value;
var moveValue2 = listField[selected].value;
listField[selected].text = moveText1;
listField[selected].value = moveValue1;
listField[selected+1].text = moveText2;
listField[selected+1].value = moveValue2;
listField.selectedIndex = selected+1; // Select the one that was selected before //BUG FIX
} // Ends the check for selecting one which can be moved
} // Ends the check for there only being one in the list to begin with
} // Ends the check for there being something selected
} // Ends the check for there being none in the list
}


function submitBuckets(textfieldName, listField1) {
var len1 = listField1.length;
var buck1 = "";


for(i=0; i<len1; i++){
	buck1 += listField1.options[i].value;
}


document.getElementById(textfieldName).value = buck1.substring(1);
//alert(buck1);


}

//End Of Multi-Selector functions
