function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) { 

    if (typeof(elem) == 'string') elem = document.getElementById(elem); 
    if (elem == null) return; 
    var regg = /(.*)(_nm\.)([^\.]{3,4})$/ 
    var prel = new Array(), img, imgList, imgsrc, mtchd; 
    imgList = elem.getElementsByTagName('img'); 
    for (var i=0; img = imgList[i]; i++) { 
        if (!img.rolloverSet && img.src.match(regg)) { 
            mtchd = img.src.match(regg); 
            img.hoverSRC = mtchd[1]+'_hv.'+ mtchd[3]; 
            img.outSRC = img.src; 
            if (typeof(mouseOver) != 'undefined') { 
                img.hoverSRC = (mouseOver) ? mtchd[1]+'_hv.'+ mtchd[3] : false; 
                img.outSRC = (mouseOut) ? mtchd[1]+'_ou.'+ mtchd[3] : (mouseOver && mouseOutRestore) ? img.src : false; 
                img.mdownSRC = (mouseDown) ? mtchd[1]+'_md.' + mtchd[3] : false; 
                img.mupSRC = (mouseUp) ? mtchd[1]+'_mu.' + mtchd[3] : (mouseOver && mouseDown && mouseUpRestore) ? img.hoverSRC : (mouseDown && mouseUpRestore) ? img.src : false; 
                } 
            if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;} 
            if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;} 
            if (img.mdownSRC) {preLoadImg(img.mdownSRC); img.onmousedown = imgMouseDownSwap;} 
            if (img.mupSRC) {preLoadImg(img.mupSRC); img.onmouseup = imgMouseUpSwap;} 
            img.rolloverSet = true; 
        } 
    } 
    function preLoadImg(imgSrc) { 
        prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc; 
    } 
} 
function imgHoverSwap() {this.src = this.hoverSRC;} 
function imgOutSwap() {this.src = this.outSRC;} 
function imgMouseDownSwap() {this.src = this.mdownSRC;} 
function imgMouseUpSwap() {this.src = this.mupSRC;}


/* generic form submission */

function subFrm(form) {
		document.getElementById(form).submit();

	}
	

function defaultBtn (){
		el = document.getElementById("acceptTerms")
		el.disabled = true
	}
	
function termsok () {
		if(document.getElementById("terms").checked==true) {
		el = document.getElementById("acceptTerms")	
		el.disabled = false
		} else {
		defaultBtn()
		}
	}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function cost() {
	
	var d = document
	var sc = roundNumber(d.getElementById('supcost').value,2)
	
	var dep =  roundNumber(d.getElementById('supcost').value * d.getElementById('comm').value / 100,2)
	d.getElementById('depamt').value = dep
	d.getElementById('comkept').value = dep
	
	d.getElementById('da').value = dep
	d.getElementById('ck').value = d.getElementById('comkept').value
	
	
	if(d.getElementById('fulldept').checked == true) {
			d.getElementById('depamt').value = sc
		}
	
	}
function showOther() {
		d = document.getElementById('otherhidden')
		
		if(document.getElementById('otherCB').checked == true) {
			document.getElementById('otherhidden').style.visibility = 'visible'
			} else {
			document.getElementById('otherhidden').style.visibility = 'hidden'
				}
	}

var isEmail_re       = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/; 
function isEmail (s) { 
   return String(s).search (isEmail_re) != -1; 
}


function checkregform(opt,s) {
	var uo
	uo = opt
	d=document.getElementById('theform')
	if(uo=='1' || s =='1'){
	if(d.strPassword.value != d.password2.value)
	{alert('There is a problem with your password(s). Please check they match or are not empty.')
		return false;
	}
	}
	if(uo=='2'|| s =='1'){
	if(isEmail(d.strEmailAddress.value)== false) {alert('Please enter a valid email address'); d.strEmailAddress.focus()
		return false;
	}
	}
	if(uo=='3'|| s =='1'){
	if(d.strTelephone.value == '' && d.strMobile.value == ''){alert('Please enter either a mobile or a Landline number')
		return false;
	}
	}
	if(uo=='4'|| s =='1'){
	if(d.strFirstName.value == '') {alert("Please enter your first name or initial")
		return false;
	}
	}
	if(uo=='5'|| s =='1'){
	if(d.strLastName.value == '') {alert("Please enter your surname name")
		return false;
	}
	}
	if(uo=='6'|| s =='1'){
	if(d.strAddress1.value == '') {alert("Please your house name or number")
		return false;
	}
	}
	if(uo=='7'|| s =='1'){
	if(d.strPostCode.value == '') {alert("Please your post code")
		return false;
	}
	}
	if(uo=='8'|| s =='1'){
	if(d.marketing.selectedIndex == 0) {alert("Please enter where you heard about us.")
		return false;
	}
	}
}

function checkInsuranceForm() {
	var d 
	d = document
	
	if(d.getElementById('strUserFirstName').value==''){
			alert("Please enter your first name \n")
			d.getElementById('strUserFirstName').focus()
			return false;
		}
	if(d.getElementById('strUserLastName').value=='') {
			alert("Please enter your last name \n")
			d.getElementById('strUserLastName').focus()
			return false;
		}
	if(d.getElementById('strAddress1').value=='') {
			alert("Please enter the first line of your address \n")
			d.getElementById('strAddress1').focus()
			return false;
		}
	if(d.getElementById('strUserPostCode').value=='') {
			alert("Please enter your post code \n")
			d.getElementById('strUserPostCode').focus()
			return false;
		}
	if(d.getElementById('strTelephone').value=='') {
			alert("Please enter your telephone number \n")
			d.getElementById('strTelephone').focus()
			return false;
		}
	if(d.getElementById('strUserEmailAddress').value=='') {
			alert("Please enter your email address \n")
			d.getElementById('strUserEmailAddress').focus()
			return false;
		}
	if(d.getElementById('start').value=='') {
			alert("Please enter when you require insurance from \n")
			d.getElementById('start').focus()
			return false;
		}
		return true;

	}
function checkInsuranceForm2(){
	var d
	d = document
	if(d.getElementById('carmake').value ==''){
		alert('Please select a vehicle make') 
		d.getElementById('carmake').focus()
		return false;
		}
	if(d.getElementById('strModel').value ==''){
		alert('Please enter the vehicle model') 
		d.getElementById('strModel').focus()
		return false;
		}
	}
	
/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.vdetails.start
	var dt1=document.vdetails.end
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
	if (isDate(dt1.value)==false){
		dt1.focus()
		return false
	}
    return true
 }

