//waermeplus.js
//alert($.cookie('viewbyplz_plz'));

var plz_ngw = [46519,46499,47495,46514,47665,46562,46509,46419,47661,47623,47624,47625,47626,47627,47509,47638,47589,47652,52441];

var versorger = 'GW';

jQuery().ready(function(){
	CheckPLZ();
	var logo = $('#logo img');
	//console.debug();
	//versorger = $.cookie('logo');
	jQuery('a').wp_links();
	if($.cookie('logo')=='WESTFALICA'){
		jQuery('a').westfalica_links();
		//alert(jQuery('#headerimg').attr('src'));
		
		jQuery('#headerimg').attr('src','fileadmin/templates/img/waerme_plus_header_ohne.jpg');

		//waerme_plus_header_ohne.jpg
	}
	
	

	if(logo[0])
	switch(versorger){
		case 'NGW':
			//logo[0].src = 'http://blackquad/waermeplus/fileadmin/templates/img/logo_ngw.gif';
			logo[0].src = logo[0].src.replace('logo.gif','logo_ngw.gif')
		break;

		default:
			//logo[0].src = 'http://blackquad/waermeplus/fileadmin/templates/img/logo.gif';
		break;

	}





});



function CheckPLZ(){

	versorger = $.cookie('logo');
	
	if(versorger == 'WESTFALICA' ){
		versorger = 'west';
	}
	if(versorger=='GELSENWASSER')
		versorger = 'gw';
	/*


	var plz = $.cookie('viewbyplz_plz');
	var i=0;
	for(var i=0; i < plz_ngw.length; i++ ){
		if(plz== plz_ngw[i]){
			versorger = 'NGW';
			return true;
		}
	}

	
	switch(plz){
		case '41564':
			versorger = 'KAARST';
		break;
	
		
		case'46483':
		case'46485':
		case'46487':
			versorger = 'WESEL';
		break;
		
		case'47546':
			versorger = 'KALKAR';
		break;
	}
	
	*/

}


jQuery.fn.wp_links = function(params) {

		var options = {

			wpLinkSites : ['aktuelle_preise.html','foerderprogramme.html','shk_ansprechpartner.html','bespielrechnung.html','shk_download.html','unsere_partner.html'],/*,'ansprechpartner.html'*/
            addClass: ''

		}
		var op = jQuery.extend(options, params);
		//var $el = jQuery(this);

	return this.each(function(){
		var url = this.href;
		var urlToken = parseUri (url);
		if( IsWpLink(  urlToken.file ) ){
			var xfile = urlToken.file.replace('.html','_'+versorger.toLowerCase()+'.html');
			this.href = url.replace(urlToken.file,xfile);
		}
		
		if(urlToken.file=='startseite.html' && $.cookie('indi')=='1'){
            this.href = this.href.replace(urlToken.file,'index.php?id=92');
		}
		

        function IsWpLink(file){
            for(var a =0;a<op.wpLinkSites.length;a++)
                if(op.wpLinkSites[a]==file )
                    return true;
            return false;
        }
	});
};


jQuery.fn.westfalica_links = function(params) {

		var options = {

			wpLinkSites : ['produkte.html','preise.html','waerme_plus_basis.html','waerme_plus_komfort.html','waerme_plus_service.html','grundpreisrechner.html'],/*,'ansprechpartner.html'*/
            addClass: ''

		}
		var op = jQuery.extend(options, params);
		//var $el = jQuery(this);

	return this.each(function(){
		var url = this.href;
		var urlToken = parseUri (url);
		if( IsWpLink(  urlToken.file ) ){
			var xfile = urlToken.file.replace('.html','_west'+'.html');
			this.href = url.replace(urlToken.file,xfile);
		}
		
		if($(this).text()=='Grundpreisrechner'){
			//console.debug($(this).text());
			//$(this).text('Investitionsrechner');
			this.innerHTML = 'Investitionsrechner';
			document.title ='INVESTITIONSRECHNER';
		}
		
		if($(this).text()=='GRUNDPREISRECHNER'){
			//console.debug($(this).text());
			//$(this).text('Investitionsrechner');
			this.innerHTML = 'INVESTITIONSRECHNER';
			document.title ='INVESTITIONSRECHNER';
		}
		if($(this).text()=='Beispielrechnung'){
			//console.debug($(this).parent());
			$(this).parent().remove();
		}
		if(urlToken.file=='vom_gas_zur_waerme.html'){
			
			$(this).parent().remove();
		}
		if(urlToken.file=='tuev_siegel.html'){
            $(this).remove();
		}
		

        function IsWpLink(file){
            for(var a =0;a<op.wpLinkSites.length;a++)
                if(op.wpLinkSites[a]==file )
                    return true;
            return false;
        }
	});
};



/*
	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
*/

parseUri.options = {
    strictMode: false,
    key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
    q:   {
        name:   "queryKey",
        parser: /(?:^|&)([^&=]*)=?([^&]*)/g
    },
    parser: {
        strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
        loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
    }
};

function parseUri (str) {
    var o   = parseUri.options,
        m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
        uri = {},
        i   = 14;

    while (i--) uri[o.key[i]] = m[i] || "";

    uri[o.q.name] = {};
    uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
        if ($1) uri[o.q.name][$1] = $2;
    });

    return uri;
};
