﻿// JavaScript Document
var bookmarkurl=document.location;
var bookmarktitle=document.title;

function addbookmark(){
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
} 
//funkcja pokazujaca, ukrywajaca element
function display(name,mode){
	if(document.getElementById){
		element=document.getElementById(name);
		element.style.display=mode;
	}
}
function loadDynamicPage(url,form){
	var xmlHttp;
	try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
	}catch (e){
    // Internet Explorer
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
		try{
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}catch (e){
        alert("Błąd!. Twoja przeglądarka nie osluguje obiektu XMLHttpRequest.");
        return false;
        }
      }
    }
    element=document.getElementById(form);
    element.innerHTML="Ladowanie";
    xmlHttp.onreadystatechange=function(){
    	if(xmlHttp.readyState==4){
			element.innerHTML=xmlHttp.responseText;
        }
    }
    xmlHttp.open("GET",("http://www.europolia.com/"+url),true);
    xmlHttp.send(null);
}

//prosta funkcja sprawdzajaca poprawnosc maila
function validiate_email(value){
    a_pos=value.indexOf("@");
    dot_pos=value.lastIndexOf(".");
    if(a_pos<1 || dot_pos-a_pos<2){
        return false;
    }else{
        return true;
    }
}

function goToPage(url){
    location.href=url;
}

function checkFieldsAndSend(fields,form,correct,error){
    if(document.getElementById){
        //tworzenie listy pol
        inputs=fields.split(',');
        for(i=0;i<inputs.length;i++){
            field=document.getElementById(inputs[i]);
            //sprawdzamy poprawnosc maila
            if(field.value=="" || field.value==null){
            	field.className=error;
                alert("Wypelnij wszytkie pola formularza.");
                break;
            }else{
            	field.className=correct;
			}
        }
        //jesli validacja siepowiodla
        if(i==inputs.length){
            document.getElementById(form).submit();
        }else{
            field.focus();
        }
    }
}

function checkFieldsAndSendTo(fields,form,url,correct,error){

	if(document.getElementById){
        //tworzenie listy pol
        inputs=fields.split(',');
        for(i=0;i<inputs.length;i++){
            field=document.getElementById(inputs[i]);
            //sprawdzamy poprawnosc maila
            if(field.value=="" || field.value==null){
            	field.className=error;
                alert("Wypelnij wszytkie pola formularza.");
                break;
            }else{
            	field.className=correct;
			}
        }
        //jesli validacja siepowiodla
        if(i==inputs.length){
            sendFormTo(form,url)
        }else{
            field.focus();
        }
    }
}

function checkSimpleFieldsAndSendTo(fields,form,url){
	if(document.getElementById){
        //tworzenie listy pol
        inputs=fields.split(',');
        for(i=0;i<inputs.length;i++){
            field=document.getElementById(inputs[i]);
            //sprawdzamy poprawnosc maila
            if(field.value=="" || field.value==null){
                alert("Wypelnij wszytkie pola formularza.");
                break;
        	}
        }
        //jesli validacja siepowiodla
        if(i==inputs.length){
            sendFormTo(form,url)
        }else{
            field.focus();
        }
    }
}

function validiateTextarea(textarea_name,max_chars){
	textarea=document.getElementById(textarea_name);
	if(textarea.value.length>max_chars){
		textarea.value=textarea.value.substr(0,max_chars);
		alert('Tekst był za długi, został skrócony.');
	}
}

function showTextareaState(textarea_name,max_chars,display_name){
	textarea=document.getElementById(textarea_name);
	display=document.getElementById(display_name);
	if(textarea.value.length>max_chars){
		textarea.value=textarea.value.substr(0,max_chars);
	}
	display.innerHTML="("+textarea.value.length+" z "+max_chars+")";
}

function sendFormTo(form_name,url){
	form=document.getElementById(form_name);
	form.action=url;
	form.submit();
}

function showBigImage(dir,name){
	window.open('main/show_image.php5?image_name='+name+'&image_dir='+dir,'','width=10,height=10,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes');
}

function showAdminBigImage(dir,name){
	window.open('../main/show_image.php5?image_name='+name+'&image_dir='+dir,'','width=10,height=10,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes');
}

//user

function userCategoryOnChange(sub_id){
	
	cat=document.getElementById('add_category');
	
	if(sub_id!=-1){
		url="adds_user/get_categories.php5?id="+cat.options[cat.selectedIndex].value+"&sub_id="+sub_id;
	}else{
		url="adds_user/get_categories.php5?id="+cat.options[cat.selectedIndex].value;
	}

	loadDynamicPage(url,'container');
}


