
FILE_NAME_PATTERN = /^([0-9]|[a-z]|_)+$/i;
EMAIL_PATTERN = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
NAME_PATTERN=/^([0-9]|[a-z])+$/i;
PASSWORD_PATTERN=/^([0-9]|[a-z])+$/i;
FLOAT_PATTERN = /^-?\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;

var form_get_action = "";

// ***** //

function get_pos(elemid)
{
	var elem = document.getElementById(elemid);
	var elemx = 0;
	var elemy = 0;

	while(elem)
	{
		elemx += elem.offsetLeft;
		elemy += elem.offsetTop;
		elem = elem.offsetParent;
	}
	if(navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftmargin != 'undefined')
	{
		elemx += document.body.leftMargin;
		elemy += document.body.topMargin;
	}
	return {x:elemx, y:elemy};
}

// ***** //

function goto_url(url) {
 
	document.location.href = url;
}

// ***** //

function get_form_action(form_name) {

	if(form_get_action.length == 0) {
		
		form_get_action = document.forms['form_nav'].action; 
	}
}

// ***** //

function open_kolory() {

	get_form_action('form_nav');
	//document.forms['form_nav'].action = "http://www.hybrid.pl/dryvit/kolory2";
	document.forms['form_nav'].action = SITE_URL + "kolorowanie/";
	document.forms['form_nav'].target = '_blank';
	document.forms['form_nav'].submit();
}

// ***** //

function open_iso() {

	get_form_action('form_nav');
	document.forms['form_nav'].action = SITE_URL + "kalkulator/";
	document.forms['form_nav'].target = '_blank';
	document.forms['form_nav'].submit();
}

// ***** //

function open_etykieta() {

	get_form_action('form_nav');
	document.forms['form_nav'].action = "http://www.oszczednydom.pl/etykieta/dryvit";
	document.forms['form_nav'].target = '_blank';
	document.forms['form_nav'].submit();
}

// ***** //

function hide_inf_panel() {
		
	document.getElementById('id_info_panel').style.display = 'none';
	document.getElementById('id_info_panel').style.visibility = 'hidden';
}

// ***** //

/* WINDOW FUNCTIONS */
var win1;

function open_window(link_url, w, h, window_name, conf)
{
	l = (screen.availWidth - w) / 2;
	t = (screen.availHeight - h) / 2;
	win1 = window.open(link_url, window_name, 'width=' + w + ', height=' + h + ', left=' + l + ', top=' + t + conf).focus();
	return win1;
}

// ***** //

function zoom(type, index, w, h)
{
	open_window(SITE_URL+'zoom.php?lang='+LANG+'&a='+type+'&b='+index+'&w='+w+'&h='+h, 400, 400, 'WinZoom', 'scrollbars=1');
}

function win_pattern(prod_id)
{
	open_window(SITE_URL+'pattern.php?lang='+LANG+'&prod_id='+prod_id, 500, 500, 'WinProd', 'scrollbars=1');
}

function win_print()
{
	open_window(SITE_URL+'print.php', 700, 600, 'WinPrint', 'scrollbars=1');
}

// ***** //

/* DISPLAY FUNCTIONS */
function show_element(element_id)
{
	if(navigator.appName=='Netscape')
		d='table-row';
	else
		d='block';
	document.getElementById(element_id).style.display = d;
}

function hide_element(element_id)
{
	document.getElementById(element_id).style.display = 'none';
}

function display_action(element_id)
{
	if(document.getElementById(element_id).style.display == 'none')
		show_element(element_id);
	else	hide_element(element_id);
}

// ***** //

function on_focus_find()
{
	document.forms['form_search'].elements['q'].value = '';
}

// ***** //

function on_blur_find(txt) {

	if(document.forms['form_search'].elements['q'].value == "") {
	
		document.forms['form_search'].elements['q'].value = txt;
	}
}

// ***** //

// COLOR FUNCTIONS
function rgb2cmyk(r, g, b)
{
	cyan = 255 - r;
   	magenta = 255 - g;
   	yellow = 255 - b;
   	tmp_black = Math.min(cyan, magenta); 
   	black = Math.min(tmp_black, yellow);
   	cyan = ((cyan - black) / (255 - black)) * 255;
   	magenta = ((magenta - black) / (255 - black)) * 255;
   	yellow = ((yellow - black) / (255 - black)) * 255;
   	
//	return {c:(cyan / 255), m:(magenta / 255), y:(yellow / 255), k:(black / 255)};
	return {c:(cyan / 100), m:(magenta / 100), y:(yellow / 100), k:(black / 100)};
}

function normalize255(val)
{
	return (val / 255);
}

function normalize100(val)
{
	return (val / 100);
}

function cmyk2rgb(c1, m1, y1, k1)
{
	c2 = normalize100(c1);
	m2 = normalize100(m1);
	y2 = normalize100(y1);
	k2 = normalize100(k1);

	c2 = Math.min(1, (c2 * (1 - k2) + k2));
	m2 = Math.min(1, (m2 * (1 - k2) + k2));
	y2 = Math.min(1, (y2 * (1 - k2) + k2));

	r = 1 - c2;
	g = 1 - m2;
	b = 1 - y2;

	r_val = r * 255;
	g_val = g * 255;
	b_val = b * 255;

	return {r:Math.round(r_val), g:Math.round(g_val), b:Math.round(b_val)};
}

function dec2hex_255(dec)
{
	conv_tbl = new Array('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0a', '0b', '0c', '0d', '0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', '2f', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3a', '3b', '3c', '3d', '3e', '3f', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', '5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '8a', '8b', '8c', '8d', '8e', '8f', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '9a', '9b', '9c', '9d', '9e', '9f', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'ba', 'bb', 'bc', 'bd', 'be', 'bf', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'ca', 'cb', 'cc', 'cd', 'ce', 'cf', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'da', 'db', 'dc', 'dd', 'de', 'df', 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'ea', 'eb', 'ec', 'ed', 'ee', 'ef', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'fa', 'fb', 'fc', 'fd', 'fe', 'ff');
	return conv_tbl[dec];
}

function rgb2hex(r, g, b)
{
	hex = '#' + dec2hex_255(r) + dec2hex_255(g) + dec2hex_255(b);
	return hex;
}

function getPageSize()	// Core code from - quirksmode.org
{
	var xScroll, yScroll;
	var windowWidth, windowHeight, pageWidth, pageHeight;

	if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	return {pageWidth:pageWidth, pageHeight:pageHeight, windowWidth:windowWidth, windowHeight:windowHeight};
}	

