// JavaScript Document
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_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_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];}
}

function unblur() {
	this.blur();
}

function getLinksToBlur() {
	if (!document.getElementById) return
	links = document.getElementsByTagName("a");
	for(i=0; i<links.length; i++) {
		links[i].onfocus = unblur
	}
}




// Click Map Function
// Change the dropdown menu when you click a map area
// img: Path to highlight image
// opt: Index of selected menu item
function clickMap(img, opt)
{
	// Show Areas
	showMapAreaText(opt);
	// Swap Image
	MM_swapImage('locationimage','',img,1);
	// Change menu
	var menu = MM_findObj('cboLocation');
	menu.options[opt].selected = true;
	
    var menuCat=MM_findObj('cboCategory');
	if (menuCat.options[0].selected==true)
	    menuCat.options[0].innerText='All Activity Gifts';
}



// Select Map Menu
// Highlight the map image when the menu changes
// ff: the select form field
function selectMapMenu(ff)
{
	// Array of map images
	// Array index corresponds to select menu index
	var imgs = Array();
	imgs[0] = "images/map/map_base.gif";
	imgs[1] = "images/map/scotland.gif";
	imgs[2] = "images/map/north.gif";
	imgs[3] = "images/map/wales.gif";
	imgs[4] = "images/map/midlands.gif";
	imgs[5] = "images/map/southwest.gif";
	imgs[6] = "images/map/southeast.gif";
	imgs[7] = "images/map/ireland.gif";
	// Show Areas
	showMapAreaText(ff.selectedIndex);
	// Swap Image
	MM_swapImage('locationimage','',imgs[ff.selectedIndex],1);
}


// Show Map Area Text
// n: the index of the area
function showMapAreaText(n)
{
	// Loop through areas
	for (var i=1; i<=7; ++i) {
		var area = 'area' + i;
		var myid = MM_findObj(area);
		if (i == n) {
			myid.style.display = "block";
		} else {
			myid.style.display = "none";
		}
	}
}

//Function to show popups
function OpenDialog(rsDialogName, rsDialogOptions)
{
    if(rsDialogOptions == "")
         window.open(rsDialogName, null, "height=390px,width=615px,left=50,top=10,status=no,scrollbars=yes");
        //windowshowModalDialog(rsDialogName, null, "dialogHeight:500px;dialogLeft:;dialogTop:;dialogWidth:600px;center:yes;status:no;scroll:yes;help:No;");
    else
        window.open(rsDialogName, null, rsDialogOptions);        
}

function leftTrim(sString) 
{
    while (sString.substring(0,1) == ' ')
        sString = sString.substring(1, sString.length);    
    return sString;
}


function rightTrim(sString) 
{
    while (sString.substring(sString.length-1, sString.length) == ' ')    
        sString = sString.substring(0,sString.length-1);    
    return sString;
}


function trimAll(sString) 
{
    while (sString.substring(0,1) == ' ')    
        sString = sString.substring(1, sString.length);    
    while (sString.substring(sString.length-1, sString.length) == ' ')    
        sString = sString.substring(0,sString.length-1);    
    return sString;
}

//script to set focus to the first input field
function focus_first_field()
{    
    var bFound = false;

    // for each form
    for (f=0; f < document.forms.length; f++)
    {
    // for each element in each form
    for(i=0; i < document.forms[f].length; i++)
    {
      // if it's not a hidden element
      if (document.forms[f][i].type != "hidden")
      {
        // and it's not disabled
        if (document.forms[f][i].disabled != true)
        {
            // set the focus to it
            document.forms[f][i].focus();
            var bFound = true;
        }
      }
      // if found in this element, stop looking
      if (bFound == true)
        break;
    }
    // if found in this form, stop looking
    if (bFound == true)
      break;
    }
}
function GiftPackPopUp( )
{
    window.open('GiftPackPopUp.aspx', null, 'height=390,width=600,status=no,scrollbars=no');
}

function validatePhoneNumber( rsValue , rbAllowEmpty )
{
	// avoid changing things if already formatted correctly
	var reg0Str = /^(\d|\s|-)*$/;
	var reg0 = new RegExp(reg0Str);
	if(rbAllowEmpty == false && trimAll(rsValue)== '')
	{
		return false;
	}
	return  reg0.test(rsValue);
	
}

function ScrollToElement(theElement){

  var selectedPosX = 0;
  var selectedPosY = 0;
              
  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
                        		      
 window.scrollTo(selectedPosX,selectedPosY);

}

function ScrollToElementId(theElementId){

  var theElement = document.getElementById(theElementId );

  var selectedPosX = 0;
  var selectedPosY = 0;
              
  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
                        		      
 window.scrollTo(selectedPosX,selectedPosY);

}

function DecorateSearchString( rsInputString )
{    
    if( rsInputString != null )
        return escape( rsInputString.replace( /(\.|\s|,)+/g,"+") );
    else
    return "";    
}

