var UNDEFINED;
var objForm;
var bfocus;
var sfocus;

//To Show the post office

<!--
function Base64()
{}

Base64._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

     Base64.encode = function (input)
	 {
         var output = "";
         var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
         var i = 0;

         input = Base64._utf8_encode(input);

         while (i < input.length) {

             chr1 = input.charCodeAt(i++);
             chr2 = input.charCodeAt(i++);
             chr3 = input.charCodeAt(i++);

             enc1 = chr1 >> 2;
             enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
             enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
             enc4 = chr3 & 63;

             if (isNaN(chr2)) {
                 enc3 = enc4 = 64;
             } else if (isNaN(chr3)) {
                 enc4 = 64;
             }

             output = output +
             this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
             this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

         }

         return output;
     },

     Base64.decode = function (input) {
         var output = "";
         var chr1, chr2, chr3;
         var enc1, enc2, enc3, enc4;
         var i = 0;

         input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

         while (i < input.length) {

             enc1 = this._keyStr.indexOf(input.charAt(i++));
             enc2 = this._keyStr.indexOf(input.charAt(i++));
             enc3 = this._keyStr.indexOf(input.charAt(i++));
             enc4 = this._keyStr.indexOf(input.charAt(i++));

             chr1 = (enc1 << 2) | (enc2 >> 4);
             chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
             chr3 = ((enc3 & 3) << 6) | enc4;

             output = output + String.fromCharCode(chr1);

             if (enc3 != 64) {
                 output = output + String.fromCharCode(chr2);
             }
             if (enc4 != 64) {
                 output = output + String.fromCharCode(chr3);
             }

         }

         output = Base64._utf8_decode(output);

         return output;

     }

     Base64._utf8_encode = function (string) {
         string = string.replace(/\r\n/g,"\n");
         var utftext = "";

         for (var n = 0; n < string.length; n++) {

             var c = string.charCodeAt(n);

             if (c < 128) {
                 utftext += String.fromCharCode(c);
             }
             else if((c > 127) && (c < 2048)) {
                 utftext += String.fromCharCode((c >> 6) | 192);
                 utftext += String.fromCharCode((c & 63) | 128);
             }
             else {
                 utftext += String.fromCharCode((c >> 12) | 224);
                 utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                 utftext += String.fromCharCode((c & 63) | 128);
             }

         }

         return utftext;
     },

     Base64._utf8_decode = function (utftext) {
         var string = "";
         var i = 0;
         var c = c1 = c2 = 0;

         while ( i < utftext.length ) {

             c = utftext.charCodeAt(i);

             if (c < 128) {
                 string += String.fromCharCode(c);
                 i++;
             }
             else if((c > 191) && (c < 224)) {
                 c2 = utftext.charCodeAt(i+1);
                 string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                 i += 2;
             }
             else {
                 c2 = utftext.charCodeAt(i+1);
                 c3 = utftext.charCodeAt(i+2);
                 string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                 i += 3;
             }

         }

         return string;
     }
function encodeForm(fobj) {

	var ele;
   var alen;
   var evalue;
   var ilen = fobj.elements.length;
   for (var i = 0 ; i < ilen; i++) {
      ele = fobj.elements[i];
      if(ele.type != "FILE" && ele.type != "select-one") {
         if(isNaN(ele.value)) {
            var ienval;
           	var elvaluefinal = ele.value;
           	var elvalFinal = elvaluefinal.substring(0,1);
           	if(elvalFinal == '~')
           	{           
           	return;
           	}
            ienval = ele.value.replace(/\r\n/g,"\n");
            //alen = ele.value.length;
            //alen = ele.value.replace(/\r\n/g,"\n").length;
            alen = ienval.length;
            evalue = "~" + alen + "." + Base64.encode(ienval);
            ele.maxLength = evalue.length;
            ele.value = evalue;
            }
         }
      }
   return true;
 }


//-->
function showPostOfficePage(page,width,height)
{

		if (window.showModelessDialog) 
      	
      	{
			window.showModelessDialog(page,"Mail","dialogWidth:"+width+"px;dialogHeight:"+height+"px;resizable:no;scrollbars:yes;status:no");
		} 
		else 
		{
      		
			Open_Window_dialog(page,width,height);
		}

}

function showTermsCondForm(page,width,height,val)
{

if(val=='C'){
	
	if(document.dataEncodeSubmitForm.terms.checked)
	{
      	if (window.showModelessDialog) 
      	
	      	{
				window.showModelessDialog(page,"Mail","dialogWidth:"+width+"px;dialogHeight:"+height+"px;resizable:no;scrollbars:yes;status:no");
			} 
			else 
			{
	      		
				Open_Window_dialog(page,width,height);
			}
		}
	    }else if(val=='L')
	    {
	    document.dataEncodeSubmitForm.terms.checked = true;	    
	    	if (window.showModelessDialog) 
      	
	      	{
				window.showModelessDialog(page,"Mail","dialogWidth:"+width+"px;dialogHeight:"+height+"px;resizable:no;scrollbars:yes;status:no");
			} 
			else 
			{
	      		
				Open_Window_dialog(page,width,height);
			}
	    }
}
function showPrivSecForm(page,width,height,val)
{
	if(val=='C'){
	if(document.dataEncodeSubmitForm.privAndSec.checked)
	{
	if (window.showModelessDialog) 
      	
	      	{
				window.showModelessDialog(page,"Mail","dialogWidth:"+width+"px;dialogHeight:"+height+"px;resizable:no;scrollbars:yes;status:no");
			} 
			else 
			{
	      		
				Open_Window_dialog(page,width,height);
			}
		}
	    }else if(val=='L')
	    {
	    var obj =document.dataEncodeSubmitForm.privAndSec;
	        	if(!(obj === UNDEFINED))
			{
			document.dataEncodeSubmitForm.privAndSec.checked = true;
			}
	    	if (window.showModelessDialog) 
      	
	      	{
				window.showModelessDialog(page,"Mail","dialogWidth:"+width+"px;dialogHeight:"+height+"px;resizable:no;scrollbars:yes;status:no");
			} 
			else 
			{
	      		
				Open_Window_dialog(page,width,height);
			}
	    }
	
}
function Open_Window(page,width,height) 
{
	var page = window.open(page, 'Mail', "dependent=YES,dialog=YES,modal=YES,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,width="+width+",height="+height+",resizable=0");
	page.focus()
	document.onclick=function(){
	try
	{
		page.focus();
		return false
	}
	catch(e){}
	}
}
function Open_Window_dialog(page,width,height) 
{
	var page = window.open(page, 'Mail', "dependent=YES,dialog=YES,modal=YES,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,width="+width+",height="+height+",resizable=0");
}

function textCounter(field, maxlimit)
{
	if(field.value.length>maxlimit)
	{
		field.value = field.value.substring(0, maxlimit);
	}
	return true;
}

function checkFileFormat(fileName){
	if(navigator.platform == "Linux") {
		if(fileName.charAt(0) != "/")
		{
			return false;
		}
		if(fileName.charAt(0) == "/" && fileName.charAt(1) == "/")
		{
			return false;
		} else {
			return true;
		}
	} else {
		if(!fileName.charAt(0).match(/^[a-zA-z]/))  
			{
				return false;
			}
			
			var browserName=navigator.appName; 
		
			
			if (browserName=="Microsoft Internet Explorer")
			{ 
			if(fileName.charAt(1) == "" ||!fileName.charAt(1).match(/^[:]/) || !fileName.charAt(2).match(/^[\/\\]/))
			{
				return false;
			}else {
				return true;
			}	
			}
			else if(browserName=="Netscape")
			{
			if(fileName.charAt(1) == "")
			{
			return false;
			}else {
				return true;
			}	
			
			}
			else
			{
			if(fileName.charAt(1) == "")
			{
			return false;
			}else {
				return true;
			}
			
			} 
		
		
	}
}
function checkValidFile1(){
	try{	
		var field1 = document.getElementById('_fileName');
		
		if(field1.value!="" && !checkFileFormat(field1.value)){
			alert(invalidFile);	
			return false;			
		}
		else{
			return true;
		}
	}
	catch(e){
		return true;
	}
}

function checkValidFile2(){
	try{	
		var field2 = document.getElementById('_fileName2');	
		if(field2.value!="" && !checkFileFormat(field2.value)){
			alert(invalidFile);	
			return false;			
		}
		else{
			return true;
		}
	}
	catch(e){
		return true;
	}
}

function checkValidFile3(){
	try{	
		var field3 = document.getElementById('_fileName3');	
		if(field3.value!="" && !checkFileFormat(field3.value)){
			alert(invalidFile);	
			return false;			
		}
		else{
			return true;
		}
	}
	catch(e){
		return true;
	}
}
function getSelected(opt) {
      var selected = new Array();
      var index = 0;
      for (var intLoop=0; intLoop < opt.length; intLoop++) {
         if (opt[intLoop].selected) {
            index = selected.length;
            selected[index] = new Object;
            selected[index].value = opt[intLoop].value;
            selected[index].index = intLoop;
         }
      }
      return selected;
   }
   
   
function setFieldFocus()
{
obj = eval("document.dataEncodeSubmitForm."+sfocus);
	if(!(obj.value === UNDEFINED)){	
	eval("document.dataEncodeSubmitForm."+sfocus).focus();
	}
}
function fnSearchAddress()
{
	document.dataEncodeSubmitForm.strSearchAddress.value = "yes";
	encodeForm(dataEncodeSubmitForm);
	document.dataEncodeSubmitForm.submit();
}

function checkTermsAndSubmit()
{
	
		if(!checkValidFile1()||!checkValidFile2()||!checkValidFile3()){
			return false;
		}
	
		var obj =document.dataEncodeSubmitForm.strSearchAddress;
		if(!(obj === UNDEFINED))
		{
		obj.value="";
		}
		var obj1 = 	document.dataEncodeSubmitForm.langKnown;
		if(!(obj1 === UNDEFINED))
		{
		var selected = getSelected(document.dataEncodeSubmitForm.langKnown.options);		
		var strSel="";
	    for (var item in selected)   
	    strSel += selected[item].value + ",";
	    document.dataEncodeSubmitForm.selectedLang.value=strSel;
		}	
		var obj2 = document.dataEncodeSubmitForm.strSearchAddress;
		if(!(obj2 === UNDEFINED))
		{
			obj2.value="";
		}
		encodeForm(dataEncodeSubmitForm);
		
		document.dataEncodeSubmitForm.submit();	

}

function submitTermsCondForm()
{
	document.dataEncodeSubmitForm.actionType.value="terms_cond";	
	document.dataEncodeSubmitForm.formName.value="dataEncodeSubmitForm";
	var obj =document.dataEncodeSubmitForm.strSearchAddress;
	if(!(obj === UNDEFINED))
	{
	obj.value="";
	}
		if(!checkValidFile1()||!checkValidFile1()||!checkValidFile1()){
		return false;
	}
	encodeForm(dataEncodeSubmitForm);
	document.dataEncodeSubmitForm.submit();
}

function submitPrivacySecForm()
{
	document.dataEncodeSubmitForm.actionType.value="priv_sec";	
	document.dataEncodeSubmitForm.formName.value="dataEncodeSubmitForm";
	var obj =document.dataEncodeSubmitForm.strSearchAddress;	
	if(!(obj === UNDEFINED))
	{
	obj.value="";
	}
	
	encodeForm(dataEncodeSubmitForm);
	
	document.dataEncodeSubmitForm.submit();
	
} 
function dropdownpopulate()
{

document.dataEncodeSubmitForm.drop.value='county';
document.dataEncodeSubmitForm.drop1.value='';
document.dataEncodeSubmitForm.drop2.value = 'county';
encodeForm(dataEncodeSubmitForm);
document.dataEncodeSubmitForm.submit();
}

function postcodePopulate()
{

document.dataEncodeSubmitForm.drop1.value='town';
document.dataEncodeSubmitForm.drop2.value = 'county';
encodeForm(dataEncodeSubmitForm);
document.dataEncodeSubmitForm.submit();
}
function showDataPrivacyForm(page,width,height)
{
	if (window.showModelessDialog) {
			window.showModelessDialog(page,"Mail","dialogWidth:"+width+"px;dialogHeight:"+height+"px;resizable:no;scrollbars:yes;status:no");
	} else {
		Open_Window_dialog(page,width,height);
	}
}
function Open_Window_dialog(page,width,height) 
{
	var page = window.open(page, 'Mail', "dependent=YES,dialog=YES,modal=YES,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,width="+width+",height="+height+",resizable=0");
}

