ie=false;
nn=false;
if(document.all) ie = true;
if(document.layers) nn = true;
function hideByID(id){
	var triger;	
	triger = document.getElementById(id).style.display;
	if(triger == 'block'){
		document.getElementById(id).style.display = 'none';
	}else{
		document.getElementById(id).style.display = 'block';
	}
};
function Confirmation(URL, DIR){
  if (confirm("Really delete this "+DIR+"?\n"))
  {location = String(URL);}
  else{}//Do nothing
};
function ConfirmationAjax(URL, DIR){
	if (confirm(DIR+"\n")){
		ajaxpack.getAjaxRequest(URL, "", processGetPost, "txt");
	}else{}//Do nothing
};
function processGetPost(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt"){
	var myArray = myajax.responseText.split('_');
	if(myArray[0]==1){
		var elToHide = document.getElementById(myArray[1]);
		if(typeof(elToHide)=='undefined'||elToHide==null){
			location.reload();
		}else{
			elToHide.style.display = 'none';
		}
	}
	alert(myArray[2])
}else{
	alert(myajax.responseXML)
}
}
}
}
function imgTextAjax(imgId){
	var imgDes = document.getElementById(("imgText"+imgId)).innerHTML;
	imgDes = imgDes.replace("<br>","");
	imgDes = imgDes.replace("<br>","");
	var newText = prompt("Edit text", imgDes);
	if (newText){
		postStr = "imgId="+imgId+"&imgText=" + encodeURIComponent(newText);
		ajaxpack.getAjaxRequest("/webinac/images.php", postStr, callbackImgText, "txt");
	}else{}//Do nothing
};
function callbackImgText(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt"){
	var myArray = myajax.responseText.split('_');
	if(myArray[0]==1){
		document.getElementById(("imgText"+myArray[1])).innerHTML = myArray[2];
	}
	alert(myArray[3]);
}else{
	alert(myajax.responseXML)
}
}
}
};
function imgRotateAjax(imgId,degrees){
	postStr = "imgId="+imgId+"&rotate=" + encodeURIComponent(degrees);
	ajaxpack.getAjaxRequest("/webinac/images.php", postStr, callbackImgRotate, "txt");
};
function callbackImgRotate(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt"){
	var myArray = myajax.responseText.split('_');
	if(myArray[0]==1){
		var img = document.getElementById(("in"+myArray[1]));
		document.getElementById(("in"+myArray[1])).src = "/in"+myArray[1]+"?noCache="+new Date().getTime();
		document.getElementById(("is"+myArray[1])).src = "/is"+myArray[1]+"?noCache="+new Date().getTime();
	}
}else{
	alert(myajax.responseXML)
}
}
}
};
function docMoveAt(parID,docId,postId,conf){
	postStr = "parent="+parID+"&srcDoc="+docId+"&moveAt=" + postId;
	if(conf==undefined||conf==''){
	}else{
		var params = '';
		for (i in conf) {		
			params = params+i+'='+conf[i]+'&';
		}
		postStr = postStr+'&'+params.substr(0,params.length-1);
	}
	//alert('/webinac/ajaxHelper.php?'+postStr);
	ajaxpack.getAjaxRequest("/webinac/ajaxHelper.php", postStr, callbackDocMoveAt, "txt");
};
function callbackDocMoveAt(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt"){
	var myArray = myajax.responseText.split('_');
	if(myArray[0]==1){
		var img = document.getElementById(("in"+myArray[1]));
		document.getElementById(("in"+myArray[1])).src = "/in"+myArray[1]+"?noCache="+new Date().getTime();
		document.getElementById(("is"+myArray[1])).src = "/is"+myArray[1]+"?noCache="+new Date().getTime();
	}
}else{
	alert(myajax.responseXML)
}
}
}
};
function setCookie(name, value, expires, domain, secure){
 var curCookie = name + "=" + escape(value) +
   ((expires) ? "; expires=" + expires.toGMTString() : "") +
   "; path= / "+
   ((domain) ? "; domain=" + domain : "") +
   ((secure) ? "; secure" : "");
   
   //var curCookie = new Array();
   //curCookie[name]= value;

 document.cookie = curCookie;
};

function Set_Cookie( name, value, expires, path, domain, secure ){
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
};
// this function gets the cookie, if it exists
function Get_Cookie( name ){
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
		( name != document.cookie.substring( 0, name.length ) ) )
		{
			return null;
	}
	if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ";", len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
};
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
};
oldColor ="";
function changeBG(obj,newColor){

	var curColor = obj.style.backgroundColor;
	if (newColor == ""){
		obj.style.backgroundColor = this.oldColor;
	}else{
		this.oldColor = obj.style.backgroundColor;
		obj.style.backgroundColor = newColor;
	}	
}
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}
function getQuerystring(key, default_){
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs==""||qs==null){regex.exec(window.location);}
  if(qs == null)
    return default_;
  else
    return qs[1];
}
function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}
// Adds event to window.onload without overwriting currently 
// assigned onload functions.
function addLoadEvent(func){
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
    {
        window.onload = func;
    } 
    else 
    {
        window.onload = function()
        {
            oldonload();
            func();
        }
    }
}
function addSubmitEvent(formEl,func){
    if(formEl){
		if(formEl&&formEl.onsubmit){var oldsubmit = formEl.onsubmit;}
    	if (formEl && typeof formEl.onsubmit != 'function'){
        	formEl.onsubmit = func();
    	}else{
        	formEl.onsubmit = function(){
        		func();
        		oldsubmit();
        	}
    	}
    }else{
    	return false;
    }
}
if(typeof Ext == 'object'){
myCommonSubmit =function(){Ext.MessageBox.show({
    msg: 'Čakajte prosím...',
    progressText: 'Ukladanie...',
    width:300,
    wait:true,
    waitConfig: {interval:200},
    icon:'ext-mb-download', //custom class in msg-box.html
    animEl: 'mb7'
});}
	addSubmitEvent(document.forms['cat'],myCommonSubmit);
}
function addToBasket(unid,conf){
	if(unid==undefined){
	}
	else{
		if(document.getElementById("isUserLogged").value == 1||document.getElementById("isUserLogged").value == 0){
			var url = '';
			if(conf==undefined){
			}else{
				for (i in conf) {
					
					url = url+i+'_'+conf[i]+'-';
				}
				url = '&param='+url.substr(0,url.length-1);
			}
			url = 'a=add&unid='+unid+(url);
			ajaxpack.getAjaxRequest("/webinac/ajaxBasket.php", url, callbackAddToBasket, "txt");
			//alert(url);			
		}else{
			setCookie(unid+'='+unid, '1');location.reload();	
		}
	}
}
function removeFromBasket(unid){
	var field = "basket[items]["+unid+"][value]";
	document.getElementById(field).value = '0';
	document.getElementById('recount').click();
}
function callbackAddToBasket(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt"){
	var myArray = myajax.responseText.split('_');
	if(myArray[0]==1){
		//sem treba dat ajaxovy colback ...
		location.reload();
	}
}else{
	alert(myajax.responseXML)
}
}
}
};
function showOrders(){
	ajaxpage('/webinac/viewAjaxBasket.php?id=cat_order-page_0-sort_name_internal-asc_1&#38;menu={menuFull}','td_main');
	return false;
};
function cloaseEdit(newURI){
	if(parent.overlieWin){
		parent.overlieWin.close();
	}else{
		window.location = newURI;
	}
};
function getCurrentDate(){
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	return (day + "." + month + "." + year);
};
function getNextMonth(){
	var currentTime = new Date();
	var month = currentTime.getMonth() + 2;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	return (day + "." + month + "." + year);
};
function isNewDoc(){
	var docIdItem = document.getElementById('core_id');
	var returnVal = false;
	if(docIdItem){
		if(docIdItem.value==0){
			returnVal =  ture;
		}
	}
	return returnVal;
};
