	var detailedError = "";


	function ConfirmAuditLoad(sender){

		if(Confirmfn('Please confirm load of audit item'))
		{
			var URL = sender.options[sender.selectedIndex].value;
			window.location = (URL);
		}
		else
		{
			sender.selectedIndex = 0 ;
		}
 	}

	
	function getDetailedError(){

		alert(detailedError)
   		//creatediv("error", detailedError, 200, 300, 200, 200, 200)
		
	}

	function checkUrlforHTTP(ctrl){

		var txt = ctrl.value		
		if(txt.substring(0,7) == "http://")
		{
			
		}


	}


	function creatediv(id, html, width, height, left, top) { 

		var newdiv = document.createElement('div');
		newdiv.setAttribute('id', id);
	   
		if (width) {
		newdiv.style.width = 300;
		}
	   
		if (height) {
		newdiv.style.height = 300;
		}
	   
		if ((left || top) || (left && top)) {
		newdiv.style.position = "absolute";
	       
		if (left) {
		newdiv.style.left = left;
		}
	       
		if (top) {
		newdiv.style.top = top;
		}
		}
	   
		newdiv.style.background = "#00C";
		newdiv.style.border = "4px solid #000";
		   
		if (html) {
		newdiv.innerHTML = html;
		} else {
		newdiv.innerHTML = "nothing";
		}   
		document.body.appendChild(newdiv);
	} 
	
	function CategoryManagement(sectionId, isdefault, PrimaryCategoryId)		
	{
	
		var url = "CategoryManagement.aspx?SectionId=" + sectionId + '&isdefault=' + isdefault + '&PrimaryCategoryId=' + PrimaryCategoryId
	
		try
		{
			if(!winCM.closed){
				winCM.focus();
				return false;
			}
	
			else
			{
				winCM = window.open(url,'w_tttlu','toolbar=0,menubar=0,location=0,status=0,height=610,width=720') ;
				winCM.w_tttnew = parent;  /* allow window to refer to this window */
				winCM.currentSelection = getSelection();   /* int value  */
				winCM.tnt_code = 'NTRS';  /* char value */
				return false;
			}
	
		}
		catch(e)
		{
			winCM = window.open(url,'w_tttlu','toolbar=0,menubar=0,location=0,status=0,height=610,width=720') ;
			
		}
	
	return false;
	}

	function isDuplicateFile(Filenames){

		fileAlreadyExists = false;

		var specifiedFilename = document.getElementById("txtSaveAs").value
		var existingFilenames = new String(Filenames);
		var arrExistingFilenames = existingFilenames.split(",");
	
		// check for a match in filename
		var arrLen = arrExistingFilenames.length;
		for(var i=0; i<arrLen; i++)
		{
			if(arrExistingFilenames[i] == specifiedFilename)
			{
				fileAlreadyExists = true;
				break;
			}
		}

		// first check all required fields are set
		if(CheckForm(arrRqdDocuments))
		{
			if(fileAlreadyExists)
			{
				return Confirmfn("A  file with the name specified already exists, choose ok to overwrite existing file or cancel.");
			}

			return  true;
		}
		
		return false;
	}
//-------------------------------------------------------------------
//	File Selector Specific
	//-------------------------------------------------------------------

function selectFile(id, targetCtrl) {
    //For Transaction (Auto Update and select from server call)
   
    try {
        var txtVal = document.getElementById('logos_txtVal')
        txtVal.value = id.toString();
        
        __doPostBack('logos_btn_refresh', 'OnClick');
    }
    catch (e) {
        //For all other pages
        var ctrl = document.getElementById(targetCtrl);
        for (var i = 0; i < ctrl.options.length; i++) {
            testval = ctrl[i].value;
            if (testval == id) {
                ctrl[i].selected = true;
                found = true;
            }
        }
    }
			
}








function viewDocuments(targetCtrl) {

	try{

	//check window is not already open and just lost focus

	//window is open just set focus to it
	if(!winDocuments.closed){
		winDocuments.focus();
	}
	
	//window closed, continue as usual and open new window
	else{
		winDocuments = window.open('documents.aspx?docSelection=true&targetCtrl=' + targetCtrl,'w_tttlu','toolbar=0,menubar=0,location=0,status=0,height=610,width=720') ;
		winDocuments.w_tttnew = parent;  /* allow window to refer to this window */
		winDocuments.currentSelection = getSelection();   /* int value  */
		winDocuments.tnt_code = 'NTRS';  /* char value */
	}
	}catch(e){
		winDocuments = window.open('documents.aspx?docSelection=true&targetCtrl=' + targetCtrl,'w_tttlu','toolbar=0,menubar=0,location=0,status=0,height=610,width=720') ;
		
		winDocuments.w_tttnew = parent;  /* allow window to refer to this window */
		winDocuments.currentSelection = getSelection();   /* int value  */
		winDocuments.tnt_code = 'NTRS';  /* char value */

	}

}


	//Sets the selected value of a select Box by value (not index)
	function SetSelectedValue(ctrlSelect, Selectvalue){
		var ControlToSearch = document.getElementById(ctrlSelect)
		for (i = 0; i < ControlToSearch.length; i++){
			if (ControlToSearch[i].value == Selectvalue){
				ControlToSearch.options.selectedIndex =	i;
			}
		}				
	}

	//Gets the selected value of a select Box
	function GetSelectedValue(ctrlSelect){
		var ControlToSearch = document.getElementById(ctrlSelect)
		var selectedItemId = ControlToSearch.options[ControlToSearch.options.selectedIndex].value	
		return selectedItemId;
	}

	//enables or disables a specified listbox depending if any items are selected in another specific listbox
	function Control_Update_EnabledStatus(ctrl, value){
		if(value.length > 0){
			document.getElementById(ctrl).disabled=false;
		}else{
			document.getElementById(ctrl).disabled=true;
		}
	}

	//gets and returns the selected items of a listbox as an array
	function GetSelections(ctrl, forDB){

		var ControlToSearch = document.getElementById(ctrl)
		var arrSelections = new Array()

		for (i = 0; i < ControlToSearch.length; i++){
			if (ControlToSearch[i].selected){
				arrSelections.push(ControlToSearch[i].value)
			}
		}	
		
		//check if results are for DB as DB accepts a space as delimiter
		//if not for DB, other functions require an array of selected items.

		if(!forDB){
			return arrSelections;		
		}else{
			//setup Paramters
			strSelections = new String(arrSelections.toString())

			//remove commas as database accepts space as delimiter
			strSelections = strSelections.replace(/,/g," ")
			
			return strSelections
		}
	}

	//Unselect all items in a specifiec listbox
	function UnSelectListBoxItems(ctrl){
		var ControlToSearch = document.getElementById(ctrl)

		//check control exists first
		if(ControlToSearch != null){
			for (i = 0; i < ControlToSearch.length; i++){
				if (ControlToSearch[i].selected){
					ControlToSearch[i].selected=false;
				}
			}
		}
	}

	//Disabled a control
	function DisableControl(ctrl){
		var ControlToSearch = document.getElementById(ctrl)
		ControlToSearch.disabled = true;
	}

	//Gets the selected value of a select Box
	function GetSelectedValue(ctrlSelect){
		var ControlToSearch = document.getElementById(ctrlSelect)
		var selectedItemId = ControlToSearch.options[ControlToSearch.options.selectedIndex].value	
		return selectedItemId;
	}

	//emabled or disables a specified listbox depending if any items are selected in another specific listbox
	function Control_Update_EnabledStatus(ctrl, value){
		if(value.length > 0){
			document.getElementById(ctrl).disabled=false;
		}else{
			document.getElementById(ctrl).disabled=true;
		}
	}

	//fires a dialog (div) with information, if calling from a list selection the  
	//existing list selection value can be passed to the Ajax call.
	function LoadDialog(e, DialogType, ctrlforResults, currentValue) {
		var posx = 0;
		var posy = 0;
	
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) 	{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			posx = e.clientX + document.body.scrollLeft
				+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop
				+ document.documentElement.scrollTop;
		}
		
		var Holder;
	
		switch(DialogType){
			case 1:
				Holder='LibraryHolder'
				width='585';							
				setLayerPosition(Holder, posx, posy, width)
				AJAX_Library_Get_All(currentValue);
		}	
		
	}
	
	function setLayerPosition(ctrl, x, y, width){
		//check if doesn't overflow window
		if((x + 600) > getWindowWidth()){
			x = (getWindowWidth()/2 - (width/2))
		}

		ctrlToPosition = document.getElementById(ctrl);
		ctrlToPosition.style.display='block';
		ctrlToPosition.style.left=x;
		ctrlToPosition.style.top=y;
	}

	function getWindowWidth() {
		if (document.all){
			return document.body.clientWidth;
		}
		else
			return window.innerWidth
	}


	//clears a control
	function ClearControl(Ctrl, formName){
	var targetCtrl = document.getElementById(Ctrl)

		if(targetCtrl.type == "text"){
			targetCtrl.value = '';
		}
		else if(targetCtrl.type == "checkbox"){	
			targetChk = eval('document.' + formName + '.' + Ctrl)

			var retArr = new Array();
			var lastElement = 0;
			// if the button group is an array (more than 1 one check box)
			if (targetChk.length > 1) { 
				for (var i=0; i<targetChk.length; i++) {
					if (targetChk[i].checked) {
						targetChk[i].checked = false
				         }
			      }
			} 
			// only one check box 
			else { 
				if (targetChk.checked) { 
					targetChk.checked = false
				}
			}
			return retArr.toString();
		}
	
		else if(targetCtrl.type == "select-one"){	
			targetCtrl.options.selectedIndex = -1
		}
	}
	
//-------------------------------------------------------------------
//	EDC Specific  
//-------------------------------------------------------------------

function CheckTextFieldFirstUsage(ctrl, initialMsg){

	var fieldtxt = ctrl.value.toLowerCase();

	if(fieldtxt.toLowerCase() == initialMsg.toLowerCase()){
		ctrl.value = "";
		ctrl.className="UnselectedField";
	}

}

function getValue(Ctrl, formName){

	var targetCtrl = document.getElementById(Ctrl)
	var returnValue = "";

	if(targetCtrl.type == "text"){
		returnValue = encodeURIComponent(targetCtrl.value);
	}
	else if(targetCtrl.type == "checkbox"){	
		targetChk = eval('document.' + formName + '.' + Ctrl)

		var retArr = new Array();
		var lastElement = 0;
		// if the button group is an array (more than 1 one check box)
		if (targetChk.length > 1) { 
			for (var i=0; i<targetChk.length; i++) {
				if (targetChk[i].checked) {
					retArr.length = lastElement;
					retArr[lastElement] = targetChk[i].value;
					lastElement++;
			         }
		      }
		} 
		// only one check box 
		else { 
			if (targetChk.checked) { 
				retArr.length = lastElement;
				retArr[lastElement] = 0; 
			}
		}
		return retArr.toString();
	}
	else if(targetCtrl.type == "radio"){	

		var radioLength = targetCtrl.length;
		alert(radioLength)
		if(radioLength == undefined)
			if(targetCtrl.checked)
				returnValue = targetCtrl.value;
			else
				return "";
		for(var i = 0; i < radioLength; i++) {
			if(targetCtrl[i].checked) {
				returnValue = radioObj[i].value;
			}
		}
	}
	else if(targetCtrl.type == "select-one"){	
		returnValue = targetCtrl.options[targetCtrl.options.selectedIndex].value	
	}

	return returnValue;
}


function selectAll(chkAll, chkTarget, formName){
	var masterCtrl = eval('document.' + formName + '.' + chkAll)

	var returnValue = "";
	chkTarget = eval('document.' + formName + '.' + chkTarget)
	if(masterCtrl.checked){
		// if the button group is an array (more than 1 one check box)
		if (chkTarget.length > 1) { 
			for(var i=0; i< chkTarget.length;i++){
				chkTarget[i].checked = "true"
			}
		}else{
			chkTarget.checked = true
		}
	}else{
		if (chkTarget.length > 1) { 
			for(var i=0; i< chkTarget.length;i++){
				chkTarget[i].checked = false
			}
		}else{
			chkTarget.checked = false;
		}
	}
}




function getChkRdValue(Ctrl, formName){

try{
	targetChk = eval('document.' + formName + '.' + Ctrl)
}catch(e){
	return -1
}	
	var retArr = new Array();
	var lastElement = 0;
	// if the button group is an array (more than 1 one check box)
	
	if (targetChk.length > 1) { 
		for (var i=0; i<targetChk.length; i++) {
			if (targetChk[i].checked) {
				retArr.length = lastElement;
				retArr[lastElement] = targetChk[i].value;
				lastElement++;
		         }
	      }
	} 
	// only one check box 
	else { 
		if (targetChk.checked) { 
			retArr.length = lastElement;
			retArr[lastElement] = 0; 
		}
	}
	

	
	return retArr.toString();
}


function getChkRdValueBoolean(Ctrl, formName){
	targetChk = eval('document.' + formName + '.' + Ctrl)
	

	if(targetChk.checked){
		return 'true';
	}else{
		return 'false'
	}
}









function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getChkssValue(buttonGroup, form) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
alert(buttonGroup.length)
   var lastElement = 0;
   if (buttonGroup.length > 1) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function

//-------------------------------------------------------------------
//	END EDC Specific  
//-------------------------------------------------------------------


//-------------------------------------------------------------------
//	Generic 
//-------------------------------------------------------------------


	function Confirmfn(confirmMsg){
		if(!(confirm(confirmMsg))){
			return false;
		}else{
			return true;
		}
	}

	//checks a checkbox ticked status
	function isChecked(ctrl){
		var ctrlToCheck = document.getElementById(ctrl.id)
		if(ctrlToCheck.checked == true){
			return true;
		}
		return false;
	}



//-------------------------------------------------------------------
//	Login Page
//-------------------------------------------------------------------



//-------------------------------------------------------------------
//	Login Page
//-------------------------------------------------------------------

	function SelectInitialField(ctrlEmail, ctrlPwd){
		field1 = document.getElementById(ctrlEmail)
		field2 = document.getElementById(ctrlPwd)
	
		if(field1.value.length > 0){
			field2.focus();
		}else{
			field1.focus();
		}
	}
	
	
//-------------------------------------------------------------------
//	End Login Page
//-------------------------------------------------------------------



	function ShowElement(ctrl){
		document.getElementById(ctrl).style.display='block'
	}

	function HideElement(ctrl){
		document.getElementById(ctrl).style.display='none'
	}

	function getFilename(ctrl){
		var fileCtrl = document.getElementById(ctrl);
		var strPath = fileCtrl.value;
		
		//var a= strPath.lastIndexOf('\\'); 
		//var strPathLength = strPath.Length 
		//var filename = strPath.substring(a+1, strPathLength) 

		var strPathArray = strPath.split("\\");
		var fileName = strPathArray[strPathArray.length-1];

		return fileName;
	}

	function getDescriptionFromFilename(ctrl){
		var fileCtrl = document.getElementById(ctrl);
		var strPath = fileCtrl.value;		
		var filename;		

		strPath = strPath.replace(/^\s|\s$/g, "");

	            if (/\.\w+$/.test(strPath)) {
	                var x = strPath .match(/([^\/\\]+)\.(\w+)$/);	                
			filename = x[1]
	            } else {
	                var x = strPath .match(/([^\/\\]+)$/);
			filename = x[1]
	                
	            }
		return filename;
	}

	function setElementValue(newValue, ctrl){
		var elementCtrl = document.getElementById(ctrl)
		elementCtrl.value = newValue;
	}



//-------------------------------------------------------------------
//	AddressBook 
//-------------------------------------------------------------------


	function checkNode(currChk, NodeId){	
		var elementToCheck = document.getElementById(NodeId)

		//if a parent node has been clicked and it's child is hidden show its child node
		if(elementToCheck.style.display == 'none'){
			elementToCheck.style.display = 'block'
		}else{
			//hide it's child nodes
			elementToCheck.style.display = 'none';

			//Iteratively deselect all further parent / child nodes for current deslected parent Node.		
			UpdateChildNodes(elementToCheck)			
		}
	}

	function UpdateChildNodes(parentNode){		
		//scan through all child controls and check for any checked checkboxes, 
		//if found uncheck them.
		for(var i=0; i<parentNode.childNodes.length;i++){			
			var currentNode = parentNode.childNodes[i];
			if (!currentNode.tagName) { continue; }
			//found a checkbox
			if(currentNode.tagName.toLowerCase() == 'input'){ 
				//if checked uncheck it
				if(currentNode.checked){
					currentNode.checked = false;
				}				
			}
			//check for div containing further parent/child nodes, iteratively check for further parent / child relationships
			if(currentNode.tagName.toLowerCase() == 'div'){ 
				currentNode.style.display = 'none';
				UpdateChildNodes(currentNode)
			}
		}
	}










//******************************************************
//
//	Used in orering items
//
//******************************************************





		function MoveItem(Direction, ctrl){
			//1: Up  
			//-1: Down			
			//index value of 0 = 1st

			//get control
			var TargetCtrl = document.getElementById(ctrl)
			var selectedIndex = TargetCtrl.options.selectedIndex
			var selectedTeamLocaleId = TargetCtrl.options[selectedIndex].value	
			var LastItemIndex = TargetCtrl.length-1;
			
			switch(selectedIndex){
				case 0:			
					//first Item - can't move item up
					if(Direction != -1){
						//check list does not contain only 1 item
						if(TargetCtrl.length != 1){
							//Move item down
							SwapValues(0, Direction, ctrl)
							
						}else{
							alert('This item cannot be moved down as there is only 1 item in the list')
						}
												
					}else{
						alert('This item can only be moved down the list')
					}	
					break;
				case LastItemIndex:
					//first Item - can't move item down
					if(Direction != 1){
						//check list does not contain only 1 item
						if(TargetCtrl.length != 1){
							//Move item down
							SwapValues(selectedIndex, Direction, ctrl)
							
						}else{
							alert('This item cannot be moved up as there is only 1 item in the list')
						}
												
					}else{
						alert('This item can only be moved up the list')
					}	
					break;
				default:			
					//Any item between first and last - can move up or down
					//check list does not contain only 1 item
					if(TargetCtrl.length != 1){
						//Move item 
						SwapValues(selectedIndex, Direction, ctrl)
						
					}else{
						alert('This item canno be moved down as there is only 1 item in the list')
					}
					break;
			}
			
		}
		function SwapValues(currentIndex, Direction, ctrl){
			var TargetCtrl = document.getElementById(ctrl);
			var selectedValue = TargetCtrl.options[TargetCtrl.options.selectedIndex].value
			var selectedText = TargetCtrl.options[TargetCtrl.options.selectedIndex].text
			var destinationValue = TargetCtrl.options[TargetCtrl.options.selectedIndex + Direction].value							
			var destinationText = TargetCtrl.options[TargetCtrl.options.selectedIndex + Direction].text							
			var TempValue = "";
			var TempText = "";

			//swap values
			TempValue = selectedValue;
			TempText = selectedText;

			TargetCtrl.options[currentIndex].value = destinationValue
			TargetCtrl.options[currentIndex].text = destinationText

			TargetCtrl.options[currentIndex + Direction].value = TempValue
			TargetCtrl.options[currentIndex + Direction].text = TempText

			//now select newly moved value
			TargetCtrl.options.selectedIndex = currentIndex + Direction;

			//reinitialise buttons
			CheckOptions(ctrl)

		}
		function CheckOptions(ctrl){
			var TargetCtrl = document.getElementById(ctrl)
			var LastItemIndex = TargetCtrl.length-1;
			
			switch(TargetCtrl.options.selectedIndex){
				case 0:			
					//first Item - can't move item up
					document.getElementById('btnUp').disabled=true
					document.getElementById('btnDown').disabled=false
					break;
				case LastItemIndex:
					//Last Item - can't move item down			
					document.getElementById('btnUp').disabled=false
					document.getElementById('btnDown').disabled=true
					break;
				default:			
					//Any item between first and last - can move up or down
					document.getElementById('btnUp').disabled=false
					document.getElementById('btnDown').disabled=false
					break;
			}
		}
		function getNewOrder(ctrl){
			var TargetCtrl = document.getElementById(ctrl)
			var newOrder = "";
			for(var i=0; i<TargetCtrl.length;i++){
				newOrder += TargetCtrl.options[i].value + ','
			}
			return newOrder;

}




/*Popup Window
var newwindow;
function poptastic(url, height, width, top, left) {
    newwindow = window.open(url, 'name', 'height=' + height + ',width=' + width + ',scrollbars=no,top=' + top + ',left=' + left + ',location=false,toolbar=false,menubar=false');
    if (window.focus) { newwindow.focus() }
}*/

