// JavaScript Document

function addToFavorites() { 
	if (window.external) { window.external.AddFavorite("http://www.gotravelinsurance.co.uk", "Go Travel Insurance") 
	} 
	else { alert("Sorry! Your browser doesn't support this function.");
	}
}

function GetInfo(ctrl, wn) {
	var a=document.getElementById(ctrl);
	var b=true;
	
	if (a.value==0) {
		b=false;
		alert("Please select the information that you require!");
	}
	wn=(a.value.indexOf("policywording")>0)?1:0
	if (b==true) {
		if (wn==0) {
			MM_openBrWindow(a.value,"info", "width=600,height=400,Scrollbars=Yes");
		}
		else
		{
			MM_goToURL('parent',a.value);return document.MM_returnValue
		}
	}
}

function SetImage(dv, img, pg, txt) {
	var obj=document.getElementById(dv);
	var pg=document.getElementById(pg);
	
	var strUrl="/_assets/production/"+img;
	obj.style.backgroundImage="url("+strUrl+")";
	obj.innerHTML="<p>"+txt+"</p>"
	pg.value=dv;
}

function SetFontColor(dv, Clr) {
	var obj=document.getElementById(dv);
	obj.style.color=Clr
}

function NavRollover(theDiv, img) {

	var a=document.getElementById('pg')
	if(a.tagName !=null) {
	
	if(theDiv.id!=a.value) {
		var strUrl="/_assets/production/"+img;
		theDiv.style.backgroundImage="url("+strUrl+")";
	}
	}
}

function QuoRollover(theDiv, img) {

	var a=document.getElementById('qu')
	if(a.tagName !=null){
	
	if(theDiv.id!=a.value) {
		var strUrl="/_assets/production/"+img;
		theDiv.style.backgroundImage="url("+strUrl+")";
	}
	}
}

function Rollover(obj, img) {

	var ob=document.getElementById(obj);
	var strUrl="/_assets/production/"+img;
	ob.src=strUrl
}

function dRollover(obj, img) {

	var ob=document.getElementById(obj);
	var strUrl="/_assets/production/"+img;
	ob.style.backgroundImage="url("+strUrl+")";
}

// whitespace characters
var whitespace = " \t\n\r";

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}
/****************************************************************/
// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function replaceAll (s, fromStr, toStr)
{
	var new_s = s;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace (fromStr, toStr);
	}
	return new_s;
}

/****************************************************************/

/* PURPOSE:  Since we are using the single tick mark as the
	string delimiter to construct our SQL queries, a string with
	a tick mark in it will cause a SQL error.  Therefore we replace
	all "'" with "''", which eliminates the possibility of a SQL error.
*/

function sqlSafe (s)
{
	var new_s = s;
	new_s = replaceAll (new_s, "'", "|");
	new_s = replaceAll (new_s, "|", "''");
	new_s = replaceAll (new_s, "\"", "|");
	new_s = replaceAll (new_s, "|", "''");
	return new_s;
}

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isEmail(strEmail){
	if (window.RegExp) {	
		var re = new RegExp('^[A-Z0-9_-]{1}[A-Z0-9_\.-]*[@]{1}[A-Z0-9_-]+[\.]{1}[A-Z0-9_-]+[A-Z0-9_\.-]+$', 'i');
		return strEmail.match(re) 
		//return re.test(strEmail);
	}
	else {
		return isEmailNoRegex(strEmail)
	}
}

function isEmailNoRegex(s)
{   if (isEmpty(s)) 
       if (isEmailNoRegex.arguments.length == 1) return defaultEmptyOK;
       else return (isEmailNoRegex.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function printPage(){
window.print();
 
}

function validDate(day,month,year){
	month--;
	var dt = new Date(year,month,day);
	if (dt.getDate()==day && dt.getMonth()==month && dt.getFullYear()==year) return true;
	else return false;
}

function IsNumeric(theValue)
{
  var checkOK = "0123456789";
  var checkStr = theValue;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    return false;
  }

  if (decPoints > 1)
  {
    return false;
  }

  return true;

}

function getFullYear(d) { // d is a date object
	yr = d.getYear();
	if (yr < 1000)
	yr+=1900;
	return yr;
}

function yearDisplay() {

	today = dateToday;
	year=getFullYear(today);
	document.write("<select class='listBorders' name='YearExp' id='YearExp' size='1'>");
	document.write("<option value=''>"+' '+"</option>");	

	for (i=year;i<(year+8);i++){
	
	
	document.write("<option value="+i+">"+i+"</option>");
	}

	document.write("</select>");
}

function yearDisplayBack(controlName) {
	today = dateToday;
	year=getFullYear(today);
	document.write("<select class='listBorders' name='" + controlName + "' id='" + controlName + "' size='1'>");
	document.write("<option value=''>"+' '+"</option>");	
	for (i=year-5;i<=(year);i++){
		document.write("<option value="+i+">"+i+"</option>");
	}
	document.write("</select>");
}


