// Skin Specific JS goes here. The jQuery library has already been loaded by the core templates. So if you use jQuery, you are ready to go.
dom = (document.getElementById)? true : false;
ie4 = (document.all)? true : false;
ns6= (dom && !ie4)? true : false;
ns4 = (document.layers)? true:false;


preloadImage('signinsmOff','http://www.bestwestern.se/images/btn-signin.gif');
preloadImage('signinsmOn','http://www.bestwestern.se/images/btn-signinOn.gif');


/*
This file contains javascript functions that are used globally in various 
web pages throughout the web site.  NOTE: functions are ALPHABETICAL so
if you add a function to the file please place it accordingly and list it
below...

FUNCTIONS IN THIS FILE:
	CreateSubmitDataString
	DigitValidation
	EmailAddressValidation
	EmptyValidation
	LengthValidation
	SubmitEnter
	SubmitFormOnlyOnce
	Trim
	OpenWindow
*/

// GLOBAL VARIABLES				// USED BY FUNCTION
var submitCount = 0;			// SubmitFormOnlyOnce

/************************************************************************
* CreateSubmitDataString
* 	for the passed form returns a string of all form inputs in the 
*   format [field name]: [field value][new line]
************************************************************************/
function CreateSubmitDataString(theForm)
{
	var strValues = "";
	with (theForm)
	{
		// clear any current value
		submit_data.value = "";
		
		for (var i = 0; i < length; i++)
		{
			strValues = strValues + elements[i].name + ": ";
			if (elements[i].type == "select-one")
				strValues = strValues + elements[i].options[elements[i].selectedIndex].value + "\r\n";
			else
				strValues = strValues + elements[i].value + "\r\n";
		}
	}
	return strValues;
}

/************************************************************************
* SubmitEnter
*	used in onkeypress event of form inputs to allow enter key to 
*   kick off form submission process.  works with ie and netscape.
************************************************************************/
function SubmitEnter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return false;
	
	if (keycode == 13)
	   return true;
	else
	   return false;
}

/************************************************************************
* DigitValidation
* 	verifies numeric value was entered and that it's length is between
* 	the passed min and max
************************************************************************/
function DigitValidation(entered, lenMin, lenMax, alertText)
{
	var strValue = Trim(entered.value);	
	var checkvalue=parseFloat(strValue);
	if ( (parseFloat(lenMin)==lenMin && strValue.length<lenMin) || (parseFloat(lenMax)==lenMax && strValue.length>lenMax) || strValue!=checkvalue || (strValue.indexOf(".")>0) )
	{
		if (alertText) 
			alert(alertText);
		entered.focus();
		entered.select();
		return false;
	}
	else 
		return true;
}

/************************************************************************
* EmailAddressValidation
* 	shows a message (alertText) and returns false if no e-mail address has been specified in the 
*   input text box (entered) or if the address appears invalid due to a number of conditions checked
************************************************************************/
function EmailAddressValidation(entered, alertText) {
	with (entered)
	{
		var len=value.length
		var apos=value.indexOf("@");
		var dotpos=value.lastIndexOf(".");
		var lastpos=value.length-1;
		// if length = 0
		// or "@" is the first character or doesn't exist
		// or "." doesn't follow "@" with at least 2 spaces between them
		// or there are more than 3 characters following the "."
		// or there are less than 2 characters following the "."
		if (len==0 || apos<1 || dotpos-apos<2 || lastpos-dotpos>4 || lastpos-dotpos<2) 
		{
			if (alertText) 
				alert(alertText);
			entered.focus();
			return false;
		}
		else 
			return true;
	}
}

/************************************************************************
* EmptyValidation
*	shows a message (alertText) and returns false if no data has been 
*	entered in the input text box (entered)
************************************************************************/
function EmptyValidation(entered, alertText)
{
	var strValue = Trim(entered.value);
	if (strValue == null || strValue == "" || strValue == "undefined")
	{
		if (alertText)
		{
			alert(alertText);
		} 
		entered.focus();
		entered.select();
		return false;
	}
	else 
		return true;
}

/************************************************************************
* LengthValidation
*	shows a message (alertText) and returns false if the length of
*	the input text (entered) is too short or too long
************************************************************************/
function LengthValidation(entered, lenMin, lenMax, alertText)
{
	var strValue = Trim(entered.value);
	if (strValue.length < lenMin || strValue.length > lenMax)
	{
		if (alertText) 
		{
			alert(alertText);
		} 
		entered.focus();
		entered.select();
		return false;
	}
	else 
		return true;
}

/************************************************************************
* SubmitFormOnlyOnce
*	once the form's submit button is clicked, prevents the form from 
*   being submitted more than once.  
*   NOTE: Make sure to call this function AFTER all validation functions
************************************************************************/
function SubmitFormOnlyOnce()
{
   if (submitCount == 0)
   {
      submitCount++;
      return true;
   }
   else 
   {
      alert("This form has already been submitted.  Thanks!");
      return false;
   }
}

/************************************************************************
* Trim
*	Trims leading and trailing spaces and tabs. 
************************************************************************/
function Trim(sData) 
{
	var sTrimmed = String(sData);
	sTrimmed = sTrimmed.replace(/(^[ |\t]+)|([ |\t]+$)/g, '');
	return sTrimmed;
}

/************************************************************************
* OpenWindow
*	Opens a new window with the url, winName and specified features.
*   Returns a reference to the opened window. 
************************************************************************/
function OpenWindow(URL,features){
	// ----------------------------
	// Define local variables
	var features;
	var popupWin;
	// ----------------------------
	var winName = new Date();
    winName = winName.getSeconds()+"_"+winName.getMinutes()+"_"+winName.getHours();

	popupWin = window.open(URL,winName,features);
	if (!popupWin.opener) popupWin.opener = self;
    popupWin.focus();
    
    return popupWin;
}

function toggleDisplay(obj1Name, obj2Name) {
	/*
		function to show and hide the signin and signout ids 
		made for the GCCI login bar
	*/
	
	// get the object
	objSignin = getObject(obj1Name);
	objSignout = getObject(obj2Name);
	
	if (objSignout.style.display == 'none') {
		// show the singout
		objSignout.style.display = 'block';
		objSignin.style.display = 'none';
	} else {
		// show the singin
		objSignout.style.display = 'none';
		objSignin.style.display = 'block';
	}
}

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 preloadImage(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 (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 formvalidation_login(thisform)
{
with (thisform)
{
if (EmptyValidation(userName,"Please enter a value for the \"Membership Number\" field.")==false) {return false;};
if (DigitValidation(userName,16,16,"Invalid \"Membership Number\" - must be 16 digits.")==false) {return false;};
if (LengthValidation(password,5,8,"\"Password\" must be between 5 and 8 characters in length.")==false) {return false;};
submit_data.value = CreateSubmitDataString(thisform);

// allow form to be submitted only once
if (SubmitFormOnlyOnce()==false) {return false;};

submit();
}
}
/*
function formvalidation_login(thisform)
{
	with (thisform)
	{
	    if (EmptyValidation(userName,"Please enter a value for the \" Email or Member#\" field.")==false) {return false;}
        if (EmptyValidation(password,"Please enter a password.")==false) {return false;}
        if(userName.value >= 0)
	    {
                if (DigitValidation(userName,16,16,"Invalid \" Member#\" - must be 16 digits.")==false) {return false;}
	    }
	    else
	    {
                if(EmailAddressValidation(userName, "Invalid Email ID")==false) {return false;}
	    }
        if (LengthValidation(password,5,8,"Password is not 5-8 characters in length, please change and re-submit.")==false) {return false;}

		url.value = window.location.href;
 
	    submit();
	    return true;
	}
}
*/
//-->
