/*------------------------------------------------------------------------
* Common javascript methods
* @author Steinar Hodnebo
*------------------------------------------------------------------------*/

var totalView = "TotalView"
var mainInputPage = "MainInputPage"
var agenda = "Agenda"
var start = "Start"

var restrictedWord = new Array(15)
restrictedWord[0]=" limited";
restrictedWord[1]=" inc";
restrictedWord[2]=" teoranta";
restrictedWord[3]=" teo";
restrictedWord[4]="trading as";
restrictedWord[5]="T/A";
restrictedWord[6]="C/O";
restrictedWord[7]="P.O. Box";
restrictedWord[8]=".ie";
restrictedWord[9]=".com";
restrictedWord[10]=".net";
restrictedWord[11]=".eu";
restrictedWord[12]=".org";
restrictedWord[13]=".co.uk";
restrictedWord[14]=" ltd";

var objectionLetterWord = new Array(7)
objectionLetterWord[0]=" Bank";
objectionLetterWord[1]=" Insurance";
objectionLetterWord[2]=" Assurance";
objectionLetterWord[3]="Chamber of Commerce";
objectionLetterWord[4]="Society";
objectionLetterWord[5]="University";
objectionLetterWord[6]="bank ";

var noPermissionCountry = new Array(24)
noPermissionCountry[0]="BE";
noPermissionCountry[1]="CY";
noPermissionCountry[2]="CZ";
noPermissionCountry[3]="DE";
noPermissionCountry[4]="DK";
noPermissionCountry[5]="EE";
noPermissionCountry[6]="ES";
noPermissionCountry[7]="FI";
noPermissionCountry[8]="FR";
noPermissionCountry[9]="GB";
noPermissionCountry[10]="GR";
noPermissionCountry[11]="HU";
noPermissionCountry[12]="IE";
noPermissionCountry[13]="IT";
noPermissionCountry[14]="LT";
noPermissionCountry[15]="LU";
noPermissionCountry[16]="LV";
noPermissionCountry[17]="MT";
noPermissionCountry[18]="NL";
noPermissionCountry[19]="PL";
noPermissionCountry[20]="PT";
noPermissionCountry[21]="SE";
noPermissionCountry[22]="SI";
noPermissionCountry[23]="SK";


function getPosition() {
  var b = navigator.appName;
  if (b == "Netscape")
    return "&position="+window.pageYOffset;
  else
    return "&position="+document.body.scrollTop;
}

function setLiteParams(add1,add2,add3,add4,surname,forename,addSameAsPOB,addSameAsRES){
	//alert("In setLiteParams--->");
	//alert("In setLiteParams: "+ surname +", "+ forename);
	var elements = document.forms['form1'].elements;
	
	//populate Business Name Details   
	if(addSameAsPOB.length > 1){
		var addressExists = elements['textfield-116'];
		if(add1.length > 1){
			if(addressExists!=null){
				document.form1.elements['textfield-116'].value = add1;
				document.form1.elements['textfield-117'].value = add2;
				document.form1.elements['textfield-118'].value = add3;
				document.form1.elements['textfield-119'].value = add4;
			}
		}
	}
	if(addSameAsRES.length > 1){
		var addressExists = elements['textfield-216'];
		if(add1.length > 1){
			if(addressExists!=null){
				document.form1.elements['textfield-216'].value = add1;
				document.form1.elements['textfield-217'].value = add2;
				document.form1.elements['textfield-218'].value = add3;
				document.form1.elements['textfield-219'].value = add4;
			}
		}

	//populate Business Owner Details
	var surnameField = elements['textfield-202'];
	if(surnameField !=null){
		document.form1.elements['textfield-202'].value = surname;
		document.form1.elements['textfield-203'].value = forename;
	}

	//populate person verifying the contents of the form
	var certSurnameField = elements['textfield-336'];
	if(certSurnameField !=null){
		document.form1.elements['textfield-336'].value = surname;
		document.form1.elements['textfield-337'].value = forename;
	}
	}

	
}

function setFocus(focusname, errorname) {
	var agent=navigator.userAgent.toLowerCase();
	var version = parseInt(navigator.appVersion);
	
	var isExplorer     = ((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1));
	var isExplorer3    = (isExplorer && (version < 4));
	var isExplorer4    = (isExplorer && (version == 4) && (agent.indexOf("msie 4")!=-1) );
	var isExplorer4up  = (isExplorer && (version >= 4));
	var isExplorer5    = (isExplorer && (version == 4) && (agent.indexOf("msie 5.0")!=-1) );
	var isExplorer5_5  = (isExplorer && (version == 4) && (agent.indexOf("msie 5.5") !=-1));
	var isExplorer5up  = (isExplorer && !isExplorer3 && !isExplorer4);
	var isExplorer5_5up =(isExplorer && !isExplorer3 && !isExplorer4 && !isExplorer5);
	var isExplorer6    = (isExplorer && (version == 4) && (agent.indexOf("msie 6.")!=-1) );
	var isExplorer6up  = (isExplorer && !isExplorer3 && !isExplorer4 && !isExplorer5 && !isExplorer5_5);
	
	var isNetscape  = ((agent.indexOf('mozilla')!=-1) && (agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1) && (agent.indexOf('opera')==-1) && (agent.indexOf('webtv')==-1) && (agent.indexOf('hotjava')==-1));
	var isNetscape2 = (isNetscape && (version == 2));
	var isNetscape3 = (isNetscape && (version == 3));
	var isNetscape4 = (isNetscape && (version == 4));
	var isNetscape4up = (isNetscape && (version >= 4));
	var isNetscapeonly  = (isNetscape && ((agent.indexOf(";nav") != -1) || (agent.indexOf("; nav") != -1)) );
	var isNetscape6 = (isNetscape && (version == 5));
	var isNetscape6up = (isNetscape && (version >= 5));
	
	var isOpera = (agent.indexOf("opera") != -1);
	var isOpera2 = (agent.indexOf("opera 2") != -1 || agent.indexOf("opera/2") != -1);
	var isOpera3 = (agent.indexOf("opera 3") != -1 || agent.indexOf("opera/3") != -1);
	var isOpera4 = (agent.indexOf("opera 4") != -1 || agent.indexOf("opera/4") != -1);
	var isOpera5 = (agent.indexOf("opera 5") != -1 || agent.indexOf("opera/5") != -1);
	var isOpera5up = (isOpera && !isOpera2 && !isOpera3 && !isOpera4);
	
	if(focusname=='' && errorname!='')
	  focusname = errorname;

	if(document.all && document.all(focusname)==null)
		return;
	else if(!document.all && document.getElementById[focusname]==null)
		return;

	if(document.all && isExplorer5up){
	  if(focusname!=''){
	    if(document.forms[0][focusname].length > 1){
	      if(document.forms[0][focusname][0].type=='radio' && document.forms[0][focusname][0].disabled==false)
	        document.forms[0][focusname][0].focus();
	      else if(document.forms[0][focusname].disabled==false)
	        document.forms[0][focusname].focus();
	   }
	    else if(document.forms[0][focusname].type!=''){
	      if(document.forms[0][focusname].disabled==false)
	        document.forms[0][focusname].focus();
	    }
	  }
	}
	if(!document.all && document.getElementById && isNetscape6up){
	
	  if(focusname!=''){
	    if(document.forms[0][focusname].length > 1){
	      if(document.forms[0][focusname][0].type=='radio' && document.forms[0][focusname][0].disabled==false)
	        document.forms[0][focusname][0].focus();
	      else if(document.forms[0][focusname].disabled==false)
	        document.forms[0][focusname].focus();
	    }
	    else if(document.forms[0][focusname].type!=''){
	      if(document.forms[0][focusname].disabled==false)
	        document.forms[0][focusname].focus();
	    }
	  }
	}

}

var confirmMessage='';

function navigate(pageName,pageNo,action,actionValue,actionValue2,actionValue3, lastPage) 
{
	//input type="radio" value="10" name="radiogroup-6" CHECKED onClick="
//	alert('pageName:' +pageName);
//	alert('pageNo:' +pageNo);
//	alert('action:' +action);
//	alert('actionValue:' +actionValue);
//	alert('actionValue2:' +actionValue2);
//	alert('actionValue3:' +actionValue3);
//	alert('lastPage:' +lastPage);
	var fromDateB1;
	var toDateB1;
	var newARD;
	
	
	//if the page is SSL switch it back to non SSL
	if (location.href.indexOf("https")!=-1){
		//alert(location.href);
		var currentUrl = location.href;
		var newUrl =  "http"+currentUrl.substring(5,currentUrl.length);
		//alert(newUrl);
		window.location.href = newUrl;
	    	return false;
		
	} 
	
	
	if((pageName=='MainInputPage')&&(actionValue2=='1')&&(lastPage=='1')){
	
		alert("When you have completed and submitted the form you will be presented with a signature page which you must print and sign and send to the CRO.  Your form will not be considered to be filed until the signature page has been received in CRO.");
	
	}
	


	if((actionValue2=='send')&&(actionValue!='b1-template')&&(actionValue!='b73-template')){

		alert("A signature page will open in a moment.  Please print and sign the signature page and return to the CRO.");

	}

	// gets the URL of the present location
	var rootUrl=document.location.protocol+"//"+document.location.host+"/finer/";
	var strUrl = "";
	if (action=='link') 
	{	
		var elements = document.forms['form1'].elements;
		if(elements)
		{
			var selections = elements['combobox-1010'];
			if (selections )
			if(selections.selectedIndex=='5')
			{
				var com_num = elements['lookupfield-196'];
				if(com_num)
				{
					if(com_num.value.charAt(0)!='9')
					{
					 	alert('The form you have selected is for external companies only. Please ensure that you have selected the correct form and that the company number entered is correct.');
					 	return false;
					}
				}
				
			}
			else{
				var com_num = elements['lookupfield-196'];
				if(com_num)
				{
					if(!(com_num.value<900000))
					{
					 	alert('The form you have selected cannot be filed for external companies. Please ensure that you have selected the correct form and that the company number entered is correct.');
					 	return false;
					}
				}
				else{
			
				var com_num = elements['lookupfield-145'];
				if(com_num)
				{
					if(!(com_num.value<900000))
					{
						alert('The form you have selected cannot be filed for external companies. Please ensure that you have selected the correct form and that the company number entered is correct.');
					 	return false;
					}			
				}
			
			}
				
			
			}
					
					
			var interalCompNum = elements['lookupfield-41'];
				
			if(interalCompNum)
			{
					if(!(interalCompNum.value<900000))
					{
					 	alert('The form you have selected cannot be filed for external companies. Please ensure that you have selected the correct form and that the company number entered is correct.');
					 	return false;
					}
			}	
			var interalCompNum = elements['lookupfield-113'];
							
					if(interalCompNum)
					{
						if(!(interalCompNum.value<900000))
							{
							 	alert('The form you have selected cannot be filed for external companies. Please ensure that you have selected the correct form and that the company number entered is correct.');
							 	return false;
							}
			}
			
			
					
			//check enterprise name does not contain restricted word
			var enterpriseName = elements['textfield-130'];
			if(enterpriseName)
			{
			if(enterpriseName.value!='')
				{			
									
				for (i = 0; i < restrictedWord.length; i++)
				{
				if(enterpriseName.value.toUpperCase().indexOf(restrictedWord[i].toUpperCase())!=-1){
				 	alert('Invalid Business Name. Cannot contain: '+ restrictedWord[i].toUpperCase()+' Please see help for more details.');
				 	return false;				
				}					
				}
				for (i = 0; i < objectionLetterWord.length; i++)
					{
						if(enterpriseName.value.toUpperCase().indexOf(objectionLetterWord[i].toUpperCase())!=-1){
							alert('You must include a letter of no objection due to the following word being in Business Name: '+ objectionLetterWord[i].toUpperCase() +' Please see help for more details.');
						 	break;				
						}					
					}
				}
				}
			
			var resSelected = elements['combobox-458'];
				if(resSelected)
						{
						if(resSelected.value=='23')
							{	
							var answer = confirm("Please ensure that the new company name includes the company type. eg. Limited, Public Limited Company, (Please note abbreviations are not acceptable)");				
							if (answer) {
							}
							else{	
								return;
							}	
							}
						}
			
				
			//check country is not resticted
			var selectedCountry = elements['combobox-207'];
			if(selectedCountry)
			{
			if(selectedCountry.value!='')
				{	
				var showWarning="true";

				for (i = 0; i < noPermissionCountry.length; i++)
					{
					if(selectedCountry.value.toUpperCase() == noPermissionCountry[i].toUpperCase()){			
						//country selected does not require permission
						showWarning="false";
						break;				
					}					
					}
					
				}

			if(showWarning=="true")				
				alert("If you are a non EU National business permission must be sought from Department of Justice, Equality and Law Reform before you can begin to trade in this country.  Please attach a photocopy of your permission documentation(Green book / I.D. CARD) with stamp 4 to your application.");
			}
			
			var retvalue = true;
			
			for (i = 0; i < elements.length; i++)
			{
				
				var element = elements[i];


				var curdate = new Date();
				var month = curdate.getMonth() +1;
				var year = curdate.getFullYear();
				var day = curdate.getDate();
				
				
				
					
				if(element.name.indexOf("datefield") != -1)
				{
					//alert('date ' + element.name + ' ' + element.value);
					//alert(day+ ' ' + month  + ' ' + year);		
					var fmonth = 0;
					var fyear = 0;
					var fday = 0;
					
					if(element.name.indexOf("day") != -1)
					{
						fday = element.value;
						
						
						if(fday==""){
							// if all date fields are blank then don't check for valid date
							var eleCount = i;
							var tempMonthElement = elements[++eleCount];	
							var tempYearElement = elements[++eleCount];
							if((tempMonthElement.value=="")&&(tempYearElement.value=="")){
								break;
							}
							
						}
						
						element = elements[++i];
						if(element.name.indexOf("month") != -1)
						{
							fmonth = eval(element.value);
						}
						else{
							alert('You have entered an invalid date, please check the date(s) you have entered on this page.');
							return false;
						}
						element = elements[++i];
						if(element.name.indexOf("year") != -1)
						{
							fyear = element.value;
						}
						else{
							alert('You have entered an invalid date, please check the date(s) you have entered on this page.');
							return false;
						}
						//alert(fday+ ' ' + fmonth  + ' ' + fyear);



						var dteDate;

						//set up a Date object based on the day, month and year arguments
						//javascript months start at 0 (0-11 instead of 1-12)
						dteDate=new Date(fyear,(fmonth-1),fday);

						if ((fday==dteDate.getDate()) && ((fmonth-1)==dteDate.getMonth()) && (fyear==dteDate.getFullYear())){
							//valid date
							if(element.name.indexOf("fromDateB1") != -1){
								fromDateB1 = dteDate;
	
							}
							if(element.name.indexOf("toDateB1") != -1){
								toDateB1 = dteDate;												
							}
							//B77 new ARD Date
							if(element.name.indexOf("newARD") != -1){
								newARD = dteDate;												
							}


					
						}
						else{
							alert(' You have entered an invalid date, please check the date(s) you have entered on this page.');
							return false;
						}

						if(fday!= null && fmonth!=null && fyear!=null)
						{
										
							if(fyear>year)
								retvalue = false;
							else if(fyear==year)
							{
								if(fmonth>month)
								  retvalue = false;
								else if(fmonth==month)
								  if(fday>(day+5))
								    retvalue = false;
							}
							
						}
					
					}
				}
				
			}
			//alert(fromDateB1);
			//alert(toDateB1);
			
			if(retvalue == false){

				//don't display warning for B1 or B77 dates
				if((fromDateB1==null)&&(toDateB1==null)&&(newARD==null)){
				alert('You have entered a date in the future, applications can not be processed with an effective date in the future.');
				return false;
				}
			}
			
			if(fromDateB1>toDateB1){				
				alert("You have ented a Financial year from date that is after the Financial year to date.");
				return false;
			}
			
		}
		if (actionValue==totalView && actionValue2=='')
			strUrl = rootUrl+totalView;
		else if (actionValue==totalView && pageName==totalView)
			strUrl = rootUrl+mainInputPage+"?pageno="+ actionValue2;
		else if (actionValue==totalView)
			strUrl = rootUrl+totalView;
		else if (actionValue!='' && actionValue2!='' && actionValue3!='')
			strUrl = rootUrl+actionValue+"?pageno="+ actionValue2+"&template="+actionValue3;
		else
			strUrl = rootUrl+actionValue+"?pageno="+ actionValue2;
	}
	else if (action=='previous') 
	{	
		if (pageName == totalView && actionValue3=="yes")
			strUrl = rootUrl+totalView;
		else if (pageName == totalView)
			strUrl = rootUrl+mainInputPage+"?pageno=" + lastPage;
		else if (actionValue == actionValue2)
			strUrl = rootUrl+start+"?pageno=2&template=start";
		else
			strUrl = rootUrl+pageName+"?pageno="+ pageNo;
	}
	else if (action=='next') 
	{	
		var elements = document.forms['form1'].elements;
		var curdate = new Date();
		var month = curdate.getMonth() +1;
		var year = curdate.getFullYear();
		var day = curdate.getDate();

		if(elements)
		{
		
			//check enterprise name does not contain restricted word
			var enterpriseName = elements['textfield-130'];
			if(enterpriseName)
			{
			if(enterpriseName.value!='')
				{			
				
				for (i = 0; i < restrictedWord.length; i++)
				{
					if(enterpriseName.value.toUpperCase().indexOf(restrictedWord[i].toUpperCase())!=-1){
					 	alert('Invalid Business Name. Cannot contain: '+ restrictedWord[i].toUpperCase()+' Please see help for more details.');
					 	return false;				
					}					
				}
				for (i = 0; i < objectionLetterWord.length; i++)
				{
					if(enterpriseName.value.toUpperCase().indexOf(objectionLetterWord[i].toUpperCase())!=-1){
						alert('You must include a letter of no objection due to the following word being in Business Name: '+ objectionLetterWord[i].toUpperCase()+' Please see help for more details.');
					 	break;				
					}					
				}
				}
			}
			
			var resSelected = elements['combobox-458'];
				if(resSelected)
						{
						if(resSelected.value=='23')
							{	
							var answer = confirm("Please ensure that the new company name includes the company type. eg. Limited, Public Limited Company, (Please note abbreviations are not acceptable)");				
							if (answer) {
								
							}
							else{	
								return;
							}	
							}
				}
			
			
			
			//check country is not resticted
			var selectedCountry = elements['combobox-207'];
			if(selectedCountry)
			{
			if(selectedCountry.value!='')
				{	
				var showWarning="true";

				for (i = 0; i < noPermissionCountry.length; i++)
					{
					if(selectedCountry.value.toUpperCase() == noPermissionCountry[i].toUpperCase()){			
						//country selected does not require permission
						showWarning="false";
						break;				
					}					
					}
					
				}

			if(showWarning=="true")				
				alert("If you are a non EU National business permission must be sought from Department of Justice, Equality and Law Reform before you can begin to trade in this country.  Please attach a photocopy of your permission documentation(Green book / I.D. CARD) with stamp 4 to your application.");
			}		
			
		
			//Registration of Business Name
			var radioSelections = elements['radiogroup-6'];
			if(radioSelections!=null){
			
			for (var i = 0; i < radioSelections.length; i++) {
				if (radioSelections[i].checked) {
					if((radioSelections[i].value)==10){
						alert('The principal place of business must be in the Republic of Ireland');	
					}	
				break;
			   	}
				}

			}

			//Registration of Business Lite Name
			var radioSelections2 = elements['radiogroup-1'];
			if(radioSelections2!=null){
			
			for (var i = 0; i < radioSelections2.length; i++) {
				if (radioSelections2[i].checked) {
					if((radioSelections2[i].value)==5){
						var answer = confirm('This form is for registering a sole trader\'s business name only.  If you wish to register a business name for a partnership or body corporate you must register as a user first.  The principal place of business must be in the Republic of Ireland');	
	if (answer) 
	{
		break;
	}
	else{
	
		return false;
	}

				}	
				break;
			   	}
				}

			}

		
			var selections = elements['combobox-1010'];
			if (selections )
			if(selections.selectedIndex=='5')
			{
				var com_num = elements['lookupfield-196'];
				if(com_num)
				{
					if(com_num.value.charAt(0)!='9')
					{
					 	alert('The form you have selected is for external companies only. Please ensure that you have selected the correct form and that the company number entered is correct.');
					 	return false;
					}
				}
			}
			else{
				var com_num = elements['lookupfield-196'];
				if(com_num)
				{
					if(!(com_num.value<900000))
					{
						alert('The form you have selected cannot be filed for external companies. Please ensure that you have selected the correct form and that the company number entered is correct.');
					 	return false;
					}
				}
				else{
					var com_num = elements['lookupfield-145'];
					if(com_num)
					{					
						if(!(com_num.value<900000))
						{
							alert('The form you have selected cannot be filed for external companies. Please ensure that you have selected the correct form and that the company number entered is correct.');
						 	return false;
						}			
					}
				
				}
			
						
			}
			
			var interalCompNum = elements['lookupfield-41'];
				
			if(interalCompNum)
			{
					if(!(interalCompNum.value<900000))
					{
					 	alert('The form you have selected cannot be filed for external companies. Please ensure that you have selected the correct form and that the company number entered is correct.');
					 	return false;
					}
			}	
			var interalCompNum = elements['lookupfield-113'];
							
					if(interalCompNum)
					{
						if(!(interalCompNum.value<900000))
							{
							 	alert('The form you have selected cannot be filed for external companies. Please ensure that you have selected the correct form and that the company number entered is correct.');
							 	return false;
							}
			}
			
			var retvalue = true;
			
			for (i = 0; i < elements.length; i++)
			{
				var element = elements[i];
				if(element.name.indexOf("datefield") != -1)
				{
//					alert('date ' + element.name + ' ' + element.value);
//					alert(day+ ' ' + month  + ' ' + year);		
					var fmonth = 0;
					var fyear = 0;
					var fday = 0;
					
					
					
					if(element.name.indexOf("day") != -1)
					{
					
					
						fday = element.value;
						
						if(fday==""){
							// if all date fields are blank then don't check for valid date
							var eleCount = i;
							var tempMonthElement = elements[++eleCount];	
							var tempYearElement = elements[++eleCount];
							if((tempMonthElement.value=="")&&(tempYearElement.value=="")){
								break;
							}
							
						}
						
						element = elements[++i];
						if(element.name.indexOf("month") != -1)
						{
							fmonth = eval(element.value);
						}
						else{
							alert('You have entered an invalid date, please check the date(s) you have entered on this page.');
							return false;
						}
						element = elements[++i];
						if(element.name.indexOf("year") != -1)
						{
							fyear = element.value;
						}
						else{
							alert('You have entered an invalid date, please check the date(s) you have entered on this page.');
							return false;
						}
						//alert(fday+ ' ' + fmonth  + ' ' + fyear);



						var dteDate;

						//set up a Date object based on the day, month and year arguments
						//javascript months start at 0 (0-11 instead of 1-12)
						dteDate=new Date(fyear,(fmonth-1),fday);

						if ((fday==dteDate.getDate()) && ((fmonth-1)==dteDate.getMonth()) && (fyear==dteDate.getFullYear())){
							//valid date
							if(element.name.indexOf("fromDateB1") != -1){
								fromDateB1 = dteDate;
	
							}
							if(element.name.indexOf("toDateB1") != -1){
								toDateB1 = dteDate;												
							}		
							//B77 new ARD Date
							if(element.name.indexOf("newARD") != -1){
								newARD = dteDate;												
							}			
					
						}
						else{
							alert('You have entered an invalid date, please check the date(s) you have entered on this page.');
							return false;
						}

						if(fday!= null && fmonth!=null && fyear!=null)
						{
							var retvalue = true;
							if(fyear>year)
								retvalue = false;
							else if(fyear==year)
							{
								if(fmonth>month)
								  retvalue = false;
								else if(fmonth==month)
								  if(fday>(day+5))
								    retvalue = false;
							}
							
						}
					
					}
				}
			}
			if(fromDateB1>toDateB1){				
				alert("You have ented a Financial year from date that is after the Financial year to date.");
				return false;
			}

			if(retvalue == false){

			//don't display warning for B1 or B77 dates
			if((fromDateB1==null)&&(toDateB1==null)&&(newARD==null)){
				alert('You have entered a date in the future, applications can not be processed with an effective date in the future.');
				return false;
				}
			}
		}
		if (actionValue != '')
			pageName = actionValue;
		if (actionValue2 != '')
			pageNo = actionValue2;
		if (pageNo == '')
			pageNo = '1';
		
		if (actionValue3 != '')
			strUrl = rootUrl+pageName+"?pageno="+pageNo+"&template="+actionValue3;
		else if (pageName == '')
			strUrl = rootUrl+start+"?pageno=1";
		else
			strUrl = rootUrl+pageName+"?pageno="+ pageNo;
	}
	else if (action=='save') 
	{	
		if (actionValue=='domainadmin'||actionValue=='changepassword')
			strUrl = rootUrl+pageName+"?pageno="+pageNo+"&action="+actionValue;			
		else if (actionValue2=='send')
			strUrl = rootUrl+totalView+"?pageno=1&template="+actionValue+"&send=true";
		else if (actionValue3=='true')
			strUrl = rootUrl+pageName+"?pageno="+pageNo+"&action="+action+"&control=true";
		else
			strUrl = rootUrl+pageName+"?pageno="+pageNo+"&action="+action;
	}
	else if (action=='open') 
	{	
			strUrl = rootUrl+mainInputPage+"?template="+actionValue+"&uoid="+actionValue2;
	}
	else if (action=='duplicate') 
	{	
			var elements 	 = document.forms['form1'].elements;
			if(elements)
			{
				
				var relationtype = 	elements['combobox-44'];
				var eventtype = 	elements['combobox-45'];
				if(relationtype)
				{
				if(eventtype.selectedIndex==1  && relationtype.selectedIndex==5)
				{
					alert('You are appointing a new secretary, please ensure that you resign the existing secretary');
				}
				if(eventtype.selectedIndex==4  && relationtype.selectedIndex==5)
				{
					alert('You are resigning the secretary of the company, please ensure you appoint a new secretary');				
				}
				if(eventtype.selectedIndex==1  && relationtype.selectedIndex==4)
				{
					alert('The director and his/her alternate will not be linked on the register. Therefore, when notifying the resignation of the director it is the responsibility of the company to also notify the resignation of the alternate.');				
				}
				if(eventtype.selectedIndex==3)
				{
					alert('This option should only be used when you wish to change the name, date of birth, occupation or nationality of a Director/Secretary.  Please select another option should you wish to appoint, resign or change the address of a Director/Secretary');
				}
				//if(eventtype.selectedIndex == 0)
				//{
				//	alert('You did not select Type of Event');
				//	return false;
				//}
				if(relationtype){
					if(relationtype.selectedIndex == 0)
					{
						alert('You did not select Type of Relationship');
						return false;
					}
					}
				}

				if(eventtype){
					if(eventtype.selectedIndex == 0)
					{
						alert('You did not select Type of Event');
						return false;
					}
				}
				
				
				//for B1 display message regarding B10
				if(pageNo==3)
				{
					alert('Please ensure that you have filed a B10 for this director');
				}
				
			}
			tagList = "";
			if(actionValue!='' && actionValue!='-')
				tagList += "&fieldid="+actionValue;
			if(actionValue2!='')
				tagList += "&groupid="+actionValue2;
			if(actionValue3!='')
				tagList += "&pageid="+actionValue3;
			strUrl = rootUrl+pageName+"?pageno="+pageNo+"&action="+action+tagList+getPosition();
	}
	else if (action=='add') 
	{	
			strUrl = rootUrl+pageName+"?pageno="+pageNo+"&"+action+"="+actionValue+getPosition();	
	}
	else if (action=='edit' || action=='change') 
	{	
			strUrl = rootUrl+pageName+"?pageno="+pageNo+"&"+action+"="+actionValue+"&groupId="+actionValue2+getPosition();;
	}
	else if (action=='delete') 
	{	
	    var proceed=confirm(confirmMessage+ " (ITEM: "+actionValue+")");
	    if (proceed)
	    {
				strUrl = rootUrl+pageName+"?pageno="+pageNo+"&"+action+"="+actionValue+"&groupId="+actionValue2+getPosition();;
				confirmMessage='';
		} else return;
	}
	else if (action=='logon' || action=='newdomain' || action=='password' || action=='businesslite')
	{	
			strUrl = rootUrl+pageName+"?pageno="+pageNo+"&action="+action;
	}
	else if (action=='logout') 
	{	
			strUrl = rootUrl+start+"?pageno=1&action="+action;
	}
	
	else if (action=='liteform')
	{
			strUrl = rootUrl+mainInputPage+"?pageno=1&template=liteform";
	}

	//alert(strUrl);
	// Set new URL
	document.forms["form1"].action = strUrl;
	document.forms["form1"].submit();
}

function confirmAction(goToUrl)
{

	//alert(goToUrl);

	var posUid = goToUrl.indexOf("uoid=");
	var uoid = goToUrl.substring(posUid+5,posUid+11);
	
  	var rootUrl=document.location.protocol+"//"+document.location.host+"/finer/";


    var proceed=confirm(confirmMessage+ " (ITEM: "+uoid+")");
    if (proceed)
    {
				document.forms["form1"].action = rootUrl + goToUrl;
				document.forms["form1"].submit();
    }
    confirmMessage='';
}

infoImages = new Array()
infoImages[0] = new Image()
infoImages[0].src = "images/info_selected.gif"
infoImages[1] = new Image()
infoImages[1].src = "images/info.gif"

function showInfo(info) 
{	
	var rootUrl=document.location.protocol+"//"+document.location.host+"/finer/";
	var picInfo="pic-"+info;
	var isSelected=false;
	
	if(document.all && (document.images(info).src == rootUrl+infoImages[0].src || document.images(info).src == infoImages[0].src))
		isSelected=true;
	if(!document.all && document.getElementById && (document.images[info].src == rootUrl+infoImages[0].src || document.images[info].src == infoImages[0].src))
		isSelected=true;
		
	var helpInfoTop=0;
	var helpInfo="help-"+info;
	for (i = 0; i < document.images.length; i++)
	{
		if(document.images[i].src == rootUrl+infoImages[0].src || document.images[i].src == infoImages[0].src)
		{
			document.images[i].src = infoImages[1].src;
			if(document.all)
			{
				document.all("help-"+document.images[i].name).style.visibility="hidden";
			}
			if(!document.all && document.getElementById)
			{
				document.getElementById("help-"+document.images[i].name).style.visibility="hidden";
			}			
		}
	}
	
	if(document.all && !isSelected)
	{
		document.images(info).src = infoImages[0].src;
	}
	else if(document.all && !isSelected)
	{
		document.images[info].src = infoImages[0].src;
	}

	if(document.all && !isSelected)
	{
		document.images(info).style.position = "absolute";
		helpInfoTop = document.images(info).offsetTop;
		if (helpInfoTop < 5)
			helpInfoTop = window.event.y-10;
		document.images(info).style.position = "relative";
		
		document.all(helpInfo).style.visibility="visible";
		document.all(helpInfo).style.top=helpInfoTop;

		document.images(info).src = infoImages[0].src;
	}
	if(!document.all && !isSelected)
	{
		document.images[info].style.position = "absolute";
		helpInfoTop = document.images[info].offsetTop;
		if (helpInfoTop < 5)
			helpInfoTop = window.event.y-10;
		document.images[info].style.position = "relative";
		
		document.getElementById(helpInfo).style.visibility="visible";
		document.getElementById(helpInfo).style.top=helpInfoTop;

		document.images[info].src = infoImages[0].src;
	}
}

errorImages = new Array()
errorImages[0] = new Image()
errorImages[0].src = "images/error_selected.gif"
errorImages[1] = new Image()
errorImages[1].src = "images/error.gif"

function showError(fieldName) 
{	
	var rootUrl=document.location.protocol+"//"+document.location.host+"/finer/";
	var isSelected=false;

	if(document.all && document.images(fieldName)==null)
		return;
	else if(!document.all && document.images[fieldName]==null)
		return;
	
	if(document.all && (document.images(fieldName).src == rootUrl+errorImages[0].src || document.images(fieldName).src == errorImages[0].src))
		isSelected=true;
	if(!document.all && document.getElementById && (document.images[fieldName].src == rootUrl+errorImages[0].src || document.images[fieldName].src == errorImages[0].src))
		isSelected=true;

	var helpInfoTop=0;
	var helpInfo="div-"+fieldName;
	for (i = 0; i < document.images.length; i++)
	{
		if(document.images[i].src == rootUrl + errorImages[0].src || document.images[i].src == errorImages[0].src)
		{
			document.images[i].src = errorImages[1].src;
			if(document.all)
			{
				document.all("div-"+document.images[i].name).style.visibility="hidden";
			}
			if(!document.all && document.getElementById)
			{
				document.getElementById("div-"+document.images[i].name).style.visibility="hidden";
			}			
		}
	}
	if(document.all && !isSelected)
	{		
		document.images(fieldName).style.position = "absolute";
		helpInfoTop = document.images(fieldName).offsetTop;
		if (helpInfoTop < 5)
			helpInfoTop=100;
		document.images(fieldName).style.position = "relative";
		
		document.all(helpInfo).style.visibility="visible";
		document.all(helpInfo).style.top=helpInfoTop;
		
		document.images(fieldName).src = errorImages[0].src;
	}
	if(!document.all && document.getElementById && !isSelected)
	{
		document.images[fieldName].style.position = "absolute";
		helpInfoTop = document.images[fieldName].offsetTop;
		if (helpInfoTop < 5)
			helpInfoTop=100;
		document.images[fieldName].style.position = "relative";
		
		document.getElementById(helpInfo).style.visibility="visible";
		document.getElementById(helpInfo).style.top=helpInfoTop;

		document.images[fieldName].src = errorImages[0].src;
	}			
}

function sendWithWarnings() {
	
	if(document.form1.PayByAccount!=null){
		if(document.form1.PayByAccount.checked){
		    window.location.href = "payment.jsp?type=account";
		    return false;
		}
		else{
		    alert("A signature page will open shortly in a new window.  Please print it and ensure it is signed by a Director and/or Secretary or an Electronic Filing Agent before returning it to the CRO.");
		    opener.document.form1.sendwithwarnings.value = true;
		    opener.document.form1.submit();
		    window.close();
	    	    return false;	
		}
	}
	else{
	    alert("A signature page will open shortly in a new window.  Please print it and ensure it is signed by a Director and/or Secretary or an Electronic Filing Agent before returning it to the CRO.");
	    opener.document.form1.sendwithwarnings.value = true;
	    opener.document.form1.submit();
	    window.close();
    	    return false;		
	
	}

}


function sendWithAccountPayment() {
   window.location.href = "confirmation.jsp";
   return false;	
}

function saveSendLater() {
   opener.opener.location.href = "Agenda?pageno=1";
   opener.close();
   window.close();
   return false;
}

function displayWarning(){

	if((document.form1.NumberInRegister!=null)&&(document.form1.NumberInRegister.value=="Start B1")){

		var answer = confirm ("You will now be presented with a pre-filled annual return for this company. The information supplied is a combination from the Register and this company’s last annual return.\n\nIf the last annual return has not been checked or registered by the CRO, it is possible that some of the information contained in this return is incorrect. In that case, it is possible that when you submit the form at the end you may be warned of discrepancies even for information which you have not changed. If this happens please check and correct the information concerned and submit again. \n\n If, to best of your knowledge, the information is correct, you will be allowed to submit the annual return even though it does not correspond to information on the Register.");

		if (answer) {
				return true;
			}
		else{	
				return;
			}
	}
	else{
		return true;
	}

}

function securePage(){
	//if the page is Non SSL switch it to SSL
	if (location.href.indexOf("http:")!=-1){
	//	alert(location.href);
		var currentUrl = location.href;
		var newUrl =  "https"+currentUrl.substring(4,currentUrl.length);
	//	alert(newUrl);
		window.location.href = newUrl;
		return;
	} 
}
function unSecurePage(){
	//if the page is SSL switch it to Non SSL
	if (location.href.indexOf("https")!=-1){
	//	alert(location.href);
		var currentUrl = location.href;
		var newUrl =  "http"+currentUrl.substring(5,currentUrl.length);
	//	alert(newUrl);
		window.location.href = newUrl;
		return;
	} 
}
