
function newSiteAdmin(option,category,industry,country,administrative_unit,town,currency,income_range,tag,edit,sort,order,opt)
{
	if (opt == 0)
	{
		if (option == 0) {sort_value = 0;order_value = 'asc';}
		if (option == 1) {sort_value = 0;order_value = 'desc';}
		if (option == 2) {sort_value = 1;order_value = 'asc';}
		if (option == 3) {sort_value = 1;order_value = 'desc';}
		if (option == 4) {sort_value = 2;order_value = 'asc';}
		if (option == 5) {sort_value = 2;order_value = 'desc';}
		if (option == 6) {sort_value = 3;order_value = 'asc';}
		if (option == 7) {sort_value = 3;order_value = 'desc';}
		if (option == 8) {sort_value = 4;order_value = 'asc';}
		if (option == 9) {sort_value = 4;order_value = 'desc';}
		if (option == 10) {sort_value = 5;order_value = 'asc';}
		if (option == 11) {sort_value = 5;order_value = 'desc';}
		if (option == 12) {sort_value = 6;order_value = 'asc';}
		if (option == 13) {sort_value = 6;order_value = 'desc';}
		if (option == 14) {sort_value = 7;order_value = 'asc';}
		if (option == 15) {sort_value = 7;order_value = 'desc';}
		if (option == 16) {sort_value = 8;order_value = 'asc';}
		if (option == 17) {sort_value = 8;order_value = 'desc';}
		if (option == 18) {sort_value = 9;order_value = 'asc';}
		if (option == 19) {sort_value = 9;order_value = 'desc';}
		if (option == 20) {sort_value = 10;order_value = 'asc';}
		if (option == 21) {sort_value = 10;order_value = 'desc';}
		
		window.location = "offers_list-"+category+"-"+industry+"-"+country+"-"+administrative_unit+"-"+town+"-"+currency+"-"+income_range+"-"+tag+"-"+edit+"-0-"+sort_value+"-"+order_value+".html";
	}
	else
	{
		if (option == 0) {option_value = 10;}
		if (option == 1) {option_value = 30;}
		if (option == 2) {option_value = 50;}
		if (option == 3) {option_value = 100;}
		if (option == 4) {option_value = 250;}
		
		window.location = "offers_list-"+category+"-"+industry+"-"+country+"-"+administrative_unit+"-"+town+"-"+currency+"-"+income_range+"-"+tag+"-"+edit+"-0-"+sort+"-"+order+"-"+option_value+".html";
	}
}

function onChangeAdmin(select,category,industry,country,administrative_unit,town,currency,income_range,tag,edit,sort,order,opt)
{
	var myindex  = select.selectedIndex;
	newSiteAdmin(myindex,category,industry,country,administrative_unit,town,currency,income_range,tag,edit,sort,order,opt);
}

function newSiteAdmin2(option,category,industry,country,administrative_unit,town,currency,income_range,tag,edit,sort,order,opt)
{
	if (opt == 0)
	{
		if (option == 0) {sort_value = 0;order_value = 'asc';}
		if (option == 1) {sort_value = 0;order_value = 'desc';}
		if (option == 2) {sort_value = 1;order_value = 'asc';}
		if (option == 3) {sort_value = 1;order_value = 'desc';}
		if (option == 4) {sort_value = 2;order_value = 'asc';}
		if (option == 5) {sort_value = 2;order_value = 'desc';}
		if (option == 6) {sort_value = 3;order_value = 'asc';}
		if (option == 7) {sort_value = 3;order_value = 'desc';}
		if (option == 8) {sort_value = 4;order_value = 'asc';}
		if (option == 9) {sort_value = 4;order_value = 'desc';}
		if (option == 10) {sort_value = 5;order_value = 'asc';}
		if (option == 11) {sort_value = 5;order_value = 'desc';}
		if (option == 12) {sort_value = 6;order_value = 'asc';}
		if (option == 13) {sort_value = 6;order_value = 'desc';}
		if (option == 14) {sort_value = 7;order_value = 'asc';}
		if (option == 15) {sort_value = 7;order_value = 'desc';}
		if (option == 16) {sort_value = 8;order_value = 'asc';}
		if (option == 17) {sort_value = 8;order_value = 'desc';}
		if (option == 18) {sort_value = 9;order_value = 'asc';}
		if (option == 19) {sort_value = 9;order_value = 'desc';}
		if (option == 20) {sort_value = 10;order_value = 'asc';}
		if (option == 21) {sort_value = 10;order_value = 'desc';}
		
		window.location = "offers_promote_list-"+category+"-"+industry+"-"+country+"-"+administrative_unit+"-"+town+"-"+currency+"-"+income_range+"-"+tag+"-"+edit+"-0-"+sort_value+"-"+order_value+".html";
	}
	else
	{
		if (option == 0) {option_value = 10;}
		if (option == 1) {option_value = 30;}
		if (option == 2) {option_value = 50;}
		if (option == 3) {option_value = 100;}
		if (option == 4) {option_value = 250;}
		
		window.location = "offers_promote_list-"+category+"-"+industry+"-"+country+"-"+administrative_unit+"-"+town+"-"+currency+"-"+income_range+"-"+tag+"-"+edit+"-0-"+sort+"-"+order+"-"+option_value+".html";
	}
}

function onChangeAdmin2(select,category,industry,country,administrative_unit,town,currency,income_range,tag,edit,sort,order,opt)
{
	var myindex  = select.selectedIndex;
	newSiteAdmin2(myindex,category,industry,country,administrative_unit,town,currency,income_range,tag,edit,sort,order,opt);
}

function show_hide_offer_file(current_value,offer_photo) 
{ 
	if (current_value == 1)
	{
		document.getElementById(offer_photo+"_from_disc").style.display = 'block';
		document.getElementById(offer_photo+"_from_web").style.display = 'none';
	}
	else
	{
		document.getElementById(offer_photo+"_from_disc").style.display = 'none';
		document.getElementById(offer_photo+"_from_web").style.display = 'block';
	}
}

function show_logo_type(select)
{
	var myindex  = select.value;
	
	if (myindex == 5 || myindex == 8)
	{
		document.getElementById("logo_type").style.display = "inline";
		document.getElementById("offer_photos").style.display = "none";
	}
	else
	{
		document.getElementById("logo_type").style.display = "none";
		document.getElementById("offer_photos").style.display = "inline";
	}
	if (myindex == 2)
	{
		document.getElementById("offer_area_box").style.display = "inline";
	}
	else
	{
		document.getElementById("offer_area_box").style.display = "none";
	}
}

function show_logo_type2(select)
{
	if (select == 2)
	{
		document.getElementById("logo_type").style.display = "inline";
		document.getElementById("offer_photos").style.display = "none";
	}
	else
	{
		document.getElementById("logo_type").style.display = "none";
		document.getElementById("offer_photos").style.display = "inline";
	}
	if (select == 4)
	{
		document.getElementById("offer_area_box").style.display = "inline";
	}
	else
	{
		document.getElementById("offer_area_box").style.display = "none";
	}
}

function SignLimit(tab,max)
{
var oSpan = document.getElementById( 'counter' );
oSpan.innerHTML = ( ( tab.value.length ));
if ( tab.value.length == max )
{
input = tab.value.substring(0,max - 1);
tab.value = input;
}
}

function SignLimit2(tab,max)
{
var oSpan = document.getElementById( 'counter2' );
oSpan.innerHTML = ( ( tab.value.length ) ) +'/' + max;
if ( tab.value.length == max )
{
input = tab.value.substring(0,max - 1);
tab.value = input;
}
}

function validate_form()
{
	description(document.getElementById('offer_description'));
	offer_name = document.getElementById('offer_name');
	category_id = document.getElementById('category_id');
	kraj = document.getElementById('kraj');
	country_id_select = document.getElementById('country_id_select');
        accept = document.getElementById('accept');
	offer_contact_person = document.getElementById('offer_contact_person');
	offer_contact_email = document.getElementById('offer_contact_email');
	offer_contact_phone = document.getElementById('offer_contact_phone');
	
	error = 0;
	offer_name_length = document.add_offer.offer_name.value.length;
	offer_description_length = document.add_offer.offer_description.value.length;
	
	if (document.getElementById('description_info').value == '1')
	{
		error_name = 'Brak opisu';
		error = 1;
	}
	else if(offer_description_length < 200) {
			error_name = 'Zbyt krótki opis';
			error = 1;
	}
	else if(!accept.checked){
		error_name = 'Nie zaakceptowałeś regulaminu';
		error = 1;
	}
	else if(offer_name.value == '' || offer_name.value.length < 3) {
		error = 1;
		error_name = 'Nie podano tytułu oferty lub jest on krótszy niż 3 znaki.';
	}
	else if(category_id.value == 0) {
		error = 1;
		error_name = 'Nie wybrano kategorii';
	}
	else if(kraj.value == 0) {
		error = 1;
		error_name = 'Nie wybrano branży';
	}
	else if(country_id_select.value == 0) {
		error = 1;
		error_name = 'Nie wybrano kraju';
	}
		
	if (error == 0)
		//document.add_offer.submit_button.disabled = false;
		return true;
	else
	{
		//document.add_offer.submit_button.disabled = true;
		window.alert(error_name);
		return false;
	}
}

function validate_form2()
{
	description(document.getElementById('offer_description'));
	offer_name = document.getElementById('offer_name');
	category_id = document.getElementById('category_id');
	kraj = document.getElementById('kraj');
	country_id_select = document.getElementById('country_id_select');
	offer_contact_person = document.getElementById('offer_contact_person');
	offer_contact_email = document.getElementById('offer_contact_email');
	offer_contact_phone = document.getElementById('offer_contact_phone');
	
	error = 0;
	offer_name_length = document.add_offer.offer_name.value.length;
	offer_description_length = document.add_offer.offer_description.value.length;
	
	if (document.getElementById('description_info').value == '1')
	{
		error_name = 'Brak opisu';
		error = 1;
	}
	else if(offer_description_length < 120) {
			error_name = 'Zbyt krótki opis';
			error = 1;
	}

	else if(offer_name.value == '' || offer_name.value.length < 3) {
		error = 1;
		error_name = 'Nie podano tytułu oferty lub jest on krótszy niż 3 znaki.';
	}
	else if(category_id.value == 0) {
		error = 1;
		error_name = 'Nie wybrano kategorii';
	}
	else if(kraj.value == 0) {
		error = 1;
		error_name = 'Nie wybrano branży';
	}
	else if(country_id_select.value == 0) {
		error = 1;
		error_name = 'Nie wybrano kraju';
	}
		
	if (error == 0)
		//document.add_offer.submit_button.disabled = false;
		return true;
	else
	{
		//document.add_offer.submit_button.disabled = true;
		window.alert(error_name);
		return false;
	}
}

function new_window(theURL,width,height)
{
window.open(theURL,'powiekszenie','height='+height+',width='+width+',menubar=0,resizable=0,scrollbars=yes,status=0,titlebar=0,toolbar=0,right=0,bottom=0')
}

function description(currentId)
{
    var default_desc = "Opisz swoją ofertę, podając szczegóły: \n"+
    "Dłuższy i dokładniejszy opis Twojej oferty, to \n"+
    "zdecydowanie większe zainteresowanie. \n"+
    "W opisie nie można umieszczać danych \n"+
    "kontaktowych oraz adresu strony internetowej";
    current_desc = currentId.value;
    current_desc = current_desc.replace(/(\r\n|\r|\n)/g, '\n');

    if(current_desc == default_desc) {
		currentId.value = '';
		currentId.style.color = 'black';
		document.getElementById('description_info').value = '1';
	}
	else {
		document.getElementById('description_info').value = '0';
	}
}


function send_link(data, adres) {
    error = 0;

    wiadomosc = jQuery.trim(jQuery('#send_link_dialog textarea').val())
    adresat = jQuery.trim(jQuery('#send_link_dialog input[name="adresat"]').val())
    email = jQuery.trim(jQuery('#send_link_dialog input[name="email"]').val())
    nadawca  = jQuery.trim(jQuery('#send_link_dialog input[name="nadawca"]').val())
    email_nadawcy  = jQuery.trim(jQuery('#send_link_dialog input[name="email_nadawcy"]').val())
    if(wiadomosc == '' ) {
        error = 1
        jQuery('#send_link_dialog #wiadomosc_err').show();
    }
    else{
        jQuery('#send_link_dialog #wiadomosc_err').hide();
    }
    
    if(adresat == '' ) {
        error = 1
        jQuery('#send_link_dialog #adresat_err').show();
    }
    else{
        jQuery('#send_link_dialog #adresat_err').hide();
    }

    if(email == '' ) {
        error = 1
        jQuery('#send_link_dialog #email_err').show();
    }
    else{
        jQuery('#send_link_dialog #email_err').hide();
    }

    if(nadawca == '' ) {
        error = 1
        jQuery('#send_link_dialog #nadawca_err').show();
    }
    else{
        jQuery('#send_link_dialog #nadawca_err').hide();
    }
    if(email_nadawcy == '' ) {
        error = 1
        jQuery('#send_link_dialog #email_nadawcy_err').show();
    }
    else{
        jQuery('#send_link_dialog #email_nadawcy_err').hide();
    }

    if(error == 0) {
        var ajaxRequest;
        ajaxRequest = createXMLHttpRequest();
        if(ajaxRequest === false)
            return false;
        jQuery('#send_link_dialog #send_link_loading').show();
        jQuery('#send_link_dialog #send_link_form').hide();

        ajaxRequest.open('POST', adres);
        ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-2");
    
        ajaxRequest.onreadystatechange = function() {
            if(ajaxRequest.readyState==4)
            {
                jQuery('#send_link_dialog #send_link_loading').hide();
                response = jQuery.trim(ajaxRequest.responseText);
                if(response == 'OK') {
                    jQuery('#send_link_dialog #send_link_ok').show();
                }
                else {
                    jQuery('#send_link_dialog #send_link_error').show();
                }
            }
        }

        ajaxRequest.send(data);
    }
}

function send_error_report(data, adres) {
    error = 0;

    wiadomosc = jQuery.trim(jQuery('#send_report_dialog textarea').val())
    email_nadawcy  = jQuery.trim(jQuery('#send_report_dialog input[name="email_nadawcy"]').val())

    if(wiadomosc == '' ) {
        error = 1
        jQuery('#send_report_dialog #report_wiadomosc_err').show();
    }
    else{
        jQuery('#send_report_dialog #report_wiadomosc_err').hide();
    }

    if(email_nadawcy == '' ) {
        error = 1
        jQuery('#send_report_dialog #report_email_nadawcy_err').show();
    }
    else{
        jQuery('#send_report_dialog #report_email_nadawcy_err').hide();
    }

    if(error == 0) {
        var ajaxRequest;
        ajaxRequest = createXMLHttpRequest();
        if(ajaxRequest === false)
            return false;
        jQuery('#send_report_dialog #send_report_loading').show();
        jQuery('#send_report_dialog #send_report_form').hide();

        ajaxRequest.open('POST', adres);
        ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-2");

        ajaxRequest.onreadystatechange = function() {
            if(ajaxRequest.readyState==4)
            {
                jQuery('#send_report_dialog #send_report_loading').hide();
                response = jQuery.trim(ajaxRequest.responseText);
                if(response == 'OK') {
                    jQuery('#send_report_dialog #send_report_ok').show();
                }
                else {
                    jQuery('#send_report_dialog #send_report_error').show();
                }
            }
        }

        ajaxRequest.send(data);
    }
}

