
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name){var dc=document.cookie;var prefix=name+"=";var begin=dc.indexOf("; "+prefix);if(begin == -1){begin=dc.indexOf(prefix);if(begin != 0) return null;}else begin+=2;var end=document.cookie.indexOf(";", begin);if(end == -1)end=dc.length;return unescape(dc.substring(begin+prefix.length, end));}

var wybranekolko = 'kolko0';
var jakiidstrony ;
function changekolko(th)
{
	var kulkoID = th.id.replace(/kolko/, '');
	for(jj = 0; jj< 50; jj++)
	{
		if(document.getElementById("kolko"+jj)) $("kolko"+jj).src = "img/kol_off.jpg";
	}

	$("kolko"+kulkoID).src = "img/kol_on.jpg";
	
	setCookie('jakiidstrony','section'+kulkoID,'');
	setCookie('nrIdKulka',kulkoID,'');
	
}

function showBox(opcja) {
	switch(opcja) {
		case 'zgloszenie':
			content = getZgloszenie();
		break;
	}
	
	$('layer1').style.paddingTop = 70 + 'px';
	$('layer1').innerHTML = content;
	$('layer').style.display = 'block';
	$('layer1').style.display = 'block';
	var he = getPageSize();
	//var proc = Math.round((window.screen.availWidth*9)/100);
	var left = he[3];//window.screen.availHeight - proc;
	if(he[1] > 768) {
		$('layer').style.height = left - 90 + 'px';
	} else {
		$('layer').style.height = left + 'px';
	}

	//if(window.screen.availWidth < 1340) {
		//$('layer').style.width = 1340 + 'px';
		//$('layer1').style.left = (1340 - window.screen.availWidth)/2 + 10 + 'px';
	//}
}
//												javascript:showLightbox(1);
function showLightbox(send) {
	obr = '';
	//alert(send);
	if(send == '1')
		obr = 'dz_kontakt';

	if(send == '2')
		obr = 'dz_casting';

	$('layer1').innerHTML = '<img src="img/' + obr + '.jpg" />';
	$('layer').style.display = 'block';
	$('layer1').style.display = 'block';

	var he = getPageSize();

	//var proc = Math.round((window.screen.availWidth*9)/100);
	var left = he[3];//window.screen.availHeight - proc;
	$('layer').style.height = left - 90 + 'px';
	$('layer1').style.paddingTop = (left - 180) / 2 + 'px';

	if(window.screen.availWidth < 1340) {
		//$('layer').style.width = 1340 + 'px';
	}

	setTimeout('closeLayer()',3000);
}

function myCloseLayer(adres) {
	$('layer').style.display = 'none';
	$('layer1').style.display = 'none';

	var jakiidstrony = getCookie('jakiidstrony');
	window.location="http://www.mkumodels.co.uk/"+adres+"#"+jakiidstrony;
}

function closeLayer() {
	$('layer').style.display = 'none';
	$('layer1').style.display = 'none';
}

function getZgloszenie() {
	var obj = new Ajax.Request('index.php?action=zgloszenie',{ asynchronous:false });
	res = obj.transport.responseText;

	return res;
}

function checkHostessyForm(asd) {
	if($('autoryzacja').value != asd) {
		alert('Rewrite the code from image correctly.');
		$('autoryzacja').focus();
		return false;
	}

	return true;
}

function checkKontakt(asd) {
	if(!CheckEmail($('email').value)) {
		alert('Enter correct email address.');
		$('email').focus();
		return false;
	}

	if($('autoryzacja').value != asd) {
		alert('Rewrite the code from image correctly.');
		$('autoryzacja').focus();
		return false;
	}

	if($('trescwiad').value == '') {
		alert('Enter the message.');
		$('trescwiad').focus();
		return false;
	}

	return true;
}


function CheckEmail(y) {
	if (y == "") {
		return false;
	}

	var x= new String(y);
	x.toLowerCase();
	var ret= new String();
	var znaki1= ".-+_@";
	var znaki= "0123456789zxcvbnmasdfghjklqwertyuiop" + znaki1;

	if ( x.length < 1 )
		return false;

	if ( x.indexOf("@") == -1 ) {
		ok= 0;
		return false;
	}

	if ( x.indexOf("@") != x.lastIndexOf("@") ) {	
		ok= 0;
		return false;
	}

	for ( i=0; i < x.length; ++i)
		if ( znaki.indexOf(""+x.charAt(i)) == -1 ) {
			ok= 0;
			return false;
		}

	if ( znaki1.indexOf(x.charAt(x.length-1)) != -1 ) {
		ok= 0;
		return false;
	}
			
	return true;
}

function checkZgloszenie(ads) {
	if($('imienazwisko').value == '') {
		alert('Enter your name and surname.');
		$('autoryzacja').focus();
		return false;
	}

	if($('miasto').value == '') {
		alert('Enter the city name.');
		$('autoryzacja').focus();
		return false;
	}
	if(!CheckEmail($('email').value)) {
		alert('Enter correct email address.');
		$('email').focus();
		return false;
	}
	
	if($('autoryzacja').value != ads) {
		alert('Rewrite the code from image correctly.');
		$('autoryzacja').focus();
		return false;
	}

	$('ladowanieForm').style.display = 'block';

	return true;
}

function showModelLayer(id,nazwa,nrstrony) {
	var obj = new Ajax.Request('index.php?action=showModelLayer&id=' + id + '&rodzaj=' + nazwa + '&page=' + nrstrony, { asynchronous:false });
	res = obj.transport.responseText;
	$('layer').style.display = 'block';
	$('layer1').style.display = 'block';
	
	var he = getPageSize();

	//var proc = Math.round((window.screen.availWidth*9)/100);
	var left = he[3];//window.screen.availHeight - proc;
	if(he[1] > 768) {
		$('layer').style.height = left - 90 + 'px';
	} else {
		$('layer').style.height = left + 'px';
	}

	if(window.screen.availWidth < 1340) {
	//	$('layer').style.width = 1340 + 'px';
	//	$('layer1').style.left = (1340 - window.screen.availWidth)/2 + 10 + 'px';
	}

	$('layer1').innerHTML = res;
}

function emailAdd() {
	if(!CheckEmail($('adres').value)) {
		alert('Enter correct email address.');
		$('adres').focus();
		return false;
	}
	return true;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else 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;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}