// JavaScript Document
function ChangeClass (obj, class_name) {
	obj.className = class_name;
}
function ChangeClassById (obj, class_name)
{
	document.getElementById(obj).className = class_name;
}
function GoTo (url) {
	window.location.href = url;
}
function SwapClasses (id, class1, class2) {
	var obj = document.getElementById(id);
	if(obj.className==class1) { obj.className=class2; }
	else { obj.className=class1; }
}
function getyScroll()
{	
	yScroll = 0;
	if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX)
	{
		yScroll = window.innerHeight + window.scrollMaxY;
		xScroll = window.innerWidth + window.scrollMaxX;
		
		var deff = document.documentElement;
		var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
		var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
		
		xScroll -= (window.innerWidth - wff);
		yScroll -= (window.innerHeight - hff);
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth)
	{
		yScroll = document.body.scrollHeight;
		xScroll = document.body.scrollWidth;
	} 
	else
	{
		if(window.innerHeight || window.innerWidth) {
			yScroll = window.innerHeight;
			xScroll = document.body.offsetWidth;
		} else {
			yScroll = document.body.offsetHeight;
			xScroll = document.body.offsetWidth;
		}
	}
	return yScroll;
}

function show_splash(id)
 {
  $(window).scrollTop(0);
  var inputs = document.getElementsByTagName('select');
  for (i=0;i<inputs.length;i++) {
		inputs[i].style.visibility = 'visible';  
  }
  document.getElementById(id).style.display = 'block';
  document.getElementById('screen').style.display = 'block';
  document.getElementById('screen').style.height = getyScroll() + 'px'; //window.innerHeight + window.scrollMaxY;
  $('embed').css("display", "none");
  $(".flash").css("display", "none");
 }

function hide_splash(id)
 {
  var inputs = document.getElementsByTagName('select');
  for (i=0;i<inputs.length;i++) {
		inputs[i].style.visibility = 'visible';  
  }
  document.getElementById(id).style.display = 'none';
  document.getElementById('screen').style.display = 'none';
  $('embed').css("display", "block");
  $(".flash").css("display", "block");
 }

function check_els(obj, elname) {
	var els = document.getElementsByTagName('input');
	for (i=0;i<els.length;i++) {
		if(els[i].name==elname) {
			if(obj.checked==true) {
				els[i].checked = true;
			}
			else {
					els[i].checked = false;
			}
		}
	}
}
function trim_string(str)
{
  return str.replace(/^\s+|\s+$/g, "");
}
function email_validator(email_string)
{
	param = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (param.test(email_string))
		return true;
	else
		return false;
}
function checkDate()
{
	days=document.getElementById('exp_day').value;
	months=document.getElementById('exp_month').value;
	years=document.getElementById('exp_year').value;
	if(years%4==0)
		monthMax=monthsAmount(months, true);
	else
		monthMax=monthsAmount(months, false);
	
	if(days>monthMax)
	{
		document.getElementById('exp_day').value=monthMax;
	}
}
function monthsAmount(m, bissextile)
{
	if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)
		return 31;
	else if(m==2)
	{
		if(bissextile==true)
			return 29;
		else
			return 28;
	}
	else
		return 30;
}


var validate = function($form) {

	$form = $($form);
	if ("FORM" != $form.get(0).tagName) {
	    $form = $form.find("form");	
	}
	
    $form.each(function() {
	var $form = $(this);
	$submit = $form.find("input[type='submit']");
	if (!$submit.length) {
	    $submit = $form.find(".submit");	
	}
	$submit.bind("click", function(e) {
	    e.preventDefault();
	    $form.find(".error").remove();
	    var correct = true;
	  $form.find(".required").each(function() {
	      var $this = $(this);
	      var $input;
	      if (($this.get(0).tagName == "TEXTAREA") || ($this.get(0).tagName == "INPUT")) {
	          $input = $this;
	      }
	      else {
	          $input = $this.find("input, textarea");
	      }

	      if ("" == $.trim($input.val())) {
	          var errText = $this.attr("witamean:error_message") || "This field is required";
	      
	      
	          if ($input == $this) {
	              $("<p />").insertAfter($this).addClass("red small error").text(errText);	
	          }
	          else {
	             $("<p />").appendTo($this).addClass("red small error").text(errText);	
	          }
	          
	          correct = false;
	      }
	  });
	  
	  if (correct) {
	      $form.submit();  
	  }
	  });
	  
	   
	});
	

	
};
