/*---------------------------------------------------------------'				*/
/*/ Copyright 2004, Engineering and Physical Engineering Research Council.				*/
/*/ EPSRC retains the Intellectual Property Rights to the code.					*/
/*/---------------------------------------------------------------'				*/
/*/<summary>Class used to provide external common javascript functions</summary> */
/*/<remarks></remarks>*/
/*/<summary>Used to change Unicode string to cleartext and update the textbox properties</summary>*/
/*/<param name="txtLink">webcontrol textbox which is modified to behave like a mailto Hyperlink</param>*/
			function decrypttxt(txtLink)
			{
				try
				{				
					//this is made lowercase then any mailto: prefix is removed,  the Unicode in the string is unaffected
					var sinput = txtLink.value.toLowerCase();
					
					//if the SMTP has already been decrypted then dont decrypt again
					if (sinput.search(/@/) != -1)
					{
						ilen = sinput.length;
					}
					else					
					{

						sinput = sinput.replace(/mailto:/,'');
						var soutput = '';
						ilen = sinput.length/3;
						//parse the string into chunks of three characters at a time and translate into cleartext
						for (i = 1; i <= ilen; i++)
						{
							ipos = (i*3) -3;
							sCharCode = sinput.substr(ipos,3);
							if (sCharCode.length == 3)
							{
								//make the conversion to cleartext one chunk of three characters at a time
								sChar = String.fromCharCode(sCharCode);
								soutput =soutput + sChar;
							}
							else
							{
								//this will display an error if the textbox has not been correctly setup
								alert('error detected, source unicode string is invalid');
							}
						}
						//update the txtLink.text value
						txtLink.value=soutput;
					}
					//Set the width of the textbox in ex units according to the browser

					var browser=navigator.appName;
					if (browser=="Microsoft Internet Explorer")
					{
						ilen=ilen + 4 +  parseInt(ilen/6); 
					}
					else if (browser=="Netscape")
					{
						var sBrowserUserAgent = navigator.userAgent ;
						iFirefoxPosition = sBrowserUserAgent.search(/Firefox/);
						if (parseInt(iFirefoxPosition)!=-1)	
						{
							ilen=ilen + 4 +  parseInt(ilen/7);
						}
						else
						{
							ilen=ilen + 3 + parseInt(ilen/6);
						}
					}
					else if (browser=="Opera")
					{
						ilen=ilen + 5 +  parseInt(ilen/4.8);
					}
					else
					{
						ilen=ilen + 4 +  parseInt(ilen/6);
					}
					txtLink.style.width=ilen+'ex';
					
				}
                catch (err)
                {
					txt="There was an error setting the mailto hyperlink.\n\n";
					txt+="Error description: " + err.description + "\n\n";
					txt+="Click OK to continue.\n\n";
					//alert(txt);
					window.status=err.description;
                }
			}

//<summary>Used to open a mail window</summary>
//    '''<param name="sSMTP">email address</param>
//    '''<returns></returns>
//    '''<remarks></remarks>

			function sendto(sSMTP)
			{
				window.open('mailto:'+sSMTP);
			}

//<summary>Used to open a mail window on error</summary>
//    '''<param name="sSMTP">sError</param>
//    '''<returns></returns>
//    '''<remarks></remarks>
			function senderrorto(sSMTP, sError)
			{
			sError = encodeURI('A Grants on the web application error has been discovered, application error message follows:'+sError)
				window.open('mailto:'+sSMTP+'&Subject='+encodeURI('A Grants on the Web Error has been discovered')+'&body='+sError);
			}
//<summary>Used to width and focus of the customised text boxes in progresscheck.aspx</summary>
//    '''<returns></returns>
//    '''<remarks></remarks>


			function setCtlSizes()
			{

				try
				{				



					//set the focus depending upon which textbox is populated, default to EP format
					var txtGR = document.getElementById("txtPartBGR").value;
					var txtDT = document.getElementById("txtPartBDT").value;
					var txtTS = document.getElementById("txtPartBTS").value;
					var txtEP = document.getElementById("txtPartBEP").value;
				
					if (txtGR !='')				{
						document.getElementById("txtPartBGR").focus();
						document.getElementById("txtPartBGR").select();
					}
					else if (txtDT !='')				{
						document.getElementById("txtPartBDT").focus();
						document.getElementById("txtPartBDT").select();
					}
					else if (txtTS !='')				{
					    document.getElementById("txtPartBTS").focus();
						document.getElementById("txtPartBTS").select();
					}
					else
					{	document.getElementById("txtPartBEP").focus();
						document.getElementById("txtPartBEP").select();
					}


//					//set the width properties of the EP format text input control
//					//it is done this way to ensure identical rendering in all browser versions

					//set the width properties of the TS text input control
					document.getElementById("lblPartATS").style.width="30px";
					document.getElementById("tdPartATS").style.width="30px";
					document.getElementById("txtPartBTS").style.width="60px";
					document.getElementById("tdPartBTS").style.width="60px";
					document.getElementById("lblPartBTSSeparator").style.width="10px";
					document.getElementById("tdPartBTSSeparator").style.width="10px";
					document.getElementById("txtPartCTS").style.width="20px";
					document.getElementById("tdPartCTS").style.width="20px";



					document.getElementById("lblPartAEP").style.width="30px";
					document.getElementById("tdPartAEP").style.width="30px";
					document.getElementById("txtPartBEP").style.width="60px";
					document.getElementById("tdPartBEP").style.width="60px";
					document.getElementById("lblPartBEPSeparator").style.width="10px";
					document.getElementById("tdPartBEPSeparator").style.width="10px";
					document.getElementById("txtPartCEP").style.width="20px";
					document.getElementById("tdPartCEP").style.width="20px";


					//set the width properties of the GR format text input control
					document.getElementById("lblPartAGR").style.width="30px";
					document.getElementById("tdPartAGR").style.width="30px";
					document.getElementById("txtPartBGR").style.width="60px";
					document.getElementById("tdPartBGR").style.width="60px";
					document.getElementById("lblPartBGRSeparator").style.width="10px";
					document.getElementById("tdPartBGRSeparator").style.width="10px";
					document.getElementById("txtPartCGR").style.width="20px";
					document.getElementById("tdPartCGR").style.width="20px";

//					//set the width properties of the DT text input control
					document.getElementById("lblPartADT").style.width="30px";
					document.getElementById("tdPartADT").style.width="30px";
					document.getElementById("txtPartBDT").style.width="60px";
					document.getElementById("tdPartBDT").style.width="60px";
					document.getElementById("lblPartBDTSeparator").style.width="10px";
					document.getElementById("tdPartBDTSeparator").style.width="10px";
					document.getElementById("txtPartCDT").style.width="20px";
					document.getElementById("tdPartCDT").style.width="20px";



				}
                catch (err)
                {
					txt="There was an error setting the textbox properties.\n\n";
					txt+="Error description: " + err.description + "\n\n";
					txt+="Click OK to continue.\n\n";
					alert(txt);
                }

			}


//<summary>Used to set an element width to 100% if the window width less than vsize</summary>
//    '''<param name="vId">Id of the element</param>
//    '''<returns></returns>
//    '''<remarks></remarks>

			function setWidthIfHiRes(vId, vsize)
			{
				var tcontrol = document.getElementById(vId);  
						if( tcontrol != null ) 
						{
							iWidth=document.body.clientWidth;
							if (iWidth < vsize ) 
							{
						        document.getElementById(vId).style.width='100%';
    						}
                            else
							{
						        document.getElementById(vId).style.width=vsize+'px';
    						}
                            
						}
			}

			function changetext() 
			{
			    if (document.getElementById('lblPanelName') == null)
			        document.getElementById('Message').innerHTML = '<p style="font-weight:bold">This proposal has been reassigned to a panel which has not yet taken place.</p>';
			}

