
// CMS functions
// PAWhite 1st September 2005
//
	
	var focusField;		// page variable to store the first "failed" validation
	
function viewStatus(caseRef, category, now, mode)

	{
		openModalWindow('trackingEvent.aspx?caseref=' + caseRef + '&category=' + category + '&now=' + now + '&mode=' + mode,'','')
	
	}
	
//	function to show help pop-up in cms
function openWindow(url, options, frameName)

	{
		if (options == '') options = "width=400,height=250,resizable=no,scrollbars=no" ;
		
		window.open(url,frameName,options);
	}

	function OpenNewWindow(url, name, width, height)
	{
	    // Fudge factors for window decoration space.
	    // In my tests these work well on all platforms & browsers.
	width += 32;
	height += 96;
	var win = window.open(url,
	name, 
	'width=' + width + ', height=' + height + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=yes, resizable=no');
	win.resizeTo(width, height);
	win.focus();
	}

	
function openModalWindow(url, options, frameName)

	{
			
		if (window.showModalDialog) {
			if (options == '') options = "dialogWidth:600px;dialogHeight:450px;" ;
			window.showModalDialog(url,frameName,options);
		} 
		else {
			if (options == '') options = "width=600,height=450,resizable=no,scrollbars=no" ;
			window.open(url,frameName,options);
		}
	} 

function fnShowHelp(id)

	{
		var out = "help.aspx?hidemenu=true&item=" + id;
		var newwindow;
		newwindow=window.open(out,"sphelp","width=600,height=450,resizable=no,scrollbars=yes");
		if (window.focus) {newwindow.focus()}
	}

function fnRePrint(id,pdfonly,text)

	{
		// and start new page
		var out = "reprint.aspx?hidemenu=true&caseref=" + id + "&pdfonly=" + pdfonly + "&text=" + text;
		var newwindow;
		newwindow=window.open(out,"spreprint","width=600,height=300,resizable=no,scrollbars=no");
		// wait 1 second and  - redirect the current page
		setTimeout("",1000);
		location.href="adminhome.aspx";
		// and change focus to the new pop up window
		if (window.focus) {newwindow.focus()}
		
	}

function fnQuote(id,buyerseller)

	{
		// and start new page
		// wv 2007-10-22 removed quoteredirect page, no longer used
		// left this function for future reference
		//var out = "quoteRedirect.aspx?hidemenu=true&caseref=" + id + "&buyerseller=" + buyerseller;
		//var newwindow;
		//newwindow=window.open(out,"spquote","width=1000,height=600,resizable=yes,scrollbars=yes");
		// no action - just stay on this page
		// but do change focus to the new pop up window
		//if (window.focus) {newwindow.focus()}
		
	}

function fnViewCase(out)

	{
		var myindex  = document.Files.drpCases.selectedIndex
		if (myindex == '-1') {
			alert('Please select a case')
		}

		var selvalue = 'caseDetails.aspx?action=view&caseref=' + document.Files.drpCases.options[myindex].value + '&hidemenu=true'
		// if nothing selected it fails here
		var newwindow;
		newwindow=window.open(selvalue,"spViewCase","width=1100,height=600,resizable=yes,scrollbars=yes");
		if (window.focus) {newwindow.focus()}
	}


function fnViewDocument(out)

	{
		var myindex  = document.frmForm.drpArchive.selectedIndex
		if (myindex == ' ') {
			alert('Please select a document')
		}
		else
		{
		var selvalue = 'ProcessDoc.aspx?Document=' + document.frmForm.drpArchive.options[myindex].value
		// if nothing selected it fails here
		var newwindow;
		newwindow=window.open(selvalue,"HIPdocument","width=1100,height=800,resizable=yes,scrollbars=yes");
		if (window.focus) {newwindow.focus()}
		}
	}

//	function to set the visibility of a page item
	function showhide(sItem, sStatus)

	{ 
		eval("document.all." + sItem + ".style.display=" + "'" + sStatus + "';");
	}
     
//	function to set focus to a field on a form	
	function putFocus(formInst, elementInst) {


      //DLD 8/7/08 Added try..catch as it was failing on setting focus to a radiobuttongroup        
	  if (document.forms.length > 0) {
	  try {
           document.forms[formInst].elements[elementInst].focus();
       }
        catch(err) {
       }
 	  focusField=elementInst
	  }
	}             
	
// function to validate a form using the show/hide Error Div //
	function validateForm()
	{
	
		if (window.loaded != true)
		{
			return false;
		} 
		else 
		{ 
			Page_ClientValidate();
			if (Page_IsValid)
			{
				showhide('divError', 'none');
			}
			else
			{ 
				document.getElementById('drpSellerTitle').style.display = 'none';
				showhide('divError', 'inline')
				setValidateFocus() ;
			} 
		}
	}
	
	function setValidateFocus() 	
	{	
	
		var first = -1
		
		for (i=0; i < Page_Validators.length; i++)
		{
			if (!Page_Validators[i].isvalid) {
			
					var first = i;
					var focusfield = Page_Validators[i].controltovalidate
					break;
				
			}				
		}
		
		if (first != -1) {
			putFocus(0, Page_Validators[first].controltovalidate);
		}
	
	}
	
	function closeErrors()
	{
		showhide('divError', 'none'); 
		
		var focus = "putFocus(0,'" + focusField + "');" ;
		eval(focus);
		
	}
	
    function loadCase(elName)
    {
        el=document.getElementById(elName);
        if (el)
            {
               document.location.href='casehistory.aspx?caseref='+el.value+'&usingmenu=internaladmin';        
            }
    }


