function new_window(adres) {
	noweOkno = window.open(adres, 'Golfi', 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no, width=1000, height=700')
}

function new_window_size(adres, name, w, h) {
	noweOkno = window.open(adres, name, 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no, width='+w+', height='+h)
}

function close_window(){
	$('compareInstr').style.display = 'none';
	setCookie('compare','1',1);
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name){
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function showhide_elem(parentobj_id,num){

	for(var i=0; i<$(parentobj_id).childNodes.length; i++){
		$(parentobj_id).childNodes[i].style.display='none';
	}
	if (num){$(parentobj_id).childNodes[num].style.display='block';}
}

function make_active(obj, parent_obj){

var temp = new Array();

	for(var i=0; i<parent_obj.childNodes.length; i++){
		temp = parent_obj.childNodes[i].className.split(' ');
		if(temp[1]=='active'){
			parent_obj.childNodes[i].className=temp[0];
		}
	}
	obj.className = obj.className+' active';
}

function logIn(val)
{
	if(val){
		$('login_form'+val).set ('send', {onSuccess: ansLogin});
		$('login_form'+val).send();
	}
	else{
		$('login_form').set ('send', {onSuccess: ansLogin});
		$('login_form').send();
	}
}

function ansLogin (res)
{
	ret = JSON.decode (res);
	if (ret['msg']) {
		alert (ret['msg']);
	}
	if (ret['success'] == 1) {
		window.location.reload();
	}
}

function logOut(domain)
{
	url = domain + '/user/?a=logout';
	var myAjax = new Request({
		method: 'get',
		url: url,
		onSuccess: logoutAnswer
	}).send();

}

function logoutAnswer(res)
{
	ret = JSON.decode (res);
	if (ret['msg']) {
		alert (ret['msg']);
	}
	if (ret['success'] == 1) {
		window.location.reload();
	}

}

function checkNIP( inputVal )
{
	 if ( !inputVal.match( /^[0-9]{3}-[0-9]{3}-[0-9]{2}-[0-9]{2}$/ ) ){
		return false;
	 }
	 var ar = inputVal.replace(/-/g,'');
	 var arg = inputVal.replace(/-/g,'');
	 var coefficients = "657234567";
	 var sum=0;
	 var index=8;
	 for (index=8; index>=0 ;index--){
		 sum += (parseInt(coefficients.charAt(index)) * parseInt(arg.charAt(index)));
	 }
	 if ( (sum % 11) == 10 ? false : ((sum % 11) == parseInt(arg.charAt(9))) ){
		return true;
	 }

  return false;
}

function checkEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
}

function checkPhone(phone) {
    
	var stripped = phone.replace(/[\(\)\.\-\ ]/g, '');
	var reg = /^(\d)+$/;
	if (reg.test(stripped) == false) {
	   return false;
	}
}	

function checkZip(zip) {
    
	var reg = /^\d{2}\-\d{3}$/;
	if(reg.test(zip) == false) {
      return false;
   }
}

function testKeyCode(e, form_name) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	var e = e || window.event;

	if(keycode==13){
		if(form_name=='login'){
			logIn();
		}
		else if(form_name=='basket_send_data'){
			basketLogIn();
		}
		else if(form_name=='p_navigation'){
			document.p_navigation.submit();
		}
	 }
}

function searchBoxReload()
{
	$('pbox_navigation').appendChild(new Element('input', {type: 'hidden', value: 'ajax', name: 'ajax', id: 'p_ajax'}));
	$('pbox_navigation').set ('send', {onSuccess: ansBoxSearch});
	$('pbox_navigation').send();
}

function searchListReload()
{
	$('p_navigation').appendChild(new Element('input', {type: 'hidden', value: 'ajax2', name: 'ajax', id: 'p_ajax'}));
	$('p_navigation').set ('send', {onSuccess: ansListSearch});
	$('p_navigation').send();
}

function searchAdvanced()
{
	$('p_navigation').appendChild(new Element('input', {type: 'hidden', value: 'advanced', name: 'search_type', id: 'p_search_type' }));
	searchBoxReload();
}

function ansBoxSearch(ans)
{
	$('pbox_navigation').innerHTML = ans;
}
function ansListSearch(ans)
{
	$('p_navigation').innerHTML = ans;
}

function changePhoto(photoId, mainId){

	var a = $(photoId).getAttribute("alt").split("|");
	$(mainId).src=a[0];
	$(mainId+'_descr').innerHTML=a[2];
	$(mainId+'_author').innerHTML=a[1];
}


function encyclopediaCloud(obj) {
	obj.style.display='';
}

function encyclopediaCloudOff(obj) {
	obj.style.display='none';
}

function showPreloader(){
	$('preloaderId').style.display='';
}

function hidePreloader(){
	$('preloaderId').style.display='none';
}
function show_advice(elem) {
	elem.style.display='';
}

function hide_advice(elem) {
	elem.style.display='none';
}

function copy_datafields(form_id, from_f, to_f, f_check){

	sels = $$('#'+form_id+' input[type=text], #'+form_id+' select');
	if (f_check.checked ==true){		
		sels.each (function (val) {
			if($(val.id.replace(to_f,from_f))){
				val.value = $(val.id.replace(to_f,from_f)).value;
			}
		});
		
		if($(to_f+'country_area')){$(to_f+'country_area').value = $('u_country_area').value;}
		if($(to_f+'address')){$(to_f+'address').value = $('street').value;}
			
		if(to_f=='inv_'){
			if($(to_f+'name')){$(to_f+'name').value = $('name').value+' '+$('surname').value;}	
		}	
	}
	else{
		sels.each (function (val) {
			val.value = '';
		});
	}
}

function showOfferPhoto(photo_id){
	photos = $$('div[id^=photo]');
	photos.each (function (val) {
		val.style.display='none';
	});
	$('photo_'+photo_id).style.display='block';
}

function selectAns(f_val, num){
  
  sels = $$('#advAns li');
    sels.each (function (val, ind) {
      if(ind == num){
        val.className='actLi actLi'+ind;  
      }else{  
        val.className='ansLi'+ind;
      }      
    });    
  
  $('answer_value').value = f_val;
}

function loadPage(obj_id, url){
	$(obj_id).style.display='';
	$(obj_id).load(url);
}

function selectCity(f_val, parent_id, obj_id){
  
  sels = $$('#'+parent_id+' a');
  sels.each (function (val, ind) {
    val.className='';

  });  
  $(obj_id).className = 'act';  
  $('answer_value').value = f_val;
}

function changeArea(num){
  
  $('advLoc').style.display='none';
  sels = $$('#allCities .adviserCity');
  sels.each (function (val) {
    val.style.display = 'none';      
  });  
  $('subLoc_'+num).style.display='';  
}

function showIcoDesc(el){
	$('icon_desc_'+el).style.display='';
}

function hideIcoDesc(el){
	$('icon_desc_'+el).style.display='none';
}

function showJobDetails(num){
	sels = $$('div .job_details');			
	sels.each (function (val) {
		val.setStyle('display', 'none');				
	});
	$('job_details_'+num).style.display='';
}


function showPanel(num){
    var mySlide = new Fx.Slide('realization'+num);
    mySlide.toggle();

    if($('realizationLink'+num)){
        var newHTML = $('realizationLink'+num).innerHTML == unroll ? roll_up : unroll;
        $('realizationLink'+num).innerHTML = newHTML;
        var newClass = $('realizationLink'+num).parentNode.className == 'realizationHeader' ? 'realizationHeader realizationHeaderActive' : 'realizationHeader';
        $('realizationLink'+num).parentNode.className = newClass;
    }
}

function showUserPanel(num){

	if($('contentPanel'+num).style.display=='none' || $('userPanelLink'+num).innerHTML=='+'){
		
		//slideInPanel(num);
		sels = $$('#userPanel div.contentPanel');
		sels.each (function (val) {
			val.style.display='none';
			var act_num = (val.id.replace(/contentPanel/, ""));
			$('userPanelLink'+act_num).innerHTML='+';
		});	
		$('contentPanel'+num).style.display='';
		$('userPanelLink'+num).innerHTML='-';
		
	}else{	
		//slideOutPanel(num);
		$('contentPanel'+num).style.display='none';
		$('userPanelLink'+num).innerHTML='+';
	}
}

function showFilter(){	
	$('s_prop').setStyle('display','');
	$('show_prop').setStyle('display','none');
	$('hide_prop').setStyle('display','');
	$('p_filter').value='1';
}

function hideFilter(){	
	$('s_prop').setStyle('display','none');
	$('show_prop').setStyle('display','');
	$('hide_prop').setStyle('display','none');
	$('p_filter').value='';
}

var timer1;

function licznik(){
	czas = $('testowy').innerHTML.toInt();
	if(getCookie('timer')!='1'){
		if(czas > 0){
			czas -= 1;		
			$('testowy').innerHTML = czas;
			czas_m = (czas/60).toInt();
			czas_s = czas%60;
			$('czass').innerHTML = czas_m+' '+czas_s;
		}
		else{
			$clear(timer1);
			
			var mainH = $('mainBox').offsetHeight+'px';
			$('zoomBox').setStyle('display', '');
			$('zoomBox').setStyle('height', mainH);			
			$('alertInfo').setStyle('display', '');
		}
	}	
}

function closeCount(){
	if($('ifCount').checked==false){startCount();}
	else{
		$clear(timer1);
		setCookie('timer','1',3);
	}
	$('alertInfo').setStyle('display', 'none');
	$('zoomBox').setStyle('display', 'none');
}

function startCount(){	
	$('testowy').innerHTML = '300';
	timer1 = licznik.periodical(1000);
}		

function restartCount(){
	if(getCookie('timer')!='1'){
		if($('alertInfo').getStyle('display')=='none'){
			$clear(timer1);	
			startCount();
		}
	}		
}

function rangePrice(val, name){
	var price = val.split("/");
	$(name+'_search_2').value=price[0];
	$(name+'_search_3').value=price[1];
}

function showThisPhotos(num_photo){
	$$('#galImage img').each (function (val, i){
            var displayStyle = i == num_photo-1 ? '' : 'none';
            val.setStyle('display', displayStyle);
	});
}

function showThisPhotosClose(num_photo){
	$$('#galImage img').each (function (val, i){
            var displayStyle = i == num_photo-1 ? '' : 'none';
            val.setStyle('display', displayStyle);
	});
	$$('#galImages img').each (function (val, i){
            var displayStyle = i == num_photo-1 ? 'none' : '';
            val.setStyle('display', displayStyle);
	});	
}

function showNextPicture(){
    var all_pict = $$('#partners a');
    var num_pict = $('partners').style.left=='' ? 4 : ((parseInt($('partners').getStyle('left').replace('px',''))*(-1))/250)+1;

    if(all_pict.length - num_pict<3){var currLeft =(3*250*(-1)); $('partners').setStyle('left', currLeft+'px');num_pict=4;}
    var curr_val = (num_pict*250*(-1));
    var myFx = new Fx.Tween($('partners'),{duration:300,transition: Fx.Transitions.linear});
    myFx.start('left', curr_val+'px');
}

function showPrevPicture(){
    var all_pict = $$('#partners a');
    var num_pict = $('partners').style.left=='' ? 2 : ((parseInt($('partners').getStyle('left').replace('px',''))*(-1))/250)-1;

    if(num_pict<0){var currLeft =(5*250*(-1)); $('partners').setStyle('left', currLeft+'px');num_pict=4;}
    var curr_val = (num_pict*250*(-1));
    var myFx = new Fx.Tween($('partners'),{duration:300,transition: Fx.Transitions.linear});
    myFx.start('left', curr_val+'px');
}

function countTime(){
    $clear(timer1);
    timer1 = showNextPicture.periodical(5000);
}

function showNextBanner(){
    var all_pict = $$('#banners .banner');
    var num_pict = $('banners').style.left=='' ? 2 : ((parseInt($('banners').getStyle('left').replace('px',''))*(-1))/684)+1;

    if(all_pict.length - num_pict<1){var currLeft =(684*(-1)); $('banners').setStyle('left', currLeft+'px');num_pict=1;}
    var curr_val = (num_pict*684*(-1));
    var myFx = new Fx.Tween($('banners'),{duration:300,transition: Fx.Transitions.linear});
    myFx.start('left', curr_val+'px');
}

function countBannerTime(){
    $clear(timer_banner);
    timer_banner = showNextBanner.periodical(5000);
}

var timer_banner;

window.addEvent('domready', function(){
    countTime();
	countBannerTime();
});

var numPict = 1;
function showPhotoZoom(num_photo){	
	numPict = num_photo;
	$$('#galZoomImage img').each (function (val, i){
		if(i==num_photo-1){val.setStyle('display', '');
		}else{val.setStyle('display', 'none');}	
	});	
	$$('#galZoomImagesNavi a.numPict').each (function (val, i){
		if(i==num_photo-1){val.className = 'numPict current';
		}else{val.className = 'numPict';}
	});	
}
function showPhotoZoomPrev(){
	var num = numPict-1;
	if(num>0){showPhotoZoom(num);}
}
function showPhotoZoomNext(){
	var num = numPict+1;
	var max = $$('#galZoomImage img').length;
	if(num<=max){showPhotoZoom(num);}
}

function zoomGallery(num){	
	numPict = num;
	//var mainH = $('pageBox').offsetHeight;
	//$('zoomBox').setStyle('height', mainH+'px');
	//$('zoomBox').setStyle('display', '');	
	$('galZoom').setStyle('display', '');
	
	var zoomH = $('galZoom').offsetHeight;
	zoomH+=155;
	var contentH = $('content').offsetHeight;	
	if(zoomH>contentH){
		zoomH = mainH+(zoomH-contentH);
		$('zoomBox').setStyle('height', zoomH+'px');
	}
	$$('#galZoomImage img').each (function (val, i){
		if(i==num-1){val.setStyle('display', '');
		}else{val.setStyle('display', 'none');}
	});	
	$$('#galZoomImagesNavi a.numPict').each (function (val, i){
		if(i==num-1){val.className = 'numPict current';
		}else{val.className = 'numPict';}
	});
}
