
function winOpen(url, width, height)
{
    var win;
    
    width=(width==null)?500:width;
    height=(height==null)?400:height;
    
    win = window.open(url, "Window", "scrollbars=yes,resizable=yes,width=" + width + ",height=" + height); 
    win.focus();
}

function winStatus(sMsg) {
    window.status = sMsg ;
    return true ;
}

function doc(id)
{
	var ie	= (document.all);
	var ns4	= document.layers?true:false;
	var dom	= document.getElementById && !document.all?true:false;

	if (dom)
		return document.getElementById(id);
	else if (ie)
		return document.all[id];
	else if (ns4)
		return document.layers[id];
}


function onlyNumbers(evt) 
{
    // keyCode      Key
    // --------------------------------
    // 48/58        0/9
    // 8            Backspace
    var e = evt;
    var charCode = e.which || e.keyCode;
    var valid = false;
    
    if (charCode >= 48 && charCode <= 58 || charCode==8)
       valid = true;
       
    return valid;
}


function ErrorHandler(element, message) 
{
    doc(element).innerHTML = message;
    doc(element).style.display = "block";
}


function contactValidation()
{
    var errStr = "";
    var valid = true;
    
    // Run thru input fields and check if values are empty. If a value is empty append to the errStr variable.
    if (doc("txtName").value=="") { errStr += "<li>Fullname</li>"; } 
    if (doc("txtEmail").value=="") { errStr += "<li>Email address</li>"; } 
    if (doc("txtEmail").value != "" && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(doc("txtEmail").value))) { errStr += "<li>Email address: incorrect format</li>"; }
    if (doc("txtPhone").value=="") { errStr += "<li>Telephone</li>"; } 
    if (doc("txtAddLine1").value=="") { errStr += "<li>Address line 1</li>"; } 
    //if (doc("txtAddLine2").value=="") { errStr += "<li>Address line 2</li>"; } 
    if (doc("txtPostcode").value=="") { errStr += "<li>Postcode</li>"; }
    if (doc("txtEnquiry").value=="") { errStr += "<li>Enquiry</li>";} 
        
    // If an error appears build list element, display to user and stop form from submitting by returning false.
    if (errStr!="") {
        errStr = "<p>Please complete the following fields before proceeding.</p><ul>" + errStr + "</ul>";
        ErrorHandler("errStr", errStr);
        valid = false;
    }
    
    return valid;
}

function inforeqValidation()
{
    var errStr = "";
    var valid = true;
    
    // Run thru input fields and check if values are empty. If a value is empty append to the errStr variable.
    if (doc("txtName").value=="") { errStr += "<li>Fullname</li>"; } 
    if (doc("txtEmail").value=="") { errStr += "<li>Email address</li>"; } 
    if (doc("txtEmail").value != "" && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(doc("txtEmail").value))) { errStr += "<li>Email address: incorrect format</li>"; }
    if (doc("txtPhone").value=="") { errStr += "<li>Telephone</li>"; } 
    if (doc("txtAddLine1").value=="") { errStr += "<li>Address line 1</li>"; } 
    //if (doc("txtAddLine2").value=="") { errStr += "<li>Address line 2</li>"; } 
    if (doc("txtPostcode").value=="") { errStr += "<li>Postcode</li>"; }
    if (doc("txtDOB").value=="") { errStr += "<li>Date of Birth</li>"; } 
    if (doc("txtFundValue").value=="") { errStr += "<li>Fund value</li>"; } 
    if (doc("txtDateIncome").value=="") { errStr += "<li>Date income required</li>"; } 
        
    // If an error appears build list element, display to user and stop form from submitting by returning false.
    if (errStr!="") {
        errStr = "<p>Please complete the following fields before proceeding.</p><ul>" + errStr + "</ul>";
        ErrorHandler("errStr", errStr);
        valid = false;
    }
    
    return valid;
}

function toggleMenu(mId) {
	//alert(doc("ul_"+mId).style.display);
	if(doc("ul_"+mId).style.display=="") {
		doc("ul_"+mId).style.display="none";
	}
	else {
		doc("ul_"+mId).style.display="";
	}
}

function fsHandler(eID) {
	doc(eID).value=(doc(eID).value).replace(",",""); 
	doc(eID).value=(doc(eID).value).replace(";",""); 
	doc(eID).value=(doc(eID).value).replace("-",""); 
	if(isNaN(doc(eID).value)) {doc(eID).value="";}
	if(doc(eID).value=="" || doc(eID).value < 1000) {doc(eID).value="1000";}
	doc(eID).value = (doc(eID).value * 1).toFixed(2);
	if(doc("gadTFC").value=="") {doc("gadTFC").value=(doc(eID).value * 0.25).toFixed(2);}
	if(doc("gadTFC").value > (doc(eID).value * 0.25)) {doc("gadTFC").value=doc(eID).value * 0.25;}
}

function tfcHandler(eID) {
	doc(eID).value=(doc(eID).value).replace(",",""); 
	doc(eID).value=(doc(eID).value).replace(";",""); 
	doc(eID).value=(doc(eID).value).replace("-",""); 
	if(isNaN(doc(eID).value)) {doc(eID).value="";}
	if(doc(eID).value > (doc("gadFS").value * 0.25)) {alert("TFC must be a maximum of 25% of Fund Size.");doc(eID).value=doc("gadFS").value * 0.25;}
}