function rn(_s){var _t="";for(_i=0;_i<_s.length;_i++){if(_s.charCodeAt(_i)!=13&&_s.charCodeAt(_i)!=10)
_t+=_s.charAt(_i);}
return _t;}
function associativeArrayLength(array)
{length=0;for(var object in array){length++;}
return length;}
function LTrim(value){if(value){var re=/\s*((\S+\s*)*)/;return value.replace(re,"$1");}
return value;}
function RTrim(value){if(value){var re=/((\s*\S+)*)\s*/;return value.replace(re,"$1");}
return value;}
function trim(value){return LTrim(RTrim(value));}
function centerize(width,elem){var myWidth=0,myHeight=0;if(typeof(window.innerWidth)=='number'){myWidth=window.innerWidth;myHeight=window.innerHeight;}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){myWidth=document.documentElement.clientWidth;myHeight=document.documentElement.clientHeight;}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){myWidth=document.body.clientWidth;myHeight=document.body.clientHeight;}
var style=(myWidth-width)/2+"px";jQuery("#"+elem).attr("style","left:"+style+"; top:20px;");}
function getCenterizePosition(width,height,elem){var myWidth=0,myHeight=0;if(typeof(window.innerWidth)=='number'){myWidth=window.innerWidth;myHeight=window.innerHeight;}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){myWidth=document.documentElement.clientWidth;myHeight=document.documentElement.clientHeight;}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){myWidth=document.body.clientWidth;myHeight=document.body.clientHeight;}
return[(myWidth-width)/2,(myHeight-height)/2];}
function changeIconScr(object,src){var imgObj=object.getElementsByTagName("img")[0];imgObj.src=src;return false;}
function jsstr(s){var str=new String(s);str=str.replace(/\\/g,'\\\\');str=str.replace(/\'/g,'\\\'');str=str.replace(/\"/g,'\\\"');str=str.replace(/\0/g,'\\\0');str=str.replace(/\r\n/g,'');str=str.replace(/\n/g,'');return str;}
function urldecode(str){var histogram={},histogram_r={},code=0,str_tmp=[];var ret=str.toString();histogram['!']='%21';histogram['%20']='+';for(replace in histogram){search=histogram[replace];tmp_arr=ret.split(search);ret=tmp_arr.join(replace);}
ret=decodeURIComponent(ret);return ret;}

function logout() {
	jQuery('#loginCMD').attr('value','logout');
	jQuery('#loginFormId').attr('value','0');
	jQuery('#startLoginProcess').prepend("<input type='hidden' name='logintype' value='logout'>");
	jQuery('#startLoginProcess').prepend("<input type='hidden' name='pid' value='4'>");
	jQuery('#startLoginProcess').prepend("<input type='hidden' name='no_cache' value='1'>");
	jQuery('#startLoginProcess').submit();
}
function myAccountLogOut() {
	jQuery('#startRegistrationProcess').prepend("<input type='hidden' name='isLoggedIn' value='1'>");
	jQuery('#startRegistrationProcess').prepend("<input type='hidden' name='FirstCall' value='1'>");
	jQuery('#startRegistrationProcess').prepend("<input type='hidden' name='no_cache' value='1'>");
	jQuery('#startRegistrationProcess').submit();
}
function myAccountLogIn() {													
	jQuery('#startRegistrationProcess').prepend("<input type='hidden' name='FirstCall' value='1'>");
	//document.getElementById('startRegistrationProcess').submit();								
	document.forms['startRegistrationProcess'].submit();								
}
function switchPeriodTabs(current, swt, additional) {
	var addClass = "clubiContent2 ";
	if (additional == 'Haeutimat') {
		addClass = "";
	}
	switch(swt) {
		case 'viikko':
			jQuery("#"+additional+"link_viikko").css("font-weight", "bold");
			jQuery("#"+additional+"link_kuukausi").css("font-weight", "normal");
			jQuery("#"+additional+"link_vuosi").css("font-weight", "normal");
			jQuery("#"+additional+"viikko").attr("class",jQuery.trim(addClass));
			jQuery("#"+additional+"kuukausi").attr("class",addClass+"switch");
			jQuery("#"+additional+"vuosi").attr("class",addClass+"switch");
			break;
		case 'kuukausi':
			jQuery("#"+additional+"link_viikko").css("font-weight", "normal");
			jQuery("#"+additional+"link_kuukausi").css("font-weight", "bold");
			jQuery("#"+additional+"link_vuosi").css("font-weight", "normal");
			jQuery("#"+additional+"viikko").attr("class",addClass+"switch");
			jQuery("#"+additional+"kuukausi").attr("class",jQuery.trim(addClass));
			jQuery("#"+additional+"vuosi").attr("class","clubiContent2 switch");
			break;
		case 'vuosi':
			jQuery("#"+additional+"link_viikko").css("font-weight", "normal");
			jQuery("#"+additional+"link_kuukausi").css("font-weight", "normal");
			jQuery("#"+additional+"link_vuosi").css("font-weight", "bold");
			jQuery("#"+additional+"viikko").attr("class",addClass+"switch");
			jQuery("#"+additional+"kuukausi").attr("class",addClass+"switch");
			jQuery("#"+additional+"vuosi").attr("class",jQuery.trim(addClass));
			break;
			
	}
}

function loadPicturesAndMedia(Bodytype, Manufacturer, Model, model_uid, year) {
	jQuery("#loadPicturesAndMedia").find("input[name='BODYTYPE_ID']").attr("value", Bodytype);
	jQuery("#loadPicturesAndMedia").find("input[name='Manufacturer']").attr("value", Manufacturer);
	jQuery("#loadPicturesAndMedia").find("input[name='model']").attr("value", model_uid);
	jQuery("#loadPicturesAndMedia").find("input[name='Model']").attr("value", Model);
	jQuery("#loadPicturesAndMedia").find("input[name='year']").attr("value", year);
	jQuery("#loadPicturesAndMedia").submit();
}

/**
* get the brands on the homepage
*
*/
function changeBrandsList(year) {
	
	jQuery.post("index.php?id="+pageId+"&type=226", "year="+year, function (result){
		jQuery("#brandsList").html(result);
		jQuery("#brandsList").attr("style","height:245px;");
	});
}

function changeYearOnLinks(linkObject, containerID) {
	var year = linkObject.value;
	
	changeBrandsList(year);
	
	// get all a links from the container
	jQuery("#"+containerID+" .carsBox").find("a").each(function(){
		var hr = jQuery(this).attr("href");
		hr = hr.split("year=");
		var yearValue = hr[1].split("&");
		
		jQuery(this).attr("href", hr[0]+"year="+year+"&"+yearValue[1]);
	});
}

function BodytypesCreateDelete(key, containerId) {
	var container = jQuery("#"+containerId);
	var link = jQuery("#link_"+key);
	if (link.attr("class") == 'active') {
		jQuery("#input_"+key).remove();
		link.removeAttr("class");
	} else {
		container.append("<input type='hidden' name='bodytypes[]' value='"+key+"' id='input_"+key+"' />");
		link.attr("class", "active");
	}
}

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
	   myfield.form.submit();
	   return false;
	   }
	else
	   return true;
}

function isValidEmail(email) {
	
	var filter = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
	if (filter.test(email)) {
		return true;
	}
	return false;
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

	return pattern.test(emailAddress);
}