gIsImagePreloadDone = false; // becomes true after loading of navigation

/*
	dom checker
*/
dom = (document.getElementById)? true : false;
ie4 = (document.all)? true : false;
ns6= (dom && !ie4)? true : false;
ns4 = (document.layers)? true:false;

var submitCount = 0;
var myRegExp = "@";
var Emailfilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i


 function getObj(objID) 
	{
	    if (document.getElementById)
	    {
	        if (document.getElementById(objID)==null)
	        objID="ctl00_cphContent_"+objID;
	        
	        return document.getElementById(objID)
	    }
	    else if (document.all)
	    {
	        if (document.all(objID)==null)
	        objID="ctl00_cphContent_"+objID;
	        
	        return document.all[objID];
	    }
	    else if (document.layers)
	    {
	        if (document.layers(objID)==null)
	        objID="ctl00_cphContent_"+objID;
	        	    
	        return document.layers[objID];
	    }
	}


/*function ShowSignIn show and hide the signin and signout table for GCCI login bar*/

function ShowSignIn(obj1, obj2)
{	
	var objvisible=getObj(obj1);
	var objunvisible=getObj(obj2);
	objvisible.style.display = 'block';
	objunvisible.style.display = 'none';
	if(obj1=="signin")
	{
	    getObj("userName").value="";
	    getObj("password").value="";
	    getObj("userName").focus();
	}
}

/*Function SignIn validate the member_id and password field and perform form action */


function SignIn()
{

    var MemberId=getObj("userName").value;
    var Password=getObj("password").value;
   
    if(MemberId==""||MemberId==null)
    {
        alert('Please enter your email address or 16 digit Best Western Rewards account number');
        getObj("userName").focus();
        return false;
    }
    
    
    var ForEmail = MemberId.search(myRegExp);
    if(ForEmail != -1)
	{
	    if (!Emailfilter.test(MemberId))
		{
			alert("Please enter your email address or 16 digit Best Western Rewards account number");
			getObj("userName").focus();
            getObj("userName").select();
			return false;
		}
	} 
    else
	{
	    var checkvalue=parseFloat(MemberId);
	    
	    if((MemberId!=checkvalue) || (MemberId.indexOf(".")>0))
	    {
	        alert('Please enter your email address or 16 digit Best Western Rewards account number')
	        getObj("userName").focus();
            getObj("userName").select();
	        return false;
	    }
	    if(MemberId.length<16)
        {
            alert("Please enter your 16 digit Best Western Rewards account number");
            getObj("userName").focus();
            getObj("userName").select();
            return false;
        }
	    
	}
    if(Password==""||Password==null)
    {
        alert('Password must be between 5 and 8 characters in length.');
        getObj("password").focus();
        return false;
    }
    if(Password.length<5)
    {
        alert("Password must be between 5 and 8 characters in length.");
        getObj("password").focus();
        return false;
    }

   if (submitCount == 0)
   {
        getObj("url").value="https://goldcrownclub.bestwestern.com/members/benefits.asp?loginRedirect=true";
        getObj("aspnetForm").target="_blank";
         getObj("aspnetForm").methos="post";
      
       //getObj("aspnetForm").action="http://www.bestwestern.com/index.asp?loginRedirect=true";
        getObj("aspnetForm").action="https://book.bestwestern.com/bestwestern/login.do";
        //getObj("aspnetForm").action="https://goldcrownclub.bestwestern.com/";

        getObj("aspnetForm").submit(); 
        
       // <form name=login method=post action="https://book.bestwestern.com/bestwestern/login.do" >
 
	//<input type="hidden" name="url">

        submitCount++;
        return true;
   }
   else 
   {
      alert("This form has already been submitted.  Thanks!");
      return false;
   }
    
    
}

function setdefault(e)
{
  var isIE = document.all?true:false;
  var isNS = document.layers?true:false;	 
  var key = (isIE) ? window.event.keyCode : e.which; 

    if( key == 13){    
    if(getObj("booknow_Book")!=null)
      getObj("booknow_Book").disabled=true;
	 // getObj("signinsm").onclick()	  
	 // __doPostBack('signinsm','');

    var MemberId=getObj("userName").value;
    var Password=getObj("password").value;
   
    if(MemberId==""||MemberId==null)
    {
        alert('Please enter your email address or 16 digit Best Western Rewards account number');
        getObj("userName").focus();
        return false;
    }
    
    
    var ForEmail = MemberId.search(myRegExp);
    if(ForEmail != -1)
	{
	    if (!Emailfilter.test(MemberId))
		{
			alert("Please enter your email address or 16 digit Best Western Rewards account number");
			getObj("userName").focus();
            getObj("userName").select();
			return false;
		}
	} 
    else
	{
	    var checkvalue=parseFloat(MemberId);
	    
	    if((MemberId!=checkvalue) || (MemberId.indexOf(".")>0))
	    {
	        alert('Please enter your email address or 16 digit Best Western Rewards account number')
	        getObj("userName").focus();
            getObj("userName").select();
	        return false;
	    }
	    if(MemberId.length<16)
        {
            alert("Please enter your 16 digit Best Western Rewards account number");
            getObj("userName").focus();
            getObj("userName").select();
            return false;
        }	    
	}
	
    if(Password==""||Password==null)
    {
        alert('Password must be between 5 and 8 characters in length.');
        getObj("password").focus();
        return false;
    }
    
    if(Password.length<5)
    {
        alert("Password must be between 5 and 8 characters in length.");
        getObj("password").focus();
        return false;
    }

   if (submitCount == 0)
	   {
	   
	    getObj("url").value="https://goldcrownclub.bestwestern.com/members/benefits.asp?loginRedirect=true";
        getObj("aspnetForm").target="_blank";
        getObj("aspnetForm").methos="post";
        getObj("aspnetForm").action="https://book.bestwestern.com/bestwestern/login.do";
        getObj("aspnetForm").submit(); 
	    if(getObj("booknow_Book")!=null)
        getObj("booknow_Book").disabled=false;
	        //submitCount++;
	        return true;
	   }
   else 
	   {
	      alert("This form has already been submitted.  Thanks!");
	      return false;
	   }
	 
	 
    }
    else
    {
   		 return ;
    }

}

function toggleForm(objName, varStatus) {
	/*
		function to show and hide the form elements 
		made for the review and reserve and join pages
	*/
	
	// get the object
	objSection = getObject(objName);
	
	if (varStatus == 'show') {
		// show the section
		objSection.style.display = 'block';
	} else {
		// hide the section
		objSection.style.display = 'none';
		
	}
}

function makeRand(maxNum) {
	/*
		creates a random number between 1 -> maxNum
	*/
	rnd = Math.round((maxNum * Math.random()));
	rnd = (rnd == 0)? makeRand(maxNum) : rnd;
	return rnd;
}

function changeNavBg(id, bkImage, base) {
	/*
		function to change the background for the navigation. 
		Takes the td id for that navigation item and the name 
		of the background image and replaces them depending
		on the state that they need to change to or out of.
	*/
	
	// get the 3 images to be changed out
	newImagel = "url(" + base + "images/nav/" + bkImage + "-l.gif)";
	newImage = "url(" + base + "images/nav/" + bkImage + ".gif)";
	newImager = "url(" + base + "images/nav/" + bkImage + "-r.gif)";
	
	// get the object
	tdObjl = getObject(id + "l");
	tdObj = getObject(id);
	tdObjr = getObject(id + "r");
	
	// change out the different ids to the new images
	if (tdObj) {
		tdObjl.style.backgroundImage = newImagel;
		tdObj.style.backgroundImage = newImage;
		tdObjr.style.backgroundImage = newImager;
	} else {
		return;
	}
}

function getObject(oID) {
	/*
		function that returns the element based on the browser
		capitalities - ns4 will return null if the obj doesn't exist
	*/
	if (dom) {
		obj = document.getElementById(oID);
	} else if (ie4) {
		obj = document.all(oID);
	} else if (ns4) {
		obj = document.layers(oID);
		if (!obj)
			return null;
	}
	return obj;
}



function promoChanger() {
	/*
		this function changes out the images for 
		the promos so that there are two more
		in the changing area - will loop around 
		and around
	*/
	promoImgName1 = this.promoAreaExt + "Img1";
	promoImgName2 = this.promoAreaExt + "Img2";
	
	obj1 = document.images[promoImgName1];
	obj2 = document.images[promoImgName2];
	
	imgArrayLength = this.imageName.length - 1;
	
	nextPromoPlace = ((this.currentPromoPlace + 1) > imgArrayLength)? 0 : this.currentPromoPlace + 1;
	nextPlusPromoPlace = ((nextPromoPlace + 1) > imgArrayLength)? 0 : nextPromoPlace + 1;
		
	this.currentPromoPlace = nextPlusPromoPlace;
	
	obj1.src = '../images/promo/' + this.imageName[nextPromoPlace]
	obj2.src = '../images/promo/' + this.imageName[nextPlusPromoPlace]
}

function ldLinks() {
	/*
		function to load the images into an array when the 
		loadLinks part of the object is called
	*/
	args=ldLinks.arguments;
	for (var i=0;i<args.length;i++) {
		argsSplt = args[i].split("|")
		this.linkName[i] = argsSplt[0]
		this.linkTarget[i] = ((argsSplt[1] != "") && (argsSplt[1] != null))? argsSplt[1] : "";
	}
}

function ldImages()
 {
	/*
		function to load the images into an array when the 
		loadImages part of the object is called
	*/
	args=ldImages.arguments;
	for (var i=0;i<args.length;i++)
	 {
		this.imageName[i] = args[i];
	 }
}

function linkOut(lID)
 {
	/*
		function that controls what the user will link out to when
		a promotion is clicked
	*/
	imgArrayLength = this.imageName.length - 1;
	if (lID == 1)
	 {
		place = this.currentPromoPlace;
	} 
	else if (lID == 2)
	 {
		place = ((this.currentPromoPlace + 1) > imgArrayLength)? 0 : this.currentPromoPlace + 1;
	}
	if (this.linkTarget[place] != "")
	 {
		alert(this.linkName[place])
		window.open(this.linkName[place], this.linkTarget[place]);
	} 
	else 
	{
		document.location.href = this.linkName[place];
	}
}

function promoImageChange(AreaExt) {
	/*
		object to handle the promo images movements
		
		it changes out the two images within the based on the
		promoAreaExt variable as long as that extension has the Img1 and Img2
		attached to the end of the image. eg. ptnrImg1
	*/
	this.currentPromoPlace = 0;
	this.imageName = Array();
	this.linkName = Array();
	this.linkTarget = Array();
	this.loadImages = ldImages;
	this.loadLinks = ldLinks;
	this.promoAreaExt = AreaExt;
	this.promoNext = promoChanger;
	this.promoLink = linkOut;
}

partners = new promoImageChange('ptnr');
partners.loadImages("promo-holding-partner.jpg","promo-holding-partner-1.jpg","promo-holding-partner-2.jpg","promo-holding-partner-3.jpg","promo-holding-partner-4.jpg");
partners.loadLinks("http://www.digitaria.com", "http://www.google.com", "http://www.yahoo.com","http://www.google.co.nz");

offers = new promoImageChange('offr');
offers.loadImages("promo-holding-partner.jpg","promo-holding-partner-1.jpg","promo-holding-partner-2.jpg","promo-holding-partner-3.jpg","promo-holding-partner-4.jpg");
offers.loadLinks("http://www.digitaria.com|blank", "http://www.google.com", "http://www.yahoo.com|blank","");

function preload(imgObj,imgSrc)
 {
	/*
		function to preload images
	*/
	if (document.images)
	 {
		eval(imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
	}
}

function changeImage(imgName,imgObj,layer)
 {
	/*
		function to do rollovers of images
	*/
	if (gIsImagePreloadDone == true)
	 {
		if (document.images)
		 {
			if (document.layers)
			 {
				if (layer!=null)
				{
					eval('document.layers.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src');
				} 
				else 
				{
					document.images[imgName].src = eval(imgObj+".src");
				}
			}
			 else
			  {
				document.images[imgName].src = eval(imgObj+".src");
			}
		}
	}
}

function call_jumpMenu(selObj,restore)
{ //v3.0
  if(selObj.options[selObj.selectedIndex].value != " ")
  {
	  target='parent';
	  eval("parent.location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) 
	  selObj.selectedIndex=0;
	  
  }
  else
  {
  return false;
  }
}

