// JavaScript Document

<!-- hide from old browsers
  function GetDay(intDay){
    var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", 
                         "Thursday", "Friday", "Saturday")
    return DayArray[intDay]
    }

  function GetMonth(intMonth){
    var MonthArray = new Array("January", "February", "March",
                               "April", "May", "June",
                               "July", "August", "September",
                               "October", "November", "December") 
    return MonthArray[intMonth] 	  	 
    }
  function getDateStrWithDOW(){
    var today = new Date()
    var year = today.getYear()
    if(year<1000) year+=1900
    var todayStr = GetDay(today.getDay()) + "<br/>"
    todayStr += GetMonth(today.getMonth()) + " " + today.getDate()
    todayStr += ", " + year
    return todayStr
    }
//-->

function removeC()
{
	document.getElementById("txtsearch").style.background = "url('')"; 
}

function reinstateC() 
{
	document.getElementById("txtsearch").style.background = "url('assets/search_diabetes.gif')"; 
}

var newwindow;
function contact(){
	newwindow=window.open("contact/contact.asp",'name','height=300,width=330');
	
}
var newwindowXY;
function contactRoot(){
	newwindowXY=window.open("../contact/contact.asp",'name','height=300,width=330');
	
}

var newwindow2;
function contactRSB(){
	newwindow2=window.open("contact/contactRSB.asp",'name','height=300,width=330');
	
}
var newwindow3;
function contactE(){
	newwindow3=window.open("contact/contactE.asp",'name','height=300,width=330');
	
}

var newwindowX;
function contactC(){
	newwindowX=window.open("contact/contactC.asp",'name','height=300,width=330');
	
}

var newwindowY;
function enlarge(image, urltitle){
	newwindowY=window.open("enlarge.asp?i=" + image + "&t=" + urltitle + "",'name','height=600,width=700');
	
}

function clear(thisField)
{
  if (thisField.value == thisField.defaultValue)
	{
	thisField.value = ''; 
	thisField.focus();
	}
  
}

function clearHelpText(thisField)
{
  if (thisField.value == thisField.defaultValue)
	{
	thisField.value = ''; 
	thisField.focus();
	}
	
  
}



function check_form(theForm) {
	if (parseInt(theForm.heightmtr.value)<1) { theForm.heightmtr.value = ""; }
	if (parseInt(theForm.weightkg.value)<1) { theForm.weightkg.value = ""; }
	


	ResetValidation();
	Validate(0,"NAME","applicant1_name","Please enter your Name", false);
	Validate(0,"NAME","applicant1_surname","Please enter your surname", false);
	Validate(0,"PHONE","applicant1_homephone", "Please enter your telephone number", false);
	Validate(0,"PHONE","applicant1_mobilephone", "Please enter your Mobile number", false);
	Validate(0,"PHONE","applicant1_workphone", "Please enter your Work telephone number", false);
	Validate(0,"EMAIL","applicant1_email", "Please enter a valid Email Address i.e. you@somewhere.com", false);

	return validateForm(theForm);
}


// this is for hovering

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// end hovering


//validate tarvel ins

function Validate(theform)
{

//validate FirstName

var checkDIS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- ";

	var checkStr = theform.FirstName.value;

	var allValid = true;

	if (checkStr == "")
		allValid = false;
		
	if (checkStr == "firstname")
		allValid = false;
		
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!allValid)
			{
				alert("Please enter your First Name");
				theform.FirstName.focus();
				return (false);
			}


//validate Surname

var checkDIS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- ";

	var checkStr = theform.Surname.value;

	var allValid = true;

	if (checkStr == "")
		allValid = false;
if (checkStr == "surname")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!allValid)
			{
				alert("Please enter your Surname");
				theform.Surname.focus();
				return (false);
			}




//validate street

var checkDIS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";

	var checkStr = theform.Street.value;

	var allValid = true;

	if (checkStr == "")
		allValid = false;
if (checkStr == "address")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!allValid)
			{
				alert("Please enter your Street");
				theform.Street.focus();
				return (false);
			}
			
			//validate city

var checkDIS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";

	var checkStr = theform.Area.value;

	var allValid = true;

	if (checkStr == "")
		allValid = false;
if (checkStr == "city")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!allValid)
			{
				alert("Please enter your City");
				theform.Area.focus();
				return (false);
			}
			
			
			
//validate postcode

var checkDIS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";

	var checkStr = theform.PostCode.value;

	var allValid = true;

	if (checkStr == "")
		allValid = false;
if (checkStr == "postcode")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!allValid)
			{
				alert("Please enter your postcode");
				theform.PostCode.focus();
				return (false);
			}
			
//validate HomeTel

var checkDIS = "()+0123456789- ";

	var checkStr = theform.Phone1.value;

	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "")
		allValid = false;

if (checkStr == "contact tel")
		allValid = false;
		
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);

			if (ch == "(")
				openBrace = true;

			if ((ch == ")") && !openBrace)
			{
				allValid = false;
				break;
			}

			if (ch == ")")
			{
				closeBrace = true;
				openBrace = false;
			}

			if ((ch == "+") && (i != 0))
			{
				allValid = false;
				break;
			}

			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}

			if (openBrace)
				allValid = false;

			if (!allValid)

			{
				alert("Please enter a Contact Telephone Number");
				theform.Phone1.focus();
				return (false);
			}



//validate Email

var checkDIS = "-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@.";

	var checkStr = theform.Email.value;

	var allValid = true;

	var atSign = false;

	var dotOk = false;

	if (checkStr == "")
		allValid = false;
		
		if (checkStr == "your@email.co.uk")
		allValid = false;
		

	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);

			if ((ch == "@") && (i > 0))
				atSign = true;

			if ((ch == ".") && (atSign == true) && (i < (checkStr.length - 1)))
				dotOk = true;

			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;

			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!dotOk)
				allValid = false;

			if (!allValid)
			{
				alert("Please enter a valid Email Address i.e. you@somewhere.com");
				theform.Email.focus();
				return (false);
			}


			

	//validate smoker
if (!(theform.type[0].checked || theform.type[1].checked || theform.type[2].checked || theform.type[3].checked)) {
alert("Please enter which type of Diabetic Travel Insurance you require.");
   return false;
}

	
//Validate the date of birth

var checkDIS = "()+0123456789- ";

	var checkStr = theform.DobDay.value;

	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "")
		allValid = false;
if (checkStr == "0")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);

			if (ch == "(")
				openBrace = true;

			if ((ch == ")") && !openBrace)
			{
				allValid = false;
				break;
			}

			if (ch == ")")
			{
				closeBrace = true;
				openBrace = false;
			}

			if ((ch == "+") && (i != 0))
			{
				allValid = false;
				break;
			}

			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}

			if (openBrace)
				allValid = false;

			if (!allValid)
			{
				alert("Please enter day of birth");
				theform.DobDay.focus();
				return (false);
			}


//Validate the Month of birth

var checkDIS = "()+0123456789- ";

	var checkStr = theform.DobMon.value;

	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "0")
		allValid = false;
if (checkStr == "0")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);

			if (ch == "(")
				openBrace = true;

			if ((ch == ")") && !openBrace)
			{
				allValid = false;
				break;
			}

			if (ch == ")")
			{
				closeBrace = true;
				openBrace = false;
			}

			if ((ch == "+") && (i != 0))
			{
				allValid = false;
				break;
			}

			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}

			if (openBrace)
				allValid = false;

			if (!allValid)
			{
				alert("Please enter Month of birth");
				theform.DobMon.focus();
				return (false);
			}


//Validate the year of birth

var checkDIS = "()+0123456789- ";

	var checkStr = theform.DobYear.value;

	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "")
		allValid = false;
if (checkStr == "0")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);

			if (ch == "(")
				openBrace = true;

			if ((ch == ")") && !openBrace)
			{
				allValid = false;
				break;
			}

			if (ch == ")")
			{
				closeBrace = true;
				openBrace = false;
			}

			if ((ch == "+") && (i != 0))
			{
				allValid = false;
				break;
			}

			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}

			if (openBrace)
				allValid = false;

			if (!allValid)
			{
				alert("Please enter year of birth");
				theform.DobYear.focus();
				return (false);
			}



//Validate the date of birth

var checkDIS = "()+0123456789- ";

	var checkStr = theform.travelDobDay.value;

	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "")
		allValid = false;
if (checkStr == "0")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);

			if (ch == "(")
				openBrace = true;

			if ((ch == ")") && !openBrace)
			{
				allValid = false;
				break;
			}

			if (ch == ")")
			{
				closeBrace = true;
				openBrace = false;
			}

			if ((ch == "+") && (i != 0))
			{
				allValid = false;
				break;
			}

			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}

			if (openBrace)
				allValid = false;

			if (!allValid)
			{
				alert("Please enter day of travel");
				theform.travelDobDay.focus();
				return (false);
			}


//Validate the Month of birth

var checkDIS = "()+0123456789- ";

	var checkStr = theform.travelDobMon.value;

	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "0")
		allValid = false;
if (checkStr == "0")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);

			if (ch == "(")
				openBrace = true;

			if ((ch == ")") && !openBrace)
			{
				allValid = false;
				break;
			}

			if (ch == ")")
			{
				closeBrace = true;
				openBrace = false;
			}

			if ((ch == "+") && (i != 0))
			{
				allValid = false;
				break;
			}

			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}

			if (openBrace)
				allValid = false;

			if (!allValid)
			{
				alert("Please enter Month of travel");
				theform.travelDobMon.focus();
				return (false);
			}


//Validate the year of birth

var checkDIS = "()+0123456789- ";

	var checkStr = theform.travelDobYear.value;

	var allValid = true;

	var openBrace = false;

	var closeBrace = false;

	if (checkStr == "")
		allValid = false;
if (checkStr == "0")
		allValid = false;
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);

			if (ch == "(")
				openBrace = true;

			if ((ch == ")") && !openBrace)
			{
				allValid = false;
				break;
			}

			if (ch == ")")
			{
				closeBrace = true;
				openBrace = false;
			}

			if ((ch == "+") && (i != 0))
			{
				allValid = false;
				break;
			}

			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}

			if (openBrace)
				allValid = false;

			if (!allValid)
			{
				alert("Please enter year of travel");
				theform.travelDobYear.focus();
				return (false);
			}



var checkDIS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- ";

	var checkStr = theform.travelling.value;

	var allValid = true;

	if (checkStr == "")
		allValid = false;
		
	if (checkStr == "destination")
		allValid = false;
		
	for (i = 0; i < checkStr.length; i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0; j < checkDIS.length; j++)

			if (ch == checkDIS.charAt(j))
					break;
			if (j == checkDIS.length)
			{
				allValid = false;
				break;
			}
		}
			if (!allValid)
			{
				alert("Please enter your destination");
				theform.travelling.focus();
				return (false);
			}




	return (true);
}


function doThis(gotod) {
	window.open("../../media-channel/trailer_player.asp?cID=" + gotod, 'X', 'width=565,height=300,toolbar=0,scrollbars=0,screenX=200,screenY=200,left=200,top=200');
}




  function initForm() {
    document.convertbloodsugar.var_mgdl.value = "" ;
    document.convertbloodsugar.var_mmoll.value = "" ;
    document.convertbloodsugar.var_mgdl.focus() ;
  }


  function convert(strAction) {
    var var_in1 ;   
    var var_out1 ;  
    var var_conv ; 

    if (strAction == "from_mgdl") {
        var_in1 = document.convertbloodsugar.var_mgdl ;
        var_out1 = document.convertbloodsugar.var_mmoll ;
        var_conv = 1/18 ;
    }
    else {
        var_in1 = document.convertbloodsugar.var_mmoll ;
        var_out1 = document.convertbloodsugar.var_mgdl ;
        var_conv = 18 ;
    }

    // Do the math

    var_out1.value = (parseFloat(var_in1.value) + 0) * var_conv;

 
    if (var_out1.value == "NaN" || var_out1.value == 0) {
      var_out1.value = "";
      alert("Please enter a number greater than 0.");
      var_in1.value = "";
      var_in1.focus();
    }
  }
  
  function calcNum(theForm)	{
	var a = parseFloat(document.atest.num.value)
	theForm.out1.value = (Math.round(a * 33.3)-86)
	//theForm.sameNum.value = a
}

 function convertHB(strAction) {
    var var_in1 ;   
    var var_out1 ;  
    var var_conv ; 

    if (strAction == "from_hba1c") {
        var_in1 = document.convertHB1.var_hba1c.value ;
        var_out1 = document.convertHB1.var_mgdl ;
		
		var_conv = (Math.round(parseFloat(var_in1) * 33.3)-86);
		
		var_conv = ((var_conv + 0) * 1/18); // for mmol
		
		var_out1.value = var_conv;
		
    }
    else {
        var_in1 = document.convertHB1.var_mgdl.value ;
        var_out1 = document.convertHB1.var_hba1c ;
		
		var_conv = Math.round((var_in1 + 0) * 18); // for mmol
		
        var_conv = Math.round((parseFloat(var_conv) + 86)/33.3);
		
		var_out1.value = var_conv;
    }

    // Do the math

    

    if (var_out1.value == "NaN" || var_out1.value == 0) {
      var_out1.value = "";
      alert("Please enter a number greater than 0.");
      var_in1.value = "";
      var_in1.focus();
    }
  }
  
  
    function initFormHB() {
    document.convertHB1.var_hba1c.value = "" ;
    document.convertHB1.var_mgdl.value = "" ;
    document.convertHB1.var_hba1c.focus() ;
  }

function hov(loc,cls){
   if(loc.className)
      loc.className=cls;}
	  
function calcNum(theForm)	{
	var a = parseFloat(document.convertp2b.enteredvalue.value);
	
	document.convertp2b.presult.value = (Math.round(a * 10 * 1.12)/10);
	document.convertp2b.p1.value = (Math.round(a * 8 * 1.12)/10);
	document.convertp2b.p2.value = (Math.round(a * 12 * 1.12)/10);
	
}

function calcNum_1(theForm)	{
	var a = parseFloat(document.convertp2b2.enteredvalue2.value);
	document.convertp2b2.presult2.value = (Math.round(a * 10 / 1.12)/10);
	document.convertp2b2.p12.value = (Math.round(a * 8 / 1.12)/10);
	document.convertp2b2.p122.value = (Math.round(a * 12 / 1.12)/10);
	
}


function calcNum_british(theForm)	{
	var a = parseFloat(document.convertp2b_british.enteredvalue_british.value);
	
	document.convertp2b_british.presult_british.value = (Math.round(a * 10 * 1.12)/10);
	document.convertp2b_british.p1_british.value = (Math.round(a * 8 * 1.12)/10);
	document.convertp2b_british.p2_british.value = (Math.round(a * 12 * 1.12)/10);
	
}

function calcNum_1_british(theForm)	{
	var a = parseFloat(document.convertp2b2_british.enteredvalue2_british.value);
	document.convertp2b2_british.presult2_british.value = (Math.round(a * 10 / 1.12)/10);
	document.convertp2b2_british.p12_british.value = (Math.round(a * 8 / 1.12)/10);
	document.convertp2b2_british.p122_british.value = (Math.round(a * 12 / 1.12)/10);
	
}

function calcinsulin(theForm)	{
	var a = parseFloat(document.ins_form.vw.value);
	var b = parseFloat(document.ins_form.vm.value);
	var c = parseFloat(document.ins_form.vf.value);
	var d = parseFloat(document.ins_form.vg.value);
	var factor_mult;
	var total_out;
	
	if (d == 1) { 
		factor_mult = 14.3;
		} else { 
		factor_mult = 13.2;
		}
	
	total_out = Math.round(((a - 5)*2)*c/(b*factor_mult)-b);
	document.ins_form.p1.value = total_out;
}

function chatroomGuidelines()
{

window.open("http://www.diabetes.co.uk/diabetes-chat/guidelines.html", 'X', 'width=740,height=560,toolbar=0,scrollbars=1,screenX=200,screenY=200,left=200,top=200');
}


function resetBoth() {
	resetEnglish();
	resetMetric();
}

function resetEnglish() {

	document.getElementById("txtHeightFeet").value = "";
	document.getElementById("txtHeightInches").value = "";
	document.getElementById("txtWeightStones").value = "";
	document.getElementById("txtWeightPounds").value = "";
	document.getElementById("txtBMI").value = "";

}

function resetMetric() {

	document.getElementById("txtHeightMetres").value = "";
	document.getElementById("txtWeightKilos").value = "";
	document.getElementById("txtBMI").value = "";

}

function calcEnglish() {

	resetMetric();
	var feet = (document.getElementById("txtHeightFeet").value)*1;
	var inches = (document.getElementById("txtHeightInches").value)*1;
	var stones = (document.getElementById("txtWeightStones").value)*1;
	var pounds = (document.getElementById("txtWeightPounds").value)*1;
	
	var meters = (inches + (feet * 12)) / 39.36;
	var kilos = (pounds + (stones*14)) / 2.2;
	
	document.getElementById("txtHeightMetres").value = twodecplaces(meters);
	document.getElementById("txtWeightKilos").value = twodecplaces(kilos);
	document.getElementById("txtBMI").value = twodecplaces(kilos/(meters*meters));
	
	
}
function calcMetric() {
	resetEnglish();
	var meters = (document.getElementById("txtHeightMetres").value)*1;
	var kilos = (document.getElementById("txtWeightKilos").value)*1;
	document.getElementById("txtBMI").value =  twodecplaces(kilos/(meters*meters));
}
function twodecplaces(num) {
	return Math.floor(num*100)/100;
}

function jump_to_meter_function()
   {
   var w = document.jump_to_meter.metersdd.selectedIndex;
   var url_add = document.jump_to_meter.metersdd.options[w].value;
   window.location.href = url_add;
   }
