/* Resolution Interactive Media */
/* Developed By: Jonathan Kochis And Brendan Farr-Gaynor */
/* jonathan@teamresolution.com / brendan@teamresolution.com */


/****************************** RESOLUTION MASTER AJAX FUNCTIONS ***********************************/

/*
The following are global functions to be used with all new AJAX activity, some applications require thier
own AJAX functions but these should cover the majority.
*/


function resCreateRequestObject() {
    var masterRO;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        masterRO = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        masterRO = new XMLHttpRequest();
    }
    return masterRO;
}



var reshttp = resCreateRequestObject();
var resAJAXRequestStarted = false;

function resSndReq(queryStringToSend, whatFunctionToRun) {
	if(!resAJAXRequestStarted) {
		   resAJAXRequestStarted = true;
		   var functionToSend = whatFunctionToRun;
		   reshttp.open('get', queryStringToSend, true);
		   reshttp.onreadystatechange = function() {
				//data is loaded
					if (reshttp.readyState == 4) {
						resAJAXRequestStarted = false;
						
						var resResponse = reshttp.responseText;
						var arrayToSendBack = new Array();
				
						if(resResponse.indexOf('|' != -1)) {
							
							arrayToSendBack = resResponse.split('|');
							eval(functionToSend + "(arrayToSendBack);");
							
						}
					}
				
			// end of data loaded
			 }
			 
			reshttp.send(null);
	}
}


/************************** END OF RESOLUTION MASTER AJAX FUNCTIONS ***********************************/




/************************** RESOLUTION MASTER WYSIWYG FUNCTIONS ***********************************/

function confirmDownloadDelete(loc) {
		if(confirm("You are about to permanently delete this file. Are you sure you want to do this?")) {
			window.location = loc;
		}
	}


function confirmDelete(loc) {
		if(confirm("Are you sure you would like to delete this listing?")) {
			window.location = loc;
		}
	}
	

var x = null;
var xSet = false;
var IEFlag = 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");
		IEFlag = true;
		x = eval(nameToSet + ".document"); //iView.document;
	
	}	
	
}


function cleanWordHTML() {
	//ugh, well here it is, 
	//this should only be run if the user pastes something in and they are using IE
	//we must run the content off the clipboard through this puppy to deal with the 
	//possibility of Word HTML which will almost always break a layout
	
	html = window.clipboardData.getData('Text'); 
	window.clipboardData.setData('Text', html.replace(/<!(?:--[\s\S]*?--\s*)?>\s*/g,''));
}


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';
		
		
		//BUGFIX 08/14/06 brendan@resolutionim.com
		//users seem to copy from word *a lot* so a call to clean out word
		//formatting before stuff was copied in is necessary, this will likely only work in IE
		if(IEFlag) {
			x.body.attachEvent("onbeforepaste", cleanWordHTML);
		}
		
		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 supIt(myName) {
	setActiveName(myName);
	x.execCommand('superscript', false, null); 
	}
	
	function subIt(myName) {
		setActiveName(myName);
		x.execCommand('subscript', false, null); 
	}

	
	function blockChange(myName, selectname) {
	  setActiveName(myName);
	  
	  var cursel = document.getElementById(selectname).selectedIndex;
	  /* First one is always a label */
	  if (cursel != 0) {
		  
		var selected = document.getElementById(selectname).options[cursel].value;
		document.getElementById(myName).contentWindow.document.execCommand('formatblock', false, selected);
		document.getElementById(selectname).selectedIndex = 0;
	  }
	  document.getElementById(myName).contentWindow.focus();
	}
		
	
	
	function linkIt(myName) { 
	 setActiveName(myName);
	 //BUG FIX, IE had issues putting the content in the proper location if a prelim focus was not set, this works in both IE and Mozilla
	 document.getElementById(myName).contentWindow.focus();
	
		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 unlinkIt(myName) {
		setActiveName(myName);
		x.execCommand('unlink', false, null); 
	}
	
  	
	function alignIt(myName, myAction) {
	 	setActiveName(myName);
		
		var whatActionToCall = 'justify' + myAction;
		
	 	x.execCommand(whatActionToCall, false, null); 
  	}

	function indentIt(myName, myAction) {
	 	
		setActiveName(myName);
		x.execCommand(myAction, false, null); 
  	}
	

 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 RESOLUTION MASTER WYSIWYG 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


function submitDateItem(textfieldName, prefix) {
	//submitDateItem('itemDateTimeEnd', 'ed');
	
	day = document.getElementById(prefix + "Day").value;
	month = document.getElementById(prefix + "Month").value;
	year = document.getElementById(prefix + "Year").value;
	hour = document.getElementById(prefix + "Hour").value;
	minute = document.getElementById(prefix + "Minute").value;
	AMPM = document.getElementById(prefix + "AMPM").value;
	
//vvvvvvvvvvvv was setting 08/20 and 09/21 to 12/00	
//	hour = parseInt(hour);
//^^^^^^^^^^^^ was setting 08/20 and 09/21 to 12/00	
	hour = Number(hour);
	needsExtraZero = true;
	
	if(AMPM == "PM") {
		if(hour != 12) {
			hour = hour + 12;
		}
	} else {
		if(hour == 12) {
			hour = '00';
			needsExtraZero = false;
		}
		
	}
	
	
	if(needsExtraZero) {
		if(hour < 10) {
			hour = "0" + hour;	
		}
	}
		
	
	document.getElementById(textfieldName).value = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":00";
	
}

/******************************In Out Board Functions ***********************************/
function inOutCreateRequestObject() {
    var inOut;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        inOut = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        inOut = new XMLHttpRequest();
    }
    return inOut;
}

var httpInOut = inOutCreateRequestObject();
var globalInOutWindow = ""; 
var globalInOutCurUser = "";
var globalInOutStatus = "";

function inOutSndReq(inOutWindow, currentUser, status, message, time) {
	globalInOutWindow = inOutWindow;

	httpInOut.open('get', '/tools/companyDirectory/dirCommon.php?inOutWindow='+inOutWindow+'&currentUser='+
								currentUser+'&status='+status+'&message='+message+'&time='+time);
    httpInOut.onreadystatechange = inOutHandleResponse;
    httpInOut.send(null);
}

function inOutHandleResponse() {
    if(httpInOut.readyState == 4){
        var inOutResponse = httpInOut.responseText;
        var inOutUpdate = new Array();

        if(inOutResponse.indexOf('|' != -1)) {
///*debug*/	alert("Response:"+inOutResponse);
            inOutUpdate = inOutResponse.split('|');
            document.getElementById(inOutUpdate[0]).innerHTML = inOutUpdate[1];
			document.getElementById(inOutUpdate[2]).innerHTML = inOutUpdate[3];
/*errorfix*///document.getElementById(inOutUpdate[4]).innerHTML = inOutUpdate[5];
        }
    }
}

function inOutToggleMe() 
{
	if (document.getElementById('itemInList').style.display == 'none') 
	{
		document.getElementById('itemInList').style.display = 'block';
		document.getElementById('itemOutList').style.display = 'none';
		document.getElementById('btnView').value = 'View Out';
	} 
	else 
	{ 
		document.getElementById('itemInList').style.display = 'none';
		document.getElementById('itemOutList').style.display = 'block';
		document.getElementById('btnView').value = 'View In';

	}
}
function refreshIndexRand() 
{
	setTimeout('window.location.href = "/index.php"', 5 * (60 * 1000));
}

/**************************END In Out Board Functions ***********************************/



