document.root_folder = '';

function setvisibility(id, parent)
{
    $('#'+id).toggle();
//	if(id != null) {
//		if(document.getElementById(id).style.display!='none')
//			{
//				document.getElementById(id).style.display='none';
//				if(parent!=null)
//				    parent.style.backgroundPosition='right 0px;';
//		    }
//	    else
//		{
//			document.getElementById(id).style.display='block';
//			if(parent!=null)
//				    parent.style.backgroundPosition='right -31px;';
//		}
//	}
}


function trySendComment( id, title ) {
	var ajax = new myAjax();
	ajax.action = 'trySendComment';
	ajax.post( 'title='+title );
	
}

function togglePhoto( linker ) {
	get( 'ph_main' ).src = linker;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}




function saveNewPassword() {
	var op = get( 'old_pass' ).value;
	var np = get( 'new_pass' ).value;
	var npr = get( 'new_pass_repeat' ).value;
	var ajax = new myAjax();
	ajax.action = 'saveNewPassword';
	ajax.post( 'op='+op+'&np='+np+'&npr='+npr );
	ajax.onLoad = function() {
		var d = get( 'passwordMessage' );
		switch( this.response ) {
			case 'ok':
				putHtml( d, 'Zapisano nowe hasło' );
				break;
			case 'not_empty':
				putHtml( d, 'Hasło nie może być puste' );
				break;
			case 'bad_compare':
				putHtml( d, 'Hasło nie zgadza się z powtórzeniem hasła' );
				break;
			case 'bad_pass':
				putHtml( d, 'Stare hasło jest nieprawidłowe' );
				break;
			default:
				putHtml( d, this.response );
				break;
		}
	}
}

function searcher( target ) {
	var t = getSearch( target );
	if( t.length < 3 ) {
		alert( 'Wyszukiwany tekst musi mieć conajmniej 3 znaki' );
	} else {
		document.location = '/szukaj/'+t;//+'/kategoria/'+o;
	}
}

function searchCurrent( target, linker ) {
	var t = getSearch( target );
	if( t.length < 3 ) {
		alert( 'Wyszukiwany tekst musi mieć conajmniej 3 znaki' );
	} else {
		var h = linker;
		var len = h.length;
		var ls = h.substr( len - 1, 1 );
		if( ls == '/' ) {
			h = h.substr( 0, len - 1 );
		}
		document.location.href = h + '/szukaj/'+t;
	}
}

function getSearch( target ) {
	get( target ).value = trim( getValue( target ) );
	return getValue( target ).split( ' ' ).join( '+' );
}

function publicLogin() {
	var l 	= getValue( 'public_login' );
	var p	= getValue( 'public_password' );
	var g = getRadioValueByName( 'save_pass' );
//	get( 'loginMessage' ).value = '';
	var ajax = new myAjax();
	var pstr = 'login='+l+'&pass='+p+'&save_pass='+g+'&cn=Client';
	ajax.action = 'publicLogin';
//	ajax.post ( pstr, 'loginMessage' );
	ajax.post ( pstr );
	ajax.onLoad = function() {
		if( this.response == 'ok' ) {
			document.location.reload();
		} else {
			alert( this.response );
		}
	}
}

function validateEmail( email ) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if( reg.test( email ) == false ) {
      return false;
   }
   return true;
}

function setCookie(c_name, c_value) {
	time = (2*1000*60*60);
	var waznosc=new Date();
	waznosc.setTime(waznosc.getTime()+time);
	document.cookie = c_name+"="+escape(c_value)+";expires="+waznosc.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));
		}
		else
		    return null;
	}
	else {
		return null;
	}
}

$(document).ready(function(){

    $(".pl-homebox-in").stop().animate({"opacity": "0.8"}, "fast");

    $(".hover").hover(
        function() {
            $(this).stop().animate({"opacity": "1"}, "fast").addClass('hover');
            },
        function() {
            $(this).stop().animate({"opacity": "0.8"}, "fast").removeClass('hover');
    });
});
