//begin add functions to execute
addFunction('toggleLoginBox', "'topBarLoginBox'");
addFunction('submitAfterChangeSelectCatalogue', "null");
addFunction('submitAfterChangeSelectTypes', "null");
addFunction('removeElements', "null");
addFunction('openNewWindow', "null");
addFunction('legendShowHide', "null");
addFunction('confirmDelete', "null");
addFunction('confirmDeleteCMS', "null");
addFunction('confirmClear', "null");

addFunction('clickHomePL', "null");


//addFunction('submitAfterClick', "null");
//end add function to execute

/*Usuwa wszystkie elementy ktore maja klase o nazwie remove-element*/
/*za pomoca css-a sa one ukrywane zeby nie pokazywac ich uzytkownikom bez js-a*/
function removeElements() {
  $("*.remove-element").remove();
  return false;
}
/*przeladuj formularz po wyborze selec-ta katalogu*/
function submitAfterChangeSelectCatalogue() {
  $('select.catalogue').change( function () {
    $("form.submit").submit();
  });
}
function submitAfterChangeSelectTypes() {
  $('#types').change( function () {
    $("form.submit").submit();
  });
}
//function submitAfterClick() {
//  $(".click-submit").click( function () {
//    $("form.submit").submit();
//  });
//}
function hiddenLoginForm() {
  $('#topBarLoginBox').hide();
}
function toggleLoginBox(id) {
  $("#topBarSignupLoginLink").click(function () {
      $("#"+id).toggle();
      return false;
  });
}
function openNewWindow() {
  $('a.new-window').click( function () {
    var url = this.href;
    var title = this.title;
    window.open(url, title, '');
    return false;
  });
}
function legendShowHide() {
  $("#legend ul").css({display:"none"});
  $('.show-hide-legend').click( function () {
    if ($("#legend ul").is(":hidden")) {
      $("#legend ul").show("slow");
    } else {
      $("#legend ul").slideUp();
    }
    return false;
  });
}
/**
 * Potwierdzenie usunięcia
 *
 */
function confirmDelete() {
  $('.confirm-delete').click( function () {
    return confirm("Potwierdź usuwanie");
  });
}
/**
 * Potwierdzenie usunięcia
 *
 */
function confirmDeleteCMS() {
  $('.confirm-delete-cms').click( function () {
    return confirm("Potwierdź usunięcie CMS'a. Usunięcie CMS'a jest równoznaczne z usunięciem Hostingu.");
  });
}
/**
 * Potwierdzenie cyszczenia
 *
 */
function confirmClear() {
  $('.confirm-clear').click( function () {
    return confirm("Potwierdź czyszczenie");
  });
}

function isURL(val){
    if (val.length == 0) { 
    	return false; 
    }
    //val = 'http://' + val;
    return /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&amp;'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&amp;'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&amp;'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&amp;'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&amp;'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(val);
}

function redirectHomePL(val){
	if(val && val != 'Sprawdź domenę') {
		var domain = val;
		$("div#domain-availability-info").html('<a href="https://home.pl/enter/promo-prv-search/register/domain?names=' + domain + '&send_services&utm_source=prv&utm_medium=prv-search&utm_campaign=prv-search&utm_content=20110103_prv-search" rel="nofollow" target="_blank" id="clickHome"><span style="color:#3B3131;">Bezpłatna rejestracja polskich domen <b style="color:#FF0000;">.pl</b> odbywa się w serwisie naszego partnera - za pośrednictwem strony</span><span style="color:#2581C8"> www.home.pl </span><span style="color:#3B3131;">.</span></a>');
		window.open('https://home.pl/enter/promo-prv-search/register/domain?names=' + domain + '&send_services&utm_source=prv&utm_medium=prv-search&utm_campaign=prv-search&utm_content=20110103_prv-search');
	} else {
		var domain = '';
		$("div#domain-availability-info").html('Niepoprawna nazwa domeny.');
	}
	$("div.box-im-domain input#ok").show();
}

function clickHomePL(){
	$('a#clickHome').click( function () {
		var val = $("input#domain-available-input").val();
		if(val && val != 'Sprawdź domenę') {
			window.open('https://home.pl/enter/promo-prv-search/register/domain?names=' + val + '&send_services&utm_source=prv&utm_medium=prv-search&utm_campaign=prv-search&utm_content=20110103_prv-search');
			return false;
		} else {
			return true;
		}
	});
}

function prvExplode (delimiter, string, limit) {
    // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/explode    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
     var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||        typeof arguments[1] == 'undefined' ) {
        return null;
    }
 
    if ( delimiter === '' ||        delimiter === false ||
        delimiter === null ) {
        return false;
    }
     if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' ) {
        return emptyArray;    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;    }
}

function isArray(obj) {
    return obj.constructor == Array;
}
