
function sendMessage (title, out, width)
	     {
	          var divide = "";
	          for (i = 0; i < width; i++)
	          {
	               divide += "_";
	          }

	          var top = divide + "\n\n" + title + "\n\n";
	          var bottom = "\n" + divide + "\n\nClick OK to continue. \n";
	          alert (top + out + bottom);
	          return;
	     }	
function trim(_data) {
  return _data.replace(/^\s+|\s+$/g, '');
}				

function Next(navigationmode) 			
			{ 
			var out	= "";	

			var reCapl = /<BR>/gi;
			var reSmal = /<br>/gi;
  			mElement = document.getElementById("td1"); 
			var headertext = mElement.innerHTML.replace(reCapl,"\n").replace(reSmal,"\n");
  			frmpersonalise.headerdata.value = headertext;
  			frmpersonalise.headerfont.value = CboByText(document.getElementById("selFontName"), mElement.style.fontFamily)
  			frmpersonalise.headerfontsize.value = CboByValue(document.getElementById("selFontSize"), mElement.style.fontSize);
  			frmpersonalise.headerfontcolor.value = CboByValue(document.getElementById("selFontColor"), mElement.style.color);


			//out += ((frmpersonalise.headerdata.value!="") && (frmpersonalise.headerdata.value.length>30))?"\t- Please enter a header not exceeding 30 characters. \n":"";			  			
			//out += ((frmpersonalise.messagedata.value!="") && (frmpersonalise.messagedata.value.length>100))?"\t- Please enter a message not exceeding 100 characters. \n":"";			  			
			//out += ((frmpersonalise.signaturedata.value!="") && (frmpersonalise.signaturedata.value.length>30))?"\t- Please enter a signature not exceeding 30 characters. \n":"";			  									

			if (out!= "")
			{
				sendMessage ("Before submitting the form...", out, 50);
				return false;
			}
			frmpersonalise.submit();
		} 




		var SectionNow = null;
		var SignatureNow = null;
		
		function highlightArea(thisSection)
		{		
						
		if (thisSection)
		{
			SectionNow = thisSection;
			
			var strText = trim(SectionNow.innerHTML); 
			
			if(SectionNow.id == "td1")
				{
				div1.style.border = "1px solid #cccccc";
				div2.style.border = "1px solid #999999";
				div3.style.border = "1px solid Navy";
				}
			
			else if(SectionNow.id == "td2")
				{
				div1.style.border = "1px solid #333333";				
				div2.style.border = "1px solid #999999";
				div3.style.border = "1px solid Navy";				
				}
			else if(SectionNow.id == "td3")
				{
				div1.style.border = "1px solid Navy";				
				div2.style.border = "1px solid Navy";				
				div3.style.border = "1px solid Grey";
				}
			
			if(strText == "")
			{
			SectionNow.style.fontFamily = frmpersonalise.selFontName.value;	
			SectionNow.style.fontSize = frmpersonalise.selFontSize.value;				
			SectionNow.style.color =  frmpersonalise.selFontColor.value;							
			
			if(SectionNow.style.fontSize =="10pt")
					SectionNow.style.lineHeight = "10pt";		  			
			if(SectionNow.style.fontSize =="12pt")
					SectionNow.style.lineHeight = "12pt";		  			
			if(SectionNow.style.fontSize =="14pt")
					SectionNow.style.lineHeight = "14pt";		  			
			if(SectionNow.style.fontSize =="16pt")
					SectionNow.style.lineHeight = "16pt";		  			
			if(SectionNow.style.fontSize =="18pt")
					SectionNow.style.lineHeight = "18pt";		  			
			if(SectionNow.style.fontSize =="20pt")
					SectionNow.style.lineHeight = "20pt";		  			
			

			}
			
			if (document.getElementById("editArea"))
			{
				re = /&lt;/gi;
				strText = strText.replace(re,"<");
				re = /<BR>/gi;
				strText = strText.replace(re,"\n");
				re = /<br>/gi;
				strText = strText.replace(re,"\n");				
				re = /&amp;/gi;
				strText = strText.replace(re,"&");
				re = /&nbsp;/gi;			
				document.getElementById("editArea").value = strText.replace(re," ");
						
			}
			

			

			if (document.getElementById("selFontName"))
				ChangeCboByText(document.getElementById("selFontName"),	SectionNow.style.fontFamily);
			if (document.getElementById("selFontSize"))
				ChangeCboByValue(document.getElementById("selFontSize"),SectionNow.style.fontSize);
			if (document.getElementById("selFontColor"))
				ChangeCboByValue(document.getElementById("selFontColor"),SectionNow.style.color);						
		}
		document.frmpersonalise.editArea.focus();
		}

	function checkMaxChars(contentLength)
		{
		
		currentstatus = SectionNow.id + "_" + SectionNow.style.fontSize + "_" + SectionNow.style.fontFamily.replace(' ','_');
		var maxchars ="";

		switch (currentstatus) {		
				
case 'td1_10pt_Angelina':
maxchars =160
break
case 'td1_12pt_Angelina':
maxchars =100
break
case 'td1_14pt_Angelina':
maxchars =66
break
case 'td1_16pt_Angelina':
maxchars =34
break
case 'td1_18pt_Angelina':
maxchars =30
break
case 'td1_20pt_Angelina':
maxchars =26
break

case 'td1_10pt_English':
maxchars =160
break
case 'td1_12pt_English':
maxchars =100
break
case 'td1_14pt_English':
maxchars =66
break
case 'td1_16pt_English':
maxchars =34
break
case 'td1_18pt_English':
maxchars =30
break
case 'td1_20pt_English':
maxchars =26
break

case 'td1_10pt_Gabrielle':
maxchars =160
break
case 'td1_12pt_Gabrielle':
maxchars =100
break
case 'td1_14pt_Gabrielle':
maxchars =66
break
case 'td1_16pt_Gabrielle':
maxchars =34
break
case 'td1_18pt_Gabrielle':
maxchars =30
break
case 'td1_20pt_Gabrielle':
maxchars =26
break

case 'td2_10pt_Angelina':
maxchars =160
break
case 'td2_12pt_Angelina':
maxchars =100
break
case 'td2_14pt_Angelina':
maxchars =66
break
case 'td2_16pt_Angelina':
maxchars =34
break
case 'td2_18pt_Angelina':
maxchars =30
break
case 'td2_20pt_Angelina':
maxchars =26
break

case 'td2_10pt_English':
maxchars =160
break
case 'td2_12pt_English':
maxchars =100
break
case 'td2_14pt_English':
maxchars =66
break
case 'td2_16pt_English':
maxchars =34
break
case 'td2_18pt_English':
maxchars =30
break
case 'td2_20pt_English':
maxchars =26
break

case 'td2_10pt_Gabrielle':
maxchars =160
break
case 'td2_12pt_Gabrielle':
maxchars =100
break
case 'td2_14pt_Gabrielle':
maxchars =66
break
case 'td2_16pt_Gabrielle':
maxchars =34
break
case 'td2_18pt_Gabrielle':
maxchars =30
break
case 'td2_20pt_Gabrielle':
maxchars =26
break


			}
			
		if(contentLength > maxchars)
			return false;
		else
			return true;
		}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

		
		function doValidate(thisText)
			{
				replaceText(thisText);
				savePos(thisText);
				
				/*
				if(checkMaxChars(thisText.value.length))
				{
				replaceText(thisText);
				savePos(thisText);
				}
				else
				{
				alert(" You have exceeded the number of characters permitted. \n Please either shorten your message or reduce the font size.");
				}
				*/
			}
								
		function replaceText(thisText)
		{

			/*
			if(SectionNow.id!=SignatureNow || document.frmpersonalise.SignatureID.value=="-1")
			{
			*/

				rep = /</g;
				strText = thisText.value.replace(rep,"&lt;");				
				rep = /\n/g;
				strText = strText.replace(rep,"<br>");
				rep = /&/g;
				strText = strText.replace(rep,"&amp;");
				SectionNow.innerHTML = strText;
			/*
			}
			else
			{				
				SectionNow.innerHTML = thisText.value;
			}

			cs = SectionNow.id;
			reg = /S/;
			cs = cs.replace(reg, "CP");
			if (document.getElementById(cs))
			  document.getElementById(cs).innerHTML = thisText.value;
			  */
		}
		function applyFontSize(ctrl)
		{

		  SectionNow.style.fontSize = ctrl.value;

		  if(SectionNow.style.fontSize =="10pt")
				SectionNow.style.lineHeight = "10pt";		  			
		  if(SectionNow.style.fontSize =="12pt")
				SectionNow.style.lineHeight = "12pt";		  			
		  if(SectionNow.style.fontSize =="14pt")
				SectionNow.style.lineHeight = "14pt";		  			
		  if(SectionNow.style.fontSize =="16pt")
				SectionNow.style.lineHeight = "16pt";		  			
		  if(SectionNow.style.fontSize =="18pt")
				SectionNow.style.lineHeight = "18pt";		  			
		  if(SectionNow.style.fontSize =="20pt")
				SectionNow.style.lineHeight = "20pt";	
				
		}		  
		function applyFont(ctrl)
		{
		  SectionNow.style.fontFamily = ctrl.options[ctrl.selectedIndex].value;
		}		  
		function applyFontColor(ctrl)
		{
			SectionNow.style.color = ctrl.value;
		}
		
				
		function savePos (txt1)
		{
		
			if (txt1.createTextRange) 
				txt1.caretPos = document.selection.createRange().duplicate();
		}
		
		
		
	  var areaNow = null;
		function ChangeCboByText(cname, cvalue)
		{
			for (i = 0; i < cname.options.length; i++)
			{
				if (cname.options[i].text == cvalue)
				{
					cname.selectedIndex = i;
					break;
				}
			}
		}
		
		function ChangeCboByValue(cname, cvalue)
		{
			for (i = 0; i < cname.options.length; i++)
			{
				if (cname.options[i].value.toLowerCase() == cvalue.toLowerCase())
				{					
					cname.selectedIndex = i;
					break;
				}
			}
		}
		
		function CboByValue(cname, cvalue)
		{
			
			if (cname)
			{
				for (i = 0; i < cname.options.length; i++)
				{
					if (cname.options[i].value.toLowerCase() == cvalue.toLowerCase())
					{
						return(cname.options[i].value);
					}
				}
			}
			return("");
		}
		
		function CboByText(cname, ctext)
		{
			if (cname)
			{
				for (i = 0; i < cname.options.length; i++)
				{
					if (cname.options[i].text.toLowerCase() == ctext.toLowerCase())
					{
						return(cname.options[i].text);
					}
				}
			}
			return("");
		}
		
		
		function saveControl(cname)
		{
			areaNow = cname;
			savePos(cname);
		}
		
		function validate_form()
		{
		
		//alert(document.getElementById("td1"));
		document.frmpersonalise.submit();
		}

