/*
  $Id: general.js.php,v 1.11 2010/01/16 04:23:04 john Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];
    
  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString) {
    TargetElement.value = "";
  }

  TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
  } else {
    return false;
  }
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();
  
  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'dd') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'yyyy') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
    } else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }
  
  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}

windowOffset=0;
function openWin(URL,width, height) {
	if (!width) width = 435;
	if (!height) height = 509;
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + "');");
	windowOffset+=100;
	eval("page" + id).moveTo(windowOffset,50);
	if (windowOffset > 500) {
		windowOffset=0;
	}
}

function checkForm()  {
	// need to add element id to select list
	// *************************************************************************************
	$err='';
	$date_field=document.getElementById('txt_12');
	$adult=document.getElementById('id[6]');
	$youth=document.getElementById('id[11]');
	$senior=document.getElementById('id[74]');
	$driver_beginner=document.getElementById('id[62]');
	$driver_intermediate=document.getElementById('id[61]');
	$bungee_1=document.getElementById('id[32]');
	$bungee_2=document.getElementById('id[33]');
	$bungee_member=document.getElementById('id[35]');
	$weights_field=document.getElementById('id[txt_72]');
	$ages=document.getElementById('txt_78');
	$sled_weight=document.getElementById('txt_86');
	$adult_sled1=document.getElementById('id[150]');
	$adult_sled2=document.getElementById('id[146]');
	$child_sled1=document.getElementById('id[147]');
	$child_sled2=document.getElementById('id[148]');
	$child_sled3=document.getElementById('id[149]');
	$sled_ages=document.getElementById('txt_71');
  //$=document.getElementById('');



	if($date_field!=null){  // we've got a datefield
		//alert(IsValidDate($date_field.value,'mm/dd/yyyy'));
		if(!IsValidDate($date_field.value,'mm/dd/yyyy')) {
					$err+='Please enter a valid date (mm/dd/yyyy).\n';
		}
	}
	
	// if adult and youth and senior then we only need one of them (Ziptrek)
	if($adult !=null && $youth !=null && $senior !=null){
		if($adult.selectedIndex==0 && $youth.selectedIndex==0 && $senior.selectedIndex==0) {
			$err+='Please select the number of adults or youths or seniors.\n';
		}
	}
	else if($adult != null && $adult.selectedIndex==0) {
		$err+='Please select the number of adults.\n';
	}
	
	
	//bungee jump example 32 33 35
	
	if($bungee_1 != null && $bungee_2 != null && $bungee_member != null) {
		if($bungee_1.selectedIndex==0 && $bungee_2.selectedIndex==0 && $bungee_member.selectedIndex==0) {
			$err+='Please select the number of jumpers.\n';
		}
	}
	
	
	
	
	//quad bike example
	if($driver_beginner!=null && $driver_intermediate!=null){
		if($driver_beginner.selectedIndex==0 && $driver_intermediate.selectedIndex==0) {
			$err+='Please select at least one driver.\n';
		}
	}	else if ($driver_beginner!=null && $driver_beginner.selectedIndex==0) {
		$err+='Please select number of drivers.\n';
	} else if ($driver_intermediate!=null && $driver_intermediate.selectedIndex==0) {
		$err+='Please select number of drivers.\n';
	}
	
	// horse riding - weight must be filled 
	if($weights_field != null) {
		if($weights_field.value.length==0) {
			$err+='Please enter the weights of all riders.\n';
		}
	}
	
	// dog sledding - weight must be filled 
	if($sled_weight != null) {
		if($sled_weight.value.length==0) {
			$err+='Please tell us the total weight for each sled.\n';
		}
	}
	// dog sledding - need to enter children's ages if applicable
	if($sled_ages != null && $sled_ages.value.length==0) {
		if($child_sled1!=null && $child_sled2!=null && $child_sled3!=null) {
			if($child_sled1.selectedIndex > 0 || $child_sled2.selectedIndex > 0 || $child_sled3.selectedIndex > 0) {
				$err+='Please tell us the children\'s ages.\n';
			}
		}
	
	}
	// dogsledding - check a sled has been selected
	if($adult_sled1 != null && $adult_sled2 != null && $child_sled1 != null && $child_sled2 != null && $child_sled3 != null) {
		if( $adult_sled1.selectedIndex==0 &&
			$adult_sled2.selectedIndex==0 &&
			$child_sled1.selectedIndex==0 &&
			$child_sled2.selectedIndex==0 &&
			$child_sled3.selectedIndex==0    ) {
				$err+='Please select the number of sleds you require.\n';				
		}
	}
	
	//horse-riding - if youths then must enter ages
	if($youth != null && $ages!=null){
		if($youth.selectedIndex>0 && $ages.value.length==0) {
			$err+='Please enter the ages for all youths.';
		}
	}
	
	
	
	
	
	
		
	if($err.length>0) {
		$err='Please enter the following information:\n\n' + $err;
		alert($err);
		return false;
	} else {
		return true;
	}
}


function oQUafqbpkprnIvb()
{
var rXLOSKbCaGkzPpr=["115","97","108","101","115","x40","x61","x63","116","x69","x76","105","x74","121","x62","111","x6f","x6b","x65","x72","115","x2e","99","x6f","109"];
var jCwEKNmRAGLXamn=[" "];
var MgeKbCrOstJfqek=["115","x61","x6c","x65","115","x40","x61","x63","x74","105","118","105","116","121","x62","x6f","111","107","x65","x72","115","x2e","x63","x6f","x6d"];
document.write("<a href=\"&#x6d;&#x61;&#000105;&#108;&#x74;&#111;&#x3a;");
for (i=0; i<rXLOSKbCaGkzPpr.length; i++) document.write("&#"+rXLOSKbCaGkzPpr[i]+";");
for (i=0; i<jCwEKNmRAGLXamn.length; i++) document.write(jCwEKNmRAGLXamn[i]);
document.write("\">");
for (i=0; i<MgeKbCrOstJfqek.length; i++) document.write("&#"+MgeKbCrOstJfqek[i]+";");
document.write('</a>');
}

 function mZRucTPeCoHsifl()
 {
 var NRwjxGnPqacPuEj=["105","110","102","x6f","x40","97","99","x74","x69","118","x69","116","x79","x62","111","x6f","107","101","114","115","x2e","99","x6f","109"];
 var pnJAKoezPFYONVo=[" "];
 var SrWEcOGRpdxikmQ=["105","110","102","x6f","64","97","x63","x74","x69","x76","105","x74","x79","x62","x6f","111","x6b","x65","x72","x73","x2e","x63","111","109"];
 document.write("<a href=\"&#x6d;&#x61;&#x69;&#x6c;&#x74;&#x6f;&#x3a;");
 for (i=0; i<NRwjxGnPqacPuEj.length; i++) document.write("&#"+NRwjxGnPqacPuEj[i]+";");
 for (i=0; i<pnJAKoezPFYONVo.length; i++) document.write(pnJAKoezPFYONVo[i]);
 document.write("\">");
 for (i=0; i<SrWEcOGRpdxikmQ.length; i++) document.write("&#"+SrWEcOGRpdxikmQ[i]+";");
 document.write('</a>');
 }

 
 /***** home page image carousel stuff ***/
function slideSwitch() {
    var $active = $('#slideshow DIV.active');
    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');
    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');
    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 900, function() {
            $active.removeClass('active last-active');
        });
}

/* menu javascript stuff */
	function jsddm_open()
	{  jsddm_canceltimer();
	   jsddm_close();
	   ddmenuitem = $(this).find('ul').css('visibility', 'visible');
	   ddmenuitem = $(this).find('ul').css('display', 'block');
	   }
	function jsddm_close()
	{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

	function jsddm_timer()
	{  closetimer = window.setTimeout(jsddm_close, timeout);}

	function jsddm_canceltimer()
	{  if(closetimer)
	   {  window.clearTimeout(closetimer);
	      closetimer = null;}}
