/**************************************************************************************************
* Common JavaScript functions (client side execution)
*
* @author Krzysztof Chmielewski <chris@artcom-kolo.com.pl>
* @version 2.0 (2004-01-02)
***************************************************************************************************/

// Set of definitions, mirrored from /Includes/Globals/classes/Defs.class -----

var UNDEF = 'undefined';
var OK = 'ok';
var ERROR = 'error';

var reNULL = '';
var reNO = '^nie($| )'; var regexIsNo = /\^nie\(\$\| \)/;
var reANY = '.';
//var reEMAIL = '.*[^.]+@.*[^.]+\.[a-z]+[a-z]+$';
var reEMAIL = '^.+@.+[.][a-z]{2,4}$';
var reDATE = '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]';
var reINT = '\d|[ ]';
var reDOUBLE = '\d|[., ]';


var acceptEMAIL = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLŁMNOPQRSTUVWXYZ01234567890-@_."';
var acceptURL = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLŁMNOPQRSTUVWXYZ01234567890-=!@#$%^&*()_+[]{}~,./<>?:;"';
var acceptEN = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLŁMNOPQRSTUVWXYZ01234567890-=!@#$%^&*()_+[]{}~,./<>?:;"';
var acceptPL = ' aąbcćdeęfghijklłmnńoópqrsśtuvwxyzżźAĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŻŹ01234567890-=!@#$%^&*()_+[]{}~,./<>?:;"';

var illegalCHARS ='\\';


// Set of functions -----------------------------------------------------------

function syncCaption(title) {

	if(document.location.hostname == 'localhost') title = '(l) ' + title;
	if(String(document.location.hostname).match(/^amica-int$|artcom-kolo/)) title = '(a) ' + title;
  if(top) {
    parent.document.title = title;
  }
  document.title = title;
}

function powrot(win, refresh) {
	if(window == top) { 
		if(opener && refresh) win.opener.location.reload();
		win.opener.focus(); 
		win.close(); 
	}
	else 
		history.back();
}

function go2anchor(name) {
	this.location = '#'+ name;
}


function openPopUp(x, y, w, h, name, page) {

	winPopUp = window.open(page,name, 'location=no,menubar=no,scrollbars=yes,status=yes,resizable=yes,dependent=yes,width='+ w +',height='+ h +',screenX='+ x+',screenY='+ y +',left='+ x+',top='+ y +'');
	if(!winPopUp) 
		alert('Okienko pomocnicze nie zostało otwarte z powodu blokady pop-up.')
	else 
		winPopUp.focus();
	return winPopUp;
}

function openPopUpFullLocation(x, y, w, h, name, page) {

	winPopUp = window.open(page,name, 'toolbar=yes,location=yes,menubar=no,scrollbars=yes,status=yes,resizable=yes,dependent=yes,width='+ w +',height='+ h +',screenX='+ x+',screenY='+ y +',left='+ x+',top='+ y +'');
	if(!winPopUp) 
		alert('Okienko pomocnicze nie zostało otwarte z powodu blokady pop-up.')
	else 
		winPopUp.focus();
	return winPopUp;
}

function openPopUpFull(x, y, w, h, name, page) {

	winPopUp = window.open(page,name, 'toolbar=yes,location=no,menubar=no,scrollbars=yes,status=yes,resizable=yes,dependent=yes,width='+ w +',height='+ h +',screenX='+ x+',screenY='+ y +',left='+ x+',top='+ y +'');
	if(!winPopUp) 
		alert('Okienko pomocnicze nie zostało otwarte z powodu blokady pop-up.')
	else 
		winPopUp.focus();
	return winPopUp;
}

function openPopUpNoStatus(x, y, w, h, name, page) {

	winPopUp = window.open(page,name, 'location=no,menubar=no,scrollbars=yes,status=no,resizable=yes,dependent=yes,width='+ w +',height='+ h +',screenX='+ x+',screenY='+ y +',left='+ x+',top='+ y +'');
	if(!winPopUp) 
		alert('Okienko pomocnicze nie zostało otwarte z powodu blokady pop-up.')
	else 
		winPopUp.focus();
	return winPopUp;
}


function openPopUpNoBars(x, y, w, h, name, page) {

	winPopUp = window.open(page,name, 'location=no,menubar=no,scrollbars=no,status=no,resizable=no,dependent=yes,width='+ w +',height='+ h +',screenX='+ x+',screenY='+ y +',left='+ x+',top='+ y +'');
	if(!winPopUp) 
		alert('Okienko pomocnicze nie zostało otwarte z powodu blokady pop-up.')
	else 
		winPopUp.focus();
	return winPopUp;
}


function openPdf(url) {		// nowe okno z pdf-em

  var WinName = "pdfWin" + String(Math.random()).substring(2);
  winPdf = window.open(url,WinName, "location=no,menubar=yes,status=yes,resizable=yes,dependent=yes");
	if(!winPdf) 
		alert('Okienko pomocnicze nie zostało otwarte z powodu blokady pop-up.')
	else 
		winPdf.focus();
}

function openSendLink(uprawnienia) {	// nowe okno z linkiem do wysłania znajomemu

  var link = "/Commons/Files/mailings/link.send.prep.php?tytul=" + (document.title) + "&link=" + escape(location.protocol + '//' + location.hostname + location.port + top.location.pathname + top.location.search + top.location.hash) + "&upr=" + escape(uprawnienia);
	//alert(link);
  sendWindow = window.open(link,'send', 'location=no,menubar=no,status=no,resizable=no,dependent=yes,width=310,height=400,screenX=50,screenY=150,left=50,top=150')
	if(!sendWindow) 
		alert('Okienko pomocnicze nie zostało otwarte z powodu blokady pop-up.')
	else 
		sendWindow.focus();
}


function add2Favorite() {	// dodaj do ulubionych - wstęp w .js (dalej funkcja z common.vbs)
var re = /MSIE 4|MSIE 5|MSIE 6/;

	if(!re.test(navigator.userAgent)) {
		alert("Ta funkcja działa tylko w przeglądarce Microsoft Internet Explorer 4 lub wyższej  ");
	} else {
		vb_add2Favorite();
	}
}

function getFullServer(strURL) {	// docelowo niepotrzebne
  var re = /[^:\/]\//
  var results = re.exec(strURL)
  return results.input.substring(0,results.index+1)
}

function dropServer(strURL) {		// docelowo niepotrzebne
  var re = /[^:\/]\//
  var results = re.exec(strURL)
  return results.input.substr(results.index+1)
}


