/***************************************
* 
***************************************/
function goTo (l) {
	location.href=l;
}



/***************************************
* 
***************************************/
function changeBgInputOver(el) {
	//el.style.backgroundColor = '#ffffff';
	//el.style.border = '1px solid #dddddd';
}
function changeBgInputOut(el) {
	//el.style.backgroundColor = '#f9f9f9';
	//el.style.border = '1px solid #dddddd';
}
function changeBgInputFocus(el) {
	//el.style.backgroundColor = '#ffffff';
	//el.style.border = '1px solid #bbbbbb';	
}



/***************************************
* 
***************************************/
function changeBgImgOver(el) {
	el.style.backgroundColor = '#ffffff';
}
function changeBgImgOut(el) {
	el.style.backgroundColor = '#f7f7f7';
}



/***************************************
* 
***************************************/
function FormatNumberBy3(num, decpoint, sep) {
  // check for missing parameters and use defaults if so
  if (arguments.length == 2) {
    sep = " ";
  }
  if (arguments.length == 1) {
    sep = " ";
    decpoint = ".";
  }
  // need a string for operations
  num = num.toString();
  // separate the whole number and the fraction if possible
  a = num.split(decpoint);
  x = a[0]; // decimal
  y = 0;//a[1]; // fraction
  z = "";

  if (typeof(x) != "undefined") {
    // reverse the digits. regexp works from left to right.
    for (i=x.length-1;i>=0;i--)
      z += x.charAt(i);
    // add seperators. but undo the trailing one, if there
    z = z.replace(/(\d{3})/g, "$1" + sep);
    if (z.slice(-sep.length) == sep)
      z = z.slice(0, -sep.length);
    x = "";
    // reverse again to get back the number
    for (i=z.length-1;i>=0;i--)
      x += z.charAt(i);
    // add the fraction back in, if it was there
    if (typeof(y) != "undefined" && y.length > 0)
      x += decpoint + y;
  }
  return x;
}



/***************************************
* 
***************************************/
function checkEmailAddress(field) {
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.info)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	
	if (goodEmail){
	  return true
	} else {
    field.focus()
    field.select()
    return false
  }
}



/***************************************
* 
***************************************/
function checkDate(dateStr) {
	// DD/MM/YY   DD/MM/YYYY   DD-MM-YY   DD-MM-YYYY
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Format daty powinien byc DD-MM-YYYY")
		return false;
	}
	month = matchArray[3];
	day = matchArray[1];
	year = matchArray[4];

	if (day < 1 || day > 31) {
		alert("Dzień musi być pomiędzy 1 a 31.");
		return false;
	}	
	
	if (month < 1 || month > 12) { // check month range
		alert("Miesiąc musi być pomiędzy 1 a 12.");
		return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Miesiąc "+month+" nie ma 31 dni!")
		return false
	}
	
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
		alert("Miesiąc Luty  w " + year + "r. nie miał " + day + " dni!");
		return false;
   }
}
return true;  // date is valid
}





/***************************************
* 
***************************************/


function setZoom(img, dir, width, height, margin, zIndex, delay) {
	setTimeout(function() {
		if (img.dir==dir) {
			img.style.width=width;
			img.style.height=height;
			img.style.margin=margin;
			img.style.zIndex=zIndex;
			img.parentNode.parentNode.style.zIndex=zIndex;
		}
	}, delay);
}

function larger(img, width, height) {
	img.dir='rtl';
	now=parseInt(img.style.zIndex);
	for (i=now+1; i<=10; i++) {
		w=(width*(10+i))/20+'px';
		h=(height*(10+i))/20+'px';
		m=(-i)+'px 0 0 '+(-width*i/40)+'px';
		setZoom(img, 'rtl', w, h, m, i, 20*(i-now));
	}
}

function smaller(img, width, height) {
	img.dir='ltr';
	now=parseInt(img.style.zIndex);
	for (i=now-1; i>=0; i--) {
		w=(width*(10+i))/20+'px';
		h=(height*(10+i))/20+'px';
		m=(-i)+'px 0 0 '+(-width*i/40)+'px';
		setZoom(img, 'ltr', w, h, m, i, 20*(now-i));
	}
}




/***************************************
* CIASTKA
***************************************/

// pobiera wartosc ciastka
function getCookieValue(cookieName){
	cookieName+="=";
	startIndex=document.cookie.indexOf(cookieName);
	if (startIndex==-1) {
		return "";
	}
	startIndex+=cookieName.length;

	if (document.cookie.indexOf(";",startIndex)==-1) {
		endIndex=document.cookie.length;
	} else {
		endIndex=document.cookie.indexOf(";",startIndex);
	}
	cookieValue=document.cookie.substring(startIndex,endIndex);
	cookieValue=unescape(cookieValue);
	return cookieValue;
}

// ustawia wartosc ciastka
function setCookieValue(cookieName, cookieValue) {
	cookieValue=escape(cookieValue);
	document.cookie=cookieName + "=" + cookieValue + '; path=/';
}
