var selected;

$(document).ready(function() {
            
	$('input').focus(function () {
		if($(this).attr('class') != 'checkout_form' && $(this).attr('class') != 'login_form') {
			if($(this).attr('title') != '') {
				if($(this).val() == $(this).attr('title')) {
					$(this).val('');
					$(this).css('color', 'black');
				}
			}
		}
	}).blur(function() {
		if($(this).attr('class') != 'checkout_form' && $(this).attr('class') != 'login_form') {
			if($(this).val() == '') {
					$(this).val($(this).attr('title'));
					$(this).css('color', '#b8b8b8');
			}
		}
	});
	
	right_number = 0;
	hash = window.location.hash;
  	page_hash = hash.substring(1);
  	
	for (i=1;i<=5;i++) {
		if ($('a#extra_options_'+i).length > 0) {
			right_number = i;
		  	break;
		}
	}
	
	if (right_number != 0) {
		i = right_number;
		options_table = $('table.extra_options').offset();
		first_sel = $('a#extra_options_'+i).offset();
		posx = first_sel.left + ($('a#extra_options_'+i).width() / 2) - 5;
		posy = first_sel.top + 30;
		//$('img#extra_selector').css('top', posy+'px');
  		$('img#extra_selector').css('left', (posx-options_table.left)+'px');
		$('img#extra_selector').css('display', 'inline');
	}
	
	if (typeof(antonius_content) !== 'undefined') {
		var antonius_box = '<div class="antonius_box" style="display:none;background:black;width:100%;left:0px;top:0px;filter:alpha(opacity=0);opacity:0;z-index:50000;position:absolute;"></div>';
		$("body").append(antonius_box).append(antonius_content);
	}
	
	$('a[type="switch_img_left"]').click(function (e) {
		if (!big_img_is_scrolling) {
			big_img_is_scrolling = true;
			$("#img_holder").animate({"left": "+=290"}, "slow");
			setTimeout('big_img_is_scrolling = false;', 600)
			curr_image--;
			$('a[type="switch_img_right"]').show();
			if (curr_image == 1) {
				$('a[type="switch_img_left"]').hide();
			}
		}
	});
	$('a[type="switch_img_right"]').click(function (e) {
		if (!big_img_is_scrolling) {
			big_img_is_scrolling = true;
			$("#img_holder").animate({"left": "-=290"}, "slow");
			setTimeout('big_img_is_scrolling = false;', 600)
			curr_image++;
			$('a[type="switch_img_left"]').show();
			if (curr_image == images_number) {
				$('a[type="switch_img_right"]').hide();
			}
		}
	});
	
	$('div[type="switch_img_left_box"]').click(function (e) {
		if (!box_image_is_scrolling) {
			box_image_is_scrolling = true;
			$("#img_holder_box").animate({"left": "+=700"}, "slow");
			setTimeout('box_image_is_scrolling = false;', 600);
			curr_image_box--;
			$('div[type="switch_img_right_box"]').show();
			if (curr_image_box == 0) {
				$('div[type="switch_img_left_box"]').hide();
			}
		}
	});
	$('div[type="switch_img_right_box"]').click(function (e) {
		if (!box_image_is_scrolling) {
			box_image_is_scrolling = true;
			$("#img_holder_box").animate({"left": "-=700"}, "slow");
			setTimeout('box_image_is_scrolling = false;', 600);
			curr_image_box++;
			$('div[type="switch_img_left_box"]').show();
			if (curr_image_box == (images_number_box-1)) {
				$('div[type="switch_img_right_box"]').hide();
			}
		}
	});
	
	$("div.box_nav_left").hover( function () {
			$("div.box_nav_left").css('background-position', '0px -36px');
  		}, function () {
    		$("div.box_nav_left").css('background-position', '0px 0px');
  		}
	);
	
	$("div.box_nav_right").hover( function () {
			$("div.box_nav_right").css('background-position', '0px -36px');
  		}, function () {
    		$("div.box_nav_right").css('background-position', '0px 0px');
  		}
	);
	
	$("a.box_nav_close").hover( function () {
			$("a.box_nav_close").css('background-position', '0px -36px');
  		}, function () {
    		$("a.box_nav_close").css('background-position', '0px 0px');
  		}
	);
	on_nav_sel_ul = false;
	on_nav_sel_link = false;
	$('a[type="nav_sel_link"]').hover(function() {
			ul_num = 0;
			while (ul_num < $('ul[type="nav_sel_ul"]').size()) {
				if (ul_num != $(this).attr("navsellink")) {
					$('ul#nav_sel_'+ul_num).hide();
				}
				ul_num++;
			}
			on_nav_sel_link = true;
		}, function() {
			on_nav_sel_link = false;
			nav_num = $(this).attr("navsellink");
			setTimeout('setNavSelLinkFalse(nav_num)', 100);
		}
	);

	$('ul[type="nav_sel_ul"]').hover(function() {
			on_nav_sel_ul = true;
		}, function() {
			if (on_nav_sel_ul) {
				on_nav_sel_ul = false;
				nav_num = $(this).attr('navselid');
				setTimeout('setNavSelLinkFalse(nav_num)', 100);
			}
		}
	);
	
	$('a[name="tabsplace"]', document.body).click(function (e) {
		options_table = $('table.extra_options').offset();
  		var offset = $(this).offset();
  		posx = offset.left + ($(this).width() / 2) - 5;
  		posy = offset.top + 22;
  		$('img#extra_selector').animate({"left": (posx-options_table.left)+"px"}, 400);
	});
	
	$('a[type="category_link"]').hover(function(){
		
		$('#pathImage').css('background', 'url("images/path_img/'+this.id+'.jpg") center center no-repeat');
		//}, function() {$("#pathImage").css('background', 'url("images/path_img/default.jpg") center center no-repeat');
		catnum = $(this).attr('catnum');
		//$('td[type="browse_sep"]').attr('class', 'browse_sep');
		//$('td#sep'+catnum).attr('class', 'browse_sep_sel');
		$('a[type="category_link"]').attr('class', 'browse_link');
		$(this).attr('class', 'browse_link_sel')
		$('table[type="subcat"]').css('display', 'none');
		$('table#subcat'+catnum).css('display', 'inline');

		if ($("#subCatBox").height() < $(window).height()) {
			if ($(window).scrollTop() > globalposition) {
				$("#subCatBox").css("position","fixed");
				$("#subCatBox").css("top","8px");
			}
			if ($(window).scrollTop() <= globalposition) {
				$("#subCatBox").css("position","static");
			}
		} else {
			$("#subCatBox").css("position","static");
		}
		
	});
	
	if ($("#subCatBox").length > 0) {
		globalposition = ($("#subCatBox").offset().top) - 8;
	} else {
		globalposition = 0;
	}

	if ($('div#main_page_slide_div').length > 0) {
		var main_slide = document.getElementById('main_page_slide_div');
		disableSelection(main_slide);
    	timeOutTime = 5000;
    	if ($('img#main_page_im_'+currentImage).attr('timeout') != "") {
      		timeOutTime = parseInt($('img#main_page_im_'+currentImage).attr('timeout'));
      	}
    	slideTimer = setInterval("startMainPageSlide()", timeOutTime);
  	}
  	
  	$("div#slideToggle").hover( function () {
			if (sliderPaused) {
				$('div#slideToggle').css('background-position', '0px -80px');
			} else {
				$('div#slideToggle').css('background-position', '0px -20px');
			}
  		}, function () {
    		if (sliderPaused) {
				$('div#slideToggle').css('background-position', '0px -60px');
			} else {
				$('div#slideToggle').css('background-position', '0px 0px');
			}
  		}
	);
  	
  	var isIE = (navigator.appName == "Microsoft Internet Explorer");
  	slide = true;
  	if (isIE)	{
		document.onfocusout = setSlideFalse;
		document.onfocusin = setSlideTrue;
  	} else {
		window.onblur = setSlideFalse;
		window.onfocus = setSlideTrue;
  	}
});

$(function() {
    $("div.antonius_box").mousedown(function(e) { closeOverlay(); });
    $(document).keyup(function(e) { if (e.keyCode == 27) { closeOverlay(); } });

});

function showOverlay(s, n) {
	if (s == 'page') {
		$('tr#img_holder_tbl').append('<td id="box_page_content" valign="middle"></td>');
		$('td#box_page_content').html('<iframe width="400" height="250" src="'+n+'" style="margin-top:155px;border:none;"><p>Your browser does not support iframes.</p></iframe>');
		$('div[type="switch_img_left_box"]').hide();
		$('div[type="switch_img_right_box"]').hide();
	} else {
		var tblcontent = document.getElementById('box_content_main_tbl');
		disableSelection(tblcontent);
		curr_image_box = n;
		$('td#box_content_titel').html($('a#img_title_'+n).attr('title'));
		for(var i=0; i < box_array[s].length; i++) {
			$('tr#img_holder_tbl').append(box_array[s][i]);
		}
		images_number_box = box_array[s].length;
		if (images_number_box > 1) {
			if (curr_image_box >= 0) { $('div[type="switch_img_right_box"]').show(); }
			if (curr_image_box == 0) { $('div[type="switch_img_left_box"]').hide(); }
			if (curr_image_box > 0 && curr_image_box <= (images_number_box-1)) { $('div[type="switch_img_left_box"]').show(); }
			if (curr_image_box == (images_number_box-1)) { $('div[type="switch_img_right_box"]').hide();  }
		} else {
			$('div[type="switch_img_left_box"]').hide();
			$('div[type="switch_img_right_box"]').hide();
		}
	}
	var top = ($(window).scrollTop()+100);
	var left = Math.round(  ($(document).width()/2)-($('table.antonius_content').width()/2)  )
	$("a.box_nav_close").show().css('top', (top - 18)+'px').css('left', (left + $('table.antonius_content').width() - 84)+'px').fadeTo(500, 1);
	$("div.antonius_box").css('height', $(document).height()+'px');
	$("#img_holder_box").css("left", (n*-700)+"px");
	$("table.antonius_content").css("top", top+"px").css("left", left+"px");
	$("div.antonius_box").show().fadeTo(500, 0.9);
	$("table.antonius_content").show().fadeTo(500, 1);
}
function closeOverlay() {
	$("a.box_nav_close").fadeTo(200, 0);
	$("div.antonius_box").fadeTo(500, 0);
	$("table.antonius_content").fadeTo(500, 0);
	setTimeout('$("a.box_nav_close").hide();', 200);
	setTimeout('$("div.antonius_box").hide();', 500);
	setTimeout('$("table.antonius_content").hide();', 500);
	setTimeout('$("tr#img_holder_tbl").html("");', 500);
}

function setSlideTrue() {
	slide = true;
}
function setSlideFalse() {
	slide = false;
}

$(function() {
	$(window).scroll(function() {
 		if ($("#subCatBox").height() < $(window).height()) {
			if ($(window).scrollTop() > globalposition) {
				$("#subCatBox").css("position","fixed");
				$("#subCatBox").css("top","8px");
			}
			if ($(window).scrollTop() <= globalposition) {
				$("#subCatBox").css("position","static");
			}
		} else {
			$("#subCatBox").css("position","static");
		}
		
	});
});

function showSlide(n) {
	if (!manualClick) {
		clearInterval(slideTimer);
	}
	if (!manualClick) {
		manualClick = true;
		var moveTo = (n - currentImage) * 600;
		var moveTo2 = (n - currentImage) * 25;
		$("#main_page_slide_div").animate({"left": "-="+moveTo}, 800);
		$("div.slider_selection").animate({"top": "+="+moveTo2}, 800);
		currentImage = n;
		setTimeout("manualClick = false", 800);
		if (!sliderPaused) {
			if ($('img#main_page_im_'+currentImage).attr('timeout') != "") {
      			timeOutTime = parseInt($('img#main_page_im_'+currentImage).attr('timeout'));
      		}
			slideTimer = setInterval("startMainPageSlide()", timeOutTime);
		}
	}
}

function startMainPageSlide() {
  	if (slide) {
  		clearInterval(slideTimer);
  		var timeOutTime;
    	if (currentImage < main_page_images) {
      		$("#main_page_slide_div").animate({"left": "-=600"}, 800);
      		currentImage++;
      		$("div.slider_selection").animate({"top": "+="+25}, 800);
    	} else if (currentImage == main_page_images) {
      		setTimeout("resetMainPageSlide()", 500);
      		$("#main_page_slide_div").fadeTo(500, 0);
      		$("#main_page_slide_div").fadeTo(500, 1);
      		$("div.slider_selection").fadeTo(500, 0);
      		$("div.slider_selection").fadeTo(500, 1);
      		currentImage = 1;
    	}
    	if ($('img#main_page_im_'+currentImage).attr('timeout') != "") {
      		timeOutTime = parseInt($('img#main_page_im_'+currentImage).attr('timeout'));
      	}
    	slideTimer = setInterval("startMainPageSlide()", timeOutTime);
  	}
}

function resetMainPageSlide() {
	$("#main_page_slide_div").css('left', '0px');
	$("div.slider_selection").css('top', '5px');
}

function toggleSlidePause(obj) {
	if (sliderPaused) {
		sliderPaused = false;
		$('div#slideToggle').css('background-position', '0px 0px');
		slideTimer = setInterval("startMainPageSlide()", 4000);
	} else {
		sliderPaused = true;
		$('div#slideToggle').css('background-position', '0px -60px');
		clearInterval(slideTimer);
	}
}

function showNavSel(n) {
		nav_sel_table = $('table#tbl_nav_sel_'+n);
  		var offset = nav_sel_table.offset();
	  	posx = offset.left;
  		posy = offset.top + 21;
  		$('ul#nav_sel_'+n).css('left', posx+'px').css('top', posy+'px');
  		if ($('ul#nav_sel_'+n).is(':visible') ) {
			hideNavSel(n);
  		} else {
  			$('a#nav_sel_drop_'+n).css('background-image', 'url("images/nav_sel_drop_rev.jpg")');
  			$('ul#nav_sel_'+n).show();
  		}
  		if ($('ul#nav_sel_'+n).width() < $('table#tbl_nav_sel_'+n).width()) {
  			var isIE = (navigator.appName == "Microsoft Internet Explorer");
  			if (isIE) { remove = 0; } else { remove = 2; }
  			$('ul#nav_sel_'+n).css('width', ($('table#tbl_nav_sel_'+n).width()-remove)+'px')
  		} else {
  			$('ul#nav_sel_'+n).css('width', ($('ul#nav_sel_'+n).width()+10)+'px')
  		}
}

function hideNavSel(n) {
	$('a#nav_sel_drop_'+n).css('background-image', 'url("images/nav_sel_drop.jpg")');
	$('ul#nav_sel_'+n).hide();
}

function setNavSelLinkFalse(obj) {
	if ( $('ul#nav_sel_'+obj).is(":visible") && !on_nav_sel_link && !on_nav_sel_ul) {
		$('a#nav_sel_drop_'+obj).css('background-image', 'url("images/nav_sel_drop.jpg")');
		$('ul#nav_sel_'+obj).hide();
	}
}

function checkSearchHandle(e) {
	 var key;
     if (window.event) {
          key = window.event.keyCode;
     } else {
          key = e.which;
     }
     if (key == 13) {
          return false;
	} else {
          return true;
	}
}

function togglePriceVAT(orig_price) {
	if (curr_price_vat == 1) {
		$('span.productPriceSpEx_xl').html($('a#togglePriceA').attr('priceex'));
		$('a#togglePriceA').html('(excl. BTW)');
		curr_price_vat = 0;
	} else if (curr_price_vat == 0) {
		$('span.productPriceSpEx_xl').html($('a#togglePriceA').attr('pricein'));
		$('a#togglePriceA').html('(incl. BTW)');
		curr_price_vat = 1;
	}
}

function toggleExtraInfo(textid) {
	if($('div#'+textid).css('display') == 'none') {
		$('div#'+textid).css('display', 'inline');
	} else {
		$('div#'+textid).css('display', 'none');
	}
}

function selectRowEffect(object, buttonSelect) {
	if (!selected) {
		if (document.getElementById) {
			selected = document.getElementById('defaultSelected');
		} else {
			selected = document.all['defaultSelected'];
		}
	}

	if (selected) selected.className = 'moduleRow';
	object.className = 'moduleRowSelected';
	selected = object;

// one button is not an array
	if (document.checkout_address.address[0]) {
		document.checkout_address.address[buttonSelect].checked=true;
	} else {
		document.checkout_address.address.checked=true;
	}
}

function selectRowEffect2(object, buttonSelect) {
	if (!selected) {
		if (document.getElementById) {
			selected = document.getElementById('defaultSelected');
		} else {
			selected = document.all['defaultSelected'];
		}
	}

	if (selected) selected.className = 'moduleRow';
	object.className = 'moduleRowSelected';
	selected = object;

// one button is not an array
	if (document.checkout_address.address[0]) {
		document.checkout_address.address[buttonSelect].checked=true;
	} else {
		document.checkout_address.address.checked=true;
	}
}

function selectRowEffect3(object, buttonSelect) {
	if (!selected) {
		if (document.getElementById) {
			selected = document.getElementById('defaultSelected');
		} else {
			selected = document.all['defaultSelected'];
		}
	}

	if (selected) selected.className = 'moduleRow';
	object.className = 'moduleRowSelected';
	selected = object;

// one button is not an array
	if (document.checkout_address.address[0]) {
		document.checkout_address.address[buttonSelect].checked=true;
	} else {
		document.checkout_address.address.checked=true;
	}
}

function selectRowEffect4(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.checkout_payment.payment[0]) {
    document.checkout_payment.payment[buttonSelect].checked=true;
  } else {
    document.checkout_payment.payment.checked=true;
  }
}

function check_form_optional(form_name) {
	var form = form_name;

	var firstname = form.elements['firstname'].value;
	var lastname = form.elements['lastname'].value;
	var street_address = form.elements['street_address'].value;

	if (firstname == '' && lastname == '' && street_address == '') {
		return true;
	} else {
		return check_form(form_name);
	}
}

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}

function elementDisable (el_name, el_status)
{
	document.forms["rma_params"].elements[el_name].readOnly = el_status;
	el_status ? document.forms["rma_params"].elements[el_name].style.background = "#CCCCCC" : document.forms["rma_params"].elements[el_name].style.background = "#FFFFFF";
}

function RadioChanged(status)
{
	elementDisable ('products_orders_number', !status);
}

function validateForm()
{
	if ((document.forms["rma_params"].elements['customers_first_name'].value       == '') ||
			(document.forms["rma_params"].elements['customers_second_name'].value      == '') ||
			(document.forms["rma_params"].elements['customers_street_address'].value   == '') ||
			(document.forms["rma_params"].elements['customers_house_number'].value     == '') ||
			(document.forms["rma_params"].elements['customers_postcode'].value         == '') ||
			(document.forms["rma_params"].elements['customers_city'].value             == '') ||
			(document.forms["rma_params"].elements['customers_land'].value             == '') ||
			(document.forms["rma_params"].elements['customers_email_address'].value    == '') ||
			(document.forms["rma_params"].elements['customers_telephone'].value        == '') ||
			(document.forms["rma_params"].elements['products_purchase_date'].value     == '') ||
			(document.forms["rma_params"].elements['rma_text'].value                   == '')) {
		alert('Bericht kan niet verzonden worden! Gelieve alle noodzakelijke velden met een * in te vullen.');
		return false;
	} else {
		return true;
	}
}

function checkForm() {
  /*var error = 0;
  var error_message = "<?php echo JS_ERROR; ?>";

  var review = document.product_reviews_write.review.value;
  var firstname = document.product_reviews_write.customers_firstname.value;
  var lastname = document.product_reviews_write.customers_lastname.value;

  if (firstname.length < <?php echo ENTRY_FIRST_NAME_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_FIRST_NAME; ?>";
    error = 1;
  }

  if (lastname.length < <?php echo ENTRY_LAST_NAME_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_LAST_NAME; ?>";
    error = 1;
  }

  if (review.length < <?php echo REVIEW_TEXT_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_REVIEW_TEXT; ?>";
    error = 1;
  }

  if ((document.product_reviews_write.rating[0].checked) || (document.product_reviews_write.rating[1].checked) || (document.product_reviews_write.rating[2].checked) || (document.product_reviews_write.rating[3].checked) || (document.product_reviews_write.rating[4].checked)) {
  } else {
    error_message = error_message + "<?php echo JS_REVIEW_RATING; ?>";
    error = 1;
  }

  if (error == 1) {
    alert(error_message);
    return false;
  } else {
    return true;
  }*/
}

function rowOverEffect(object) {
	if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
	if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function checkBox(object) {
  document.account_notifications.elements[object].checked = !document.account_notifications.elements[object].checked;
}
function checkBox2(object) {
  document.account_newsletter.elements[object].checked = !document.account_newsletter.elements[object].checked;
}

function popupWindow(url) {
	window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function popupBigWindow(url) {  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=300,height=250,screenX=150,screenY=150,top=150,left=150')
}

function session_win() {
	window.open("<?php echo tep_href_link(FILENAME_INFO_SHOPPING_CART); ?>","info_shopping_cart","height=460,width=430,toolbar=no,statusbar=no,scrollbars=yes").focus();
}

function checkCheckBox(f){
if (f.agree.checked == false )
{
alert('<?php echo CONDITION_AGREEMENT_WARNING; ?>');
return false;
}else
return true;
}

function validateForm() 
{
  if ((document.forms["email_params"].elements['email_voornaam'].value           == '') || 
      (document.forms["email_params"].elements['email_achternaam'].value         == '') || 
      (document.forms["email_params"].elements['email_adres'].value              == '') || 
      (document.forms["email_params"].elements['email_postcode'].value           == '') || 
      (document.forms["email_params"].elements['email_plaats'].value             == '') || 
      (document.forms["email_params"].elements['email_phone'].value              == '') || 
      (document.forms["email_params"].elements['email_email'].value              == '') || 
      (document.forms["email_params"].elements['email_klachtomschrijving'].value == '')) {
    alert('Bericht kan niet verzonden worden! Gelieve alle noodzakelijke velden met een * in te vullen.');
    return false;
  } else {
    return true;
  }
}

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;
}

var isOpened = 0;

function popupWindow(url) {
	window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}
function popupBigWindow(url) {  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=300,height=250,screenX=150,screenY=150,top=150,left=150')
}

function TryToOpen(){
	if (!isOpened) {
		PopEx('imgPopIMG', null, null, 0, 0, 75, 'PopBoxImageLarge');
	}
}

function PrePopProcessing(obj)
{
	isOpened = 1 - isOpened;
}

function PostRevertProcessing(obj)
{
	isOpened = 1 - isOpened;
}
