 //@param the checkbox control/s that need to be checked.
 //@param the string message for alert.
 var flipImage = true;
function isAnyCheckboxChecked(chkBox, alertMessage) {
if(chkBox.length == undefined) {
return chkBox.checked
} 
else {
	for(var ii = 0; ii < chkBox.length; ii++) {
			if(chkBox[ii].checked == true) {
				return true;
			}
		}
	}
}

function getSelectedRadio(buttonGroup) {
  // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function


//This function will remove leading anf trailing sapces
function trim(stringToTrim) {
		//return stringToTrim.replace(/^\s+|\s+$/g,"");
		return stringToTrim.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

//returns true if the string is numeric
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
  
   return blnResult;
   } 
   
  
function IsNumericFloat(numericValue) {
	var numbers = "0123456789.";

	if (numericValue == '0' || numericValue == "" || numericValue == '.') {
		return false;
	}

	var decimalCount = 0;

	for (ii = 0; ii < numericValue.length; ii++) {
		if (numericValue.charAt(ii) == ".") {
			decimalCount = decimalCount + 1;
			if (decimalCount > 1) {
				return false;
			}
		}
	}

	if(decimalCount > 0) {
		if(("" + numericValue).substring(("" + numericValue).indexOf('.') + 1).length > 2) {
			return false;
		}
	}

	for (ii = 0; ii < numericValue.length; ii++) {
		if (numbers.indexOf(numericValue.charAt(ii)) == -1) {
			return false;
		}
	}
   
	if(parseFloat(numericValue) <= 0) {
		return false;
 	}
	return true;
}
   
   
/**
 * DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

	var maxL;
	var bName = navigator.appName;
	var textAreaLength;
	
	function taLimit(taObj,event,maxL) {		
		var objVal=taObj.value;		
		var enterCount = 0;
		if(bName == "Netscape") {		
			enterCount = CounterForEnter(objVal);		
			maxL = maxL - enterCount;
			
		}		
		if (objVal.length  >= maxL){			
			if(event.keyCode==8 || event.keyCode==46 || event.keyCode==9){
				return true;
			} else {				
				return false;
			}
		}
	}

function taCount(taObj,Cnt,maxL,event) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	
	
	var enterCount = 0;
	if(bName == "Netscape") {		
		enterCount = CounterForEnter(objVal);		
		maxL = maxL - enterCount;
	}
	
	if (objVal.length >= maxL){
		objVal=objVal.substring(0,maxL);
		taObj.value = objVal;
		if(event.keyCode==8 || event.keyCode==46 || event.keyCode==9){
			return true;
		}
	}
	
	if (objCnt) {
		if(bName == "Netscape"){
			objCnt.textContent = maxL - objVal.length;
		}
		else{
			objCnt.innerText = maxL - objVal.length;
		}
		
	}
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}
var fromHeader = true;
//script to show sign-in modal popup
function mainSignInhidWin(){
	document.getElementById('transparentPage').style.display='';
	document.getElementById('transparentPage').style.height=document.body.clientHeight+'px';
	document.getElementById('transparentPage').style.width=document.body.clientWidth+'px';
	document.getElementById('popupwin_signIn').style.display='';
	var ww = document.body.clientWidth;
	var dw = 430;
	document.getElementById('popupwin_signIn').style.left = (ww/2-dw/2)+'px';
		//document.getElementsByTagName("html")[0].style.overflow = "hidden";
	}
//Script to show up options for a user in modal pop-up for a user
function signInhidWin(){
	mainSignInhidWin();
	document.getElementById('user-options').style.display='';
	document.getElementById('returningUser').style.display='none';
	document.getElementById('newUserBlock').style.display='none';
	}
//Script to close the sign-in modal pop-up.
function signInshowWin(){
	document.getElementById('passwordDontMatchError').style.display='none';
	document.getElementById('PasswordLengthExceederror').style.display='none';
	document.getElementById('userName').className="blk";
	document.getElementById('SignInuserId').className="blk";
	document.getElementById('SignInPassword').className="blk";
	document.getElementById('emailAlreadyExistError').style.display='none';
	document.getElementById('PasswordLengtherror').style.display='none';
	document.getElementById('forgotPassword').style.display='none';
	document.getElementById('userNameerror').style.display='none';
	document.getElementById('returningUsererror').style.display='none';
	document.getElementById('forgotPassworderror').style.display='none';
	document.getElementById('signInerror').style.display='none';
	document.getElementById("clearTextPassword").value='';
	document.getElementById("email").value='';
	document.getElementById("confirmClearTextPassword").value='';
	document.getElementById('signInerror').style.display='none';
	document.getElementById('password').className="blk";
	document.getElementById('transparentPage').style.display='none';
	document.getElementById('forgotEmailAddress').value="";
	document.getElementById('forgotEmailAbsentError').style.display='none';
	document.getElementById('email').value = "";
	document.getElementById('clearTextPassword').value = "";
	document.getElementById('confirmClearTextPassword').value = "";
		var appendAction3 = window.location.href;
		var index = appendAction3.indexOf('&forgot');
			if(index == -1){
				index = appendAction3.indexOf('?forgot');
			}
			if(index != -1){
				window.location.href = appendAction3.substring(0,index);
			}
	//document.getElementById('transparent').style.height=screen.height+'px';
	//document.getElementById('transparent').style.width=screen.width+'px';
	//document.getElementsByTagName("html")[0].style.overflow = "";
	//document.getElementById('popupwin_signIn').style.display='none';
	}
//Script to be called on the selection of radio-buttons in sign-in modal pop-up.
function optionshidwin(buttonGroup){
	document.getElementById('SignInuserId').className ="";
	document.getElementById('SignInPassword').className ="";
		var slectedAction = getSelectedRadioValue(buttonGroup);
			if(slectedAction == "I am a new User"){
			        
					document.getElementById('user-options').style.display='none';
					document.getElementById('newUserBlock').style.display='';
			}
			if(slectedAction == "I am a Returning User"){
					document.getElementById('user-options').style.display='none';
					document.getElementById('returningUser').style.display='';
					}
}
//Script to validate the credentials of a new user.	
function registerNewUser(baseUrl){
 	var error = false;
	if(document.getElementById('emailAlreadyExistError')!=null){
	document.getElementById('emailAlreadyExistError').style.display='none';
	}
	var email = document.getElementById("user_email").value;
	var password = document.getElementById("clearTextPassword").value;
	var confirmPassword = document.getElementById("confirmClearTextPassword").value;
	if(email == "" && password == "" && confirmPassword == ""){
	document.getElementById('signInerror').style.display='';
	return false;
	}
	if(!emailCheck(email)){
	document.getElementById('userName').className="text_content_error";
	document.getElementById('userNameerror').style.display='';
	document.getElementById('signInerror').style.display='';
	error = true;
	}else{
	document.getElementById('userName').className="blk";
	document.getElementById('userNameerror').style.display='none';
	}
	if(password.length < 7 ){
	document.getElementById('signInerror').style.display='';
	document.getElementById('password').className="text_content_error";
	document.getElementById('PasswordLengtherror').style.display='';
	error = true;
	}else if(password.length > 14){
	document.getElementById('signInerror').style.display='';
	document.getElementById('password').className="text_content_error";
	document.getElementById('PasswordLengthExceederror').style.display='';
	error = true;
	}
	else{
	document.getElementById('password').className="blk";
	document.getElementById('PasswordLengtherror').style.display='none';
	}
	if(password != confirmPassword){
	document.getElementById('passwordDontMatchError').style.display='';
	document.getElementById('signInerror').style.display='';
	error = true;
	}else{
	document.getElementById('passwordDontMatchError').style.display='none';
	}
	if(error){
	return false;
	}
		var appendAction2 = window.location.href
		document.createNewUser.currentPageViewForRegister.value = appendAction2;
		//document.createNewUser.submit();
	//	document.createNewUser.submit();
}				
//Script to handle the returning user case in sign-in modal pop-up.
function returningUserHandle(baseUrl){
 		var appendAction = window.location.href;
 		document.returningUserUniversal.currentPageView.value = appendAction;
		//document.returningUserUniversal.submit();
		//document.returningUserUniversal.submit();
}
//Script for forgot password Pop-up
function forgotPasswordPopUp(){
		fromHeader = true;
		document.getElementById('returningUser').style.display='none';
		document.getElementById('forgotPassword').style.display='';
}
//Script to submit the form forget password.
function forgotPasswordFormSubmit(baseUrl){
		document.getElementById('forgotPassworderror').style.display='none';
		if(document.getElementById('forgotEmailAddress').value == ""){
		document.getElementById('forgotEmailAbsentError').style.display='';
		return false;
		}
		var appendAction1 = window.location.href
		document.forgotPasswordForm.currentPageView.value = appendAction1;
		//document.forgotPasswordForm.submit();
		//document.forgotPasswordForm.submit();
}


function forgotPasswordShowWin(){
	document.getElementById('forgotEmailAbsentError').style.display='none';
	document.getElementById('forgotEmailAddress').value="";
	document.getElementById('returningUsererror').style.display='none';
	document.getElementById('forgotPassworderror').style.display='none';
	if(fromHeader){
	mainSignInhidWin();
	document.getElementById('user-options').style.display='none';
	document.getElementById('returningUser').style.display='';
	document.getElementById('newUserBlock').style.display='none';
	document.getElementById('forgotPassword').style.display='none';
	}else{
	signInshowWin();
	}
	}

	// function to check the validity of email.
	function emailCheck(str) {
		var Re = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
		if(!str.match(Re)){
			  return false;
		}
		return true	;				
	}
	//Script to open modal-pop-ups on any page.pass the parametes accordingly.
	/**
	bodyObj : div to hide the main page.eg "tranparent"
	popupObj : div id of modal pop-up to be opened.
	htmlTag : html tag.
	*/
	function popUpWin(bodyObj,popupObj,htmlTag,popupWidth){
	    document.getElementById(bodyObj).style.display='';
	    document.getElementById(bodyObj).style.height=document.body.clientHeight+'px';
	    document.getElementById(bodyObj).style.width=document.body.clientWidth+'px';
	    document.getElementById(popupObj).style.display='';
	    var ww = document.body.clientWidth;
		var dw = popupWidth;
		document.getElementById(popupObj).style.left = (ww/2-dw/2)+'px';
		
	    //document.getElementsByTagName(htmlTag)[0].style.overflow = "hidden";
	}
	//Script to close modal-pop-ups on any page.
	/**
	bodyObj : div to hide the main page.eg "tranparent"
	popupObj : div id of modal pop-up to be opened.
	htmlTag : html tag.
	*/
	function closeWin(bodyObj,popupObj,htmlTag){
	    document.getElementById(bodyObj).style.display='none';
	    //document.getElementsByTagName(htmlTag)[0].style.overflow = "";
	    document.getElementById(popupObj).style.display='none';
	}
	
	
	/*function changeImg(ImgShow,imgHide,thumbImgOff,thumbImgOn)*/
	function changeImg(ImgShow, baseUrl) {
		flipImage = true;
		var delayTime = 700; 		
	    if (ImgShow=="img_home-1"){
	       setTimeout("showFirstImage(baseUrl)", delayTime);
	    }
	    
	    if (ImgShow=="img_home-2"){
			setTimeout("showSecondImage(baseUrl)", delayTime);
	    }
	    
	    if (ImgShow=="img_home-3"){
	    	setTimeout("showThirdImage(baseUrl)", delayTime);
	    }
	}
	
function setUrl(obj) 
{
    location.href = obj;
    return false;
}
function zipCodeTest(zipCode) {
	if(isValidNineDigitZipCode(zipCode)){
		return true;
	}
	var Re = new RegExp("^[0-9]{5}|[a-zA-Z][0-9]{1}[a-zA-Z](\-| |)[0-9]{1}[a-zA-Z][0-9]{1}$");
	if(zipCode.match(Re) != zipCode + ","){
		  return false;
	}
	return true	;				
}

function canadainZipCodeTest(zipCode) {
	var Re = new RegExp("^[a-zA-Z][0-9]{1}[a-zA-Z](\-| |)[0-9]{1}[a-zA-Z][0-9]{1}$");
	if(zipCode.match(Re) != zipCode + ","){
		  return false;
	}
	return true	;				
}

function resetImageSwitch(){
	flipImage = false;
}

function clearText(objectId, text){
	var emailValue = document.getElementById(objectId).value;
	if(emailValue == text){
		document.getElementById(objectId).value = '';
		document.getElementById(objectId).style.color = '#000';
	}
}

function setText(objectId, text) {
	var emailValue = document.getElementById(objectId).value;
	if(emailValue.length == 0){
		document.getElementById(objectId).style.color = '#BCBCBC';
		document.getElementById(objectId).value = text;
	}
}

function joinEclub(){
	var email = document.getElementById('customerEmail').value;
	if(email.length == 0 || email == "email address"){
		window.location.href ="http://visitor.constantcontact.com/manage/optin/ea?v=001XWTM8Vlkw3bUsBUrjrh4Dw%3D%3D";
	}else {
		window.location.href = "http://visitor.constantcontact.com/manage/optin?v=001XWTM8Vlkw3ZslsTeVoH4LxMal6GafghH_coOxRTgWA3eTUAfPz5HYw%3D%3D";
	}
}

function submitOnEnter(elementId, e)
{
	var keycode;
	if (window.event) {
		keycode = window.event.keyCode;
	} else if (e) {
		keycode = e.which;
	} else  {
		return true;
	}
	      
	if (keycode == 13) {
      if(document.getElementById(elementId)!=null){
		document.getElementById(elementId).click();
	}
		return false;
		
	} else {
		return true;
	}
}

function submitOnEnterForAnchor(elementId, e)
{
	var keycode;
	if (window.event) {
		keycode = window.event.keyCode;
	} else if (e) {
		keycode = e.which;
	} else  {
		return true;
	}
	      
	if (keycode == 13) {
		
	if(document.getElementById(elementId)!=null){
		location.href=document.getElementById(elementId);
	
	}
		return false;
		
	} else {
		return true;
	}
}
function loginFailed(){
	 $jq('#popupwin_signInDiv').modal();
 	  document.getElementById('user-options').style.display='none';
  	  document.getElementById('returningUser').style.display='';
  	  document.getElementById('returningUsererror').style.display='';
	 
}
function forgotPasswordCart(){
	 $jq('#popupwin_signInDiv').modal();
     document.getElementById('user-options').style.display='none';
     document.getElementById('forgotPassword').style.display='';
     document.getElementById('forgotPassworderror').style.display='';
    
}

function newUserFailed(){
	$jq('#popupwin_signInDiv').modal();
    document.getElementById('user-options').style.display='none';
    document.getElementById('newUserBlock').style.display='';
    document.getElementById('emailAlreadyExistError').style.display='';
}
 
function CounterForEnter(strText){
	var platformEnterCount = 1;
	var enterRepresentation = "\n";
	if (navigator.appVersion.indexOf("Win")!=-1) { platformEnterCount = 1; }
	if (navigator.appVersion.indexOf("Mac")!=-1) { platformEnterCount = 0; enterRepresentation = "\n"; }
	if (navigator.appVersion.indexOf("Linux")!=-1) { platformEnterCount = 0;  enterRepresentation = "\n"; }
	
	


	 var strReplaceAll = strText;
	 var intIndexOfMatch = strReplaceAll.indexOf( enterRepresentation );
	 var enterCount = 0;
	 // Loop over the string value replacing out each matching
	 // substring.
	 while (intIndexOfMatch != -1){
	 // Relace out the current instance.
	 strReplaceAll = strReplaceAll.replace( enterRepresentation, " " )
	 enterCount = enterCount + platformEnterCount;
	 // Get the index of any next matching substring.
	 intIndexOfMatch = strReplaceAll.indexOf( enterRepresentation );
	 }
	 return enterCount ;
}
 
	function  submitEClub(textFieldId){
	var el =document.getElementById(textFieldId);
	if  (el.value == "email address"){
           el.value="";
	}

}
	
  
	
	function printDir(divId){
    	IF2.document.getElementById('printarea').innerHTML=document.getElementById(divId).innerHTML;
    	window.frames["IF2"].focus();
    	window.frames["IF2"].print();
}


function showHide(link)
{
	return false;
 	try {
	    var linkId = link.id;
	    var count;
	    var startIndex = linkId.indexOf('_');
	    count = linkId.substring(startIndex + 1);
	    var columnType = linkId.substring(4,startIndex);
	    var olId = 'ol' + columnType + '_' + count;
	    var ol = document.getElementById(olId);
	    if (ol.style.display == "none" && link.className == "bullet") {
	        ol.style.display = "";
	        link.className = "bulletActive";
	    }
	    else {
	        ol.style.display = "none";
	        link.className = "bullet";
	    }
    }catch(e) {
    	return false;
    }
    return false;
}


/*function showHide(ul,link)
{
    if (document.getElementById(ul).style.display == "none" && document.getElementById(link).className == "bullet") {
        document.getElementById(ul).style.display = "";
        document.getElementById(link).className = "bulletActive";
    }
    else {
        document.getElementById(ul).style.display = "none";
        document.getElementById(link).className = "bullet";
    }
    
}*/

function validatePhoneNumber(phNumber){
	var numericExpression = new RegExp("^[0-9]+$");
	if(phNumber.length >= 10 && phNumber.length <= 20 && phNumber.match(numericExpression)){
		return true;
	}else{
		return false;
	}
}

/**
* Checks whether the dateToBeChecked is within noOfDaysFromToday or not. For example if the function
* is called with the following Date Objects. currentDate_final (01/01/2009), dateToBeChecked(31/01/2009),
* noOfDaysFromToday(60). Then in that case the function would return true. However if we change  
* noOfDaysFromToday to noOfDaysFromToday(20) then it would return false. In this case dates before
* (20/01/2009) would return true including (20/01/2009).
* 
* @param currentDate_final The current date object should be a javascript Date object.
* @param dateToBeChecked The date that needs to be checked. This also should be a javascript Date object.
* @param noOfDaysFromToday No. of days from current days for which the function should return true. 
* 
* @author anupams
*/ 
function isWithinDays(currentDate_final, dateToBeChecked, noOfDaysFromToday) {
	var oneDay = 86400000; // 1000 * 60 * 60 * 24
	var currentDate = new Date();
	currentDate.setTime(currentDate_final.getTime()); //Done to ensure we are not modifiying the original date object
	currentDate.setHours(0, 0, 0, 0); // set the date to current date 0:0:00 hours
	var maxTime = currentDate.getTime() + (oneDay * noOfDaysFromToday);
	if(dateToBeChecked.getTime() > maxTime) {
		return false;
	} else {
		return true;
	}
	
}

function getOnlyZipOrPostalCodeString(zipCode){
	var onlyZipCode = zipCode;
	var index = onlyZipCode.indexOf('-');
	if(index == -1) {
		return onlyZipCode;
	}
	return onlyZipCode.substring(0, index); 
	}

function isValidNineDigitZipCode(zipCode){
		var onlyZipCode = zipCode;
		var index = onlyZipCode.indexOf('-');
		if(index == -1) {
			return false;
		}
		if(trim(zipCode).length != 10){
			return false;
		}
		if(onlyZipCode.substring(0, index).length == 5){
			return true; 
		}
}


function getOnlyZipOrPostalCodeString(zipCode){
	var onlyZipCode = zipCode;
	var index = onlyZipCode.indexOf('-');
	if(index == -1) {
		return onlyZipCode;
	}
	return onlyZipCode.substring(0, index); 
	}

function isValidNineDigitZipCode(zipCode){
		var onlyZipCode = zipCode;
		var index = onlyZipCode.indexOf('-');
		if(index == -1) {
			return false;
		}
		if(trim(zipCode).length != 10){
			return false;
		}
		if(onlyZipCode.substring(0, index).length == 5){
			return true; 
		}
}


function TabSubMenu(baseUrl) {
	var node1;
	node1 = document.getElementById('subCategories');

	if(node1.offsetHeight=="82")
	{
		document.getElementById('subCategories').style.background="url(" + baseUrl + "/template-resources/images/bachmans/sub-nav_bg_right2.gif) no-repeat right top";
		document.getElementById('subCategories').style.height="82px";

	}

	if(node1.offsetHeight=="109")
	{
		document.getElementById('subCategories').style.background="url(" + baseUrl + "/template-resources/images/bachmans/sub-nav_bg_right3.gif) no-repeat right top";
		document.getElementById('subCategories').style.height="109px";
	}

	if(node1.offsetHeight=="28")
	{
		document.getElementById('subCategories').style.background="none";
		document.getElementById('subCategories').style.height="28px";
	}
}
