// Skin Specific JS goes here. The jQuery library has already been loaded by the core templates. So if you use jQuery, you are ready to go.

function makeSublist(parent,child,isSubselectOptional,childVal)
{
    $j("body").append("<select style='display:none' id='"+parent+child+"'></select>");
    $j('#'+parent+child).html($j("#"+child+" option"));

//find the the title of the selected option in the list of parent
    var parentValue = $j('#'+parent+' :selected').attr('title');
    var test = $j('#'+child).html($j("#"+parent+child+" .sub_"+parentValue).clone());

    childVal = (typeof childVal == "undefined")? "" : childVal ;
    $j("#"+child).val(childVal).attr('selected','selected');

    $j('#'+parent).change(function(){
	var parentValue = $j('#'+parent+' :selected').attr('title');
	$j('#'+child).html($j("#"+parent+child+" .sub_"+parentValue).clone());
	if(isSubselectOptional) $j('#'+child).prepend("<option value='none' selected='selected'> -- Select -- </option>");
	$j('#'+child).trigger("change");
	$j('#'+child).focus();
    });
}


/*
 * 
 * jFontSizer Plugin
 * Written by fluidByte - http://www.fluidbyte.net
 * 
 * 
 */

jQuery.fn.jfontsizer = function(o) {

	// Cookie functions
	function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
	
	function getCookie(c_name){
	if (document.cookie.length>0){
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1){
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return "";
	}
	// Defaults
	var o = jQuery.extend( {
		applyTo: 'body',
		changesmall: '2',
		changelarge: '2',
		expire: 30
	},o);
	
	var s = '';
	var m = '';
	var l = '';
	
	// Current
	var c = 'fs_sml';
	
	// Check cookie  
	if (getCookie('fsizer') != "") {
		var c = getCookie('fsizer');
		switch (c) {
			case 'fs_sml':
				s = 'fsactive';
			$j(o.applyTo).css('font-size','1em');
				break;
			case 'fs_med':
				m = 'fsactive';
			$j(o.applyTo).css('font-size','1'+o.changesmall+'em');
				break;
			case 'fs_lrg':
				l = 'fsactive';
			$j(o.applyTo).css('font-size','1.'+o.changelarge+'em');
				break;
		}
	}
	else {
		m = "fsactive";
	}
	
	// Create font-chooser box
	$j(this).html('<div class="fsizer"><a id="fs_sml" class="'+s+'">A</a><a id="fs_med" class="'+m+'">A</a><a id="fs_lrg" class="'+l+'">A</a><br style="clear: both" /></div>');
	
	
	$j('.fsizer a').click(function(){
	
		var t = $j(this).attr('id');
		
		setCookie('fsizer',t,o.expire);
		
		$j('.fsizer a').removeClass('fsactive');
		$j(this).addClass('fsactive');
		
		var f = $j(o.applyTo).css('font-size');	
		
		switch(t){
			case 'fs_sml':
			    $j(o.applyTo).css('font-size','1em');
				break;
			case 'fs_med':
				$j(o.applyTo).css('font-size','1.'+o.changesmall+'em');
				break;
			case 'fs_lrg':
				$j(o.applyTo).css('font-size','1.'+o.changelarge+'em');
				break;
		}	
	});
};

$j(document).ready(function()
{
    makeSublist('tx-srfeuserregister-pi1-city','tx-srfeuserregister-pi1-zone', false, '');
    makeSublist('tx-srfeuserregister-pi1-mrc','tx-srfeuserregister-pi1-city', false, 'Rivière-du-loup');

	$j('#fontsizer').jfontsizer({
		applyTo: '#contentBlock-1',
		changesmall: '2',
		changelarge: '4',
		expire: 30
	  });
});

