function clear_hint(field) {
	// Remove the [search] or other hint from the input field
	// but check that the user hasn't typed something in (which
	// we wouldn't want to clear)
	
	if (field.value.match(/\[.*\]/)) {
		// string of the form [hint] is present so clear it
		field.value = "";
	}

}


function check_signon_message() {
	message = url_param( "message" );
	if (message == "expired") {
		alert( "Your signon has expired due to inactivity. Please signon again." );
	}
	else if (message == "failed") {
		alert( "Your signon failed because either your username or password were incorrect. Please try again." );	
	}
}



function url_param(p) {
	// Retrieve an url param specified by p=value
	var re = new RegExp( p + "=([^&]+)" );
	var m = document.location.href.match(re);
	if (m) {
		return m[1];
	}
	else {
		return "";
	}
}



function swap_password_fields() {
	// Hide the text field and show the password field, used on homepage
	// signon
	var p1 = document.getElementById('password1');
	var p2 = document.getElementById('password2');
	
	p2.style.display='inline';
	p2.focus();
	p1.style.display='none';	
	
	p1.name='password2';
	p2.name='password';
}

function popup(page, options) {
    var default_options = { 
        'width' : 400,
        'height' : 400,
        'left' : 20,
        'top': 20,
        'scrollbars': 'yes',
        'resizable': 'yes'
    }
    if (typeof(options) == 'undefined' || options === null) {
        options = default_options;
    } else {
        for (var property in default_options) {
            if (typeof(options[property]) == 'undefined') {
                options[property] = default_options[property]
            }
        }
    }

    var options_str = [];
    for (var opt in options) {
        options_str.push(opt + '=' + options[opt])
    }
	options_str = options_str.join(',');

	return window.open(page,'popup',options_str);
}

function popupBenefitDetails(href) {
    return popup(href, {'width':400, 'height':600})
}

function popupExample(page) {
	var options = 'width=500,height=400,left=20,top=20,scrollbars=yes,resizable=no';

	window.open(page,'popup',options);
		
}

function popupEmail(id) {
	var page = '/ventureguard/email_popup.html';
	var options = 'width=280,height=300,left=20,top=20,scrollbars=no,resizable=no';
	
	switch (id) {
		case 'vg':
			var page = '/ventureguard/email_popup.html';
			break
		case 'sg':
			var page = '/sportsguard/email_popup.html';
			break
		default:
			break
	}

	window.open(page,'popup',options);
		
}


function checkMatch(sName) {
	
	var str1 = document.getElementById(sName).value;
	var str2 = document.getElementById(sName +'2').value;
	
	var msg;
	var name = document.getElementById(sName).alt;
	
	if (name) {
		msg = "The values for '"+name+"' must match.";
	}
	else {
		msg = "The values you entered do not match."
	}
	
	
	if (str1 != str2) {
		alert(msg);
		return false
	}
}


function showHideField(id) {
	var select = document.getElementById(id);
	
	if (select.value == 'Other') {
		document.getElementById(id + 'Other').style.display = 'block';
	}
	else {
		document.getElementById(id + 'Other').style.display = 'none';
	}
}


function copyToClipboard(id) {
	var text = document.getElementById(id).value;
	
	if(window.clipboardData){ var r=clipboardData.setData('Text',text); return 1; }
	else return 0
}



function orderNoEmail(id) {
	//Show the help text
	document.getElementById('divNoEmail').style.display='block';
	//Set the email using the id
	var email = id + '@sportscover.co.uk';
	document.getElementById('username').value = email;
	document.getElementById('username2').value = email;
}


/** Original:  Ronnie T. Moore 
 * Web Site:  The JavaScript Source
 * Dynamic 'fix' by: Nannette Thacker 
 * Web Site: http://www.shiningstar.net 
 * This script and many more are available free online at 
 * The JavaScript Source!! http://javascript.internet.com 
 */
function textAreaLimit(field, maxlimit) 
{
	if(field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
		alert('Character limit exceeded.  Only '+maxlimit+' characters are allowed.');
	}
}

/**
 * http://www.quirksmode.org/js/cookies.html
 */
function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setPromoterNote() 
{
	var promoter_txt = readCookie("insurance_affiliate_name");
	if(promoter_txt)
	{	
		var display_area = document.getElementById("promoter_note_element");
		display_area.title = "Directed here from "+promoter_txt;
	}
}


