var UNDEFINED;
var objForm;
var bfocus;
var sfocus;
//To Show the post office
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.dataSubmitForm.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')
	    {
	       
	    	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);
			}
			 document.dataSubmitForm.terms.checked = true;	
	    }
}
function showPrivSecForm(page,width,height,val)
{
	if(val=='C'){
	if(document.dataSubmitForm.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.dataSubmitForm.privAndSec;
			if(!(obj === UNDEFINED))
			{
			document.dataSubmitForm.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;
			}
			if(fileName.charAt(1) == "" ||!fileName.charAt(1).match(/^[:]/) || !fileName.charAt(2).match(/^[\/\\]/))
			{
				return false;
			} else {
				return true;
			}	
		
	}
}
function checkValidFile1(){
	try{	
		var field1 = document.getElementById('_fileName');	
		if(field1.value!="" && !checkFileFormat(field1.value)){
			alert('<%=appRes.getString("alertmsg23","Invalid fildsfsdfasde1 format")%>');	
			return false;			
		}
		else{
			return true;
		}
	}
	catch(e){
		return true;
	}
}

function checkValidFile2(){
	try{	
		var field2 = document.getElementById('_fileName2');	
		if(field2.value!="" && !checkFileFormat(field2.value)){
			alert('<%=appRes.getString("alertmsg23","Invalid file2 format")%>');	
			return false;			
		}
		else{
			return true;
		}
	}
	catch(e){
		return true;
	}
}

function checkValidFile3(){
	try{	
		var field3 = document.getElementById('_fileName3');	
		if(field3.value!="" && !checkFileFormat(field3.value)){
			alert('<%=appRes.getString("alertmsg23","Invalid file3 format")%>');	
			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.dataSubmitForm."+sfocus);
	if(!(obj.value === UNDEFINED)){	
	eval("document.dataSubmitForm."+sfocus).focus();
	}
}
function fnSearchAddress()
{
	document.dataSubmitForm.strSearchAddress.value = "yes";
	document.dataSubmitForm.prepopulate.value = "true";
	document.dataSubmitForm.submit();
}

function fnSearchAddressDefault(){
	document.dataSubmitForm.prepopulate.value = "false";
}

function checkTermsAndSubmit()
{
	if(submitted == "false")
	{
	var obj =document.dataSubmitForm.strSearchAddress;
	if(!(obj === UNDEFINED))
	{
	obj.value="";
	}
	var obj1 = 	document.dataSubmitForm.langKnown;
	
	if(!(obj1 === UNDEFINED))
	{
	var selected = getSelected(document.dataSubmitForm.langKnown.options);		
	var strSel="";
    for (var item in selected)   
    strSel += selected[item].value + ",";
    document.dataSubmitForm.selectedLang.value=strSel;
	}	
	var obj2 = document.dataSubmitForm.strSearchAddress;
	
	if(!(obj2 === UNDEFINED))
	{
		obj2.value="";
	}
	submitted = "true";
	document.dataSubmitForm.submit();
	}	
}

function submitTermsCondForm()
{
	document.dataSubmitForm.actionType.value="terms_cond";	
	document.dataSubmitForm.formName.value="dataSubmitForm";
	var obj =document.dataSubmitForm.strSearchAddress;
	if(!(obj === UNDEFINED))
	{
	obj.value="";
	}
		if(!checkValidFile1()||!checkValidFile1()||!checkValidFile1()){
		return false;
	}
	document.dataSubmitForm.submit();
}

function submitPrivacySecForm()
{
	document.dataSubmitForm.actionType.value="priv_sec";	
	document.dataSubmitForm.formName.value="dataSubmitForm";
	var obj =document.dataSubmitForm.strSearchAddress;	
	if(!(obj === UNDEFINED))
	{
	obj.value="";
	}
	document.dataSubmitForm.submit();
} 
function dropdownpopulate()
{

document.dataSubmitForm.drop.value='county';
document.dataSubmitForm.drop1.value='';
document.dataSubmitForm.drop2.value = 'county';
document.dataSubmitForm.submit();
}

function postcodePopulate()
{

document.dataSubmitForm.drop1.value='town';
document.dataSubmitForm.drop2.value = 'county';
document.dataSubmitForm.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");
}
