	
/*
	@autor: Petcu Mihai
	@autor: Constandachi Paul Cosmin
	@date: 21/08/2009
	@version: 1
*/	

	function mortgagesSortBy(){
		var sortBy = $('sortBy').value;
		// alert(sortBy);
		// alert($(sortBy).href);
		location.href = $(sortBy).href;
	}

	function changeCheckbox(styleId, checkboxId){
		//alert(styleId + checkboxId);
		var styleSpan = $(styleId);
		var checkbox = $(checkboxId);
		if(checkbox.disabled != true){
			//alert(styleSpan.style.backgroundPosition);
			if(checkbox.checked == true){
				checkbox.checked = false;
				styleSpan.className = "checkbox chk_unselected";
			}else{
				checkbox.checked = true;
				styleSpan.className = "checkbox chk_selected";
			}
		}
	}
	
	
	function mortgagesHideShowCalculatorElements(obj){
		var nr = obj.length;

		for(i=0;i<nr;i++){
			if (obj[i].checked){
				//alert(obj[i].value);
				if ( obj[i].value == 'current_situation_ftb'){
					$('ddlProviders').style.display = 'none';
					$('m_value').style.display = 'block';
					$('m_borrow').style.display = 'block';
					$('ddlRepaymentType').style.display = 'none';
					$('m_term').style.display = 'block';
					$('ddlStatus').style.display = 'block';
				}
				if ( obj[i].value == 'current_situation_consolidate' || obj[i].value == 'current_situation_remortgage' || obj[i].value == 'current_situation_self_build' || obj[i].value == 'current_situation_switch' || obj[i].value == 'current_situation_equity'){
					$('ddlProviders').style.display = 'block';
					$('m_value').style.display = 'block';
					$('m_borrow').style.display = 'block';
					$('ddlRepaymentType').style.display = 'none';
					$('m_term').style.display = 'block';
					$('ddlStatus').style.display = 'block';
				}
				if ( obj[i].value == 'current_situation_buy_to_let' ) {
					$('ddlProviders').style.display = 'block';
					$('m_value').style.display = 'block';
					$('m_borrow').style.display = 'block';
					$('ddlRepaymentType').style.display = 'block';
					$('ddlStatus').style.display = 'block';
					var repaymentTypeSelected = $('CalculatorDdlRepaymentType').value;
					if (repaymentTypeSelected == 'ddlInterestAndCapital'){
						$('m_term').style.display = 'block';
					} else {
						$('m_term').style.display = 'none';
					}
				}
			}
		}
		
		/*style.display = 'none';*/
	}
	
	function calculateMaxLtvAndAmount(){
		
		var aInfo = new Array();
		aInfo = getMaxLtvAndAmount();
		var maxLtv = aInfo[0];
		var maxAmount = aInfo[1];
		//maxLtv = 80;
		var mValue = $('CalculatorMValue').value;
		var mBorrow = $('CalculatorMBorrow').value;
		//alert(maxLtv + '--' + maxAmount + '' + mValue + '--' + mBorrow);
		var requestedMaxLtv = 0;
		if( mValue != null && mValue != '' ){
			
			if ( mValue > maxAmount ){
				alert('Please choose another "Value of the Property".');
				$('CalculatorMValue').value = 0;
			}
		}
		if( mValue != null && mBorrow != null &&  mValue != '' && mBorrow != '' ){
			
			requestedMaxLtv =( mBorrow * 100 ) / mValue;
			if ( requestedMaxLtv > maxLtv) {
				alert('Please choose another "Value to borrow".');
				$('CalculatorMBorrow').value = 0;
			}
		
		}
		
	}
	
	function calculateMaxLtvAndAmount2(){
		
		var aInfo = new Array();
		aInfo = getMaxLtvAndAmount();
		var maxLtv = aInfo[0];
		var maxAmount = aInfo[1];
		//maxLtv = 80;
		var mValue = $('ReCalculateMValue').value;
		var mBorrow = $('ReCalculateMBorrow').value;
		//alert(maxLtv + '--' + maxAmount + '' + mValue + '--' + mBorrow);
		var requestedMaxLtv = 0;
		if( mValue != null && mValue != '' ){
			
			if ( mValue > maxAmount ){
				alert('Please choose another "Value of the Property".');
				$('ReCalculateMValue').value = 0;
			}
		}
		if( mValue != null && mBorrow != null &&  mValue != '' && mBorrow != '' ){
			
			requestedMaxLtv =( mBorrow * 100 ) / mValue;
			if ( requestedMaxLtv > maxLtv) {
				alert('Please choose another "Value to borrow".');
				$('ReCalculateMBorrow').value = 0;
			}
		
		}
		
	}
	
	function submitForm(formName,id){
		var checkBox = $(id);
		// alert('test'+id+'||'+checkBox.disabled);
		if(checkBox.disabled != true){
			var forVar =$(formName); 
			forVar.submit();	
		}
	}
	
	function submitGet(url){
		
		window.location.href = url;
	}
	
	function simulateRadio(aAllRadioOptions, pre_span, styleId, pre_radio,checkboxId){
			
		var styleSpan = $(pre_span+styleId);
		var checkbox = $(pre_radio+checkboxId);
		var nr = 0;
		
		
		nr = aAllRadioOptions.length;
		
		for ( i=0;i<nr;i++ ) {
			name = aAllRadioOptions[i];
		
			var styleSpanI = $(pre_span+name);
			var checkboxI = $(pre_radio+name);
			
			checkboxI.checked = false;
			styleSpanI.className = "checkbox chk_unselected";
		}

		checkbox.checked = true;
		styleSpan.className = "checkbox chk_selected";
	}

	function cangeCheckbox(styleId, checkboxId){
		//alert(styleId + checkboxId);
		var styleSpan = $(styleId);
		var checkbox = $(checkboxId);
		//alert(styleSpan.style.backgroundPosition);
		if(checkbox.checked == true){
			checkbox.checked = false;
			styleSpan.className = "checkbox chk_unselected";
		}else{
			checkbox.checked = true;
			styleSpan.className = "checkbox chk_selected";
		}
	}
	
	
	
	function cangeCheckbox2(checkboxId){
		var checkbox = $(checkboxId);
		if(checkbox.checked == true){
			checkbox.checked = false;
		}else{
			checkbox.checked = true;
		}
	}
	
	function cangeCheckboxFlg(styleId){
		//var styleSpan = $(styleId);
		//var checkbox = $(styleId+'_chk');
		
		if(styleId == 'one_way'){
			$('one_way').className = "checkbox chk_selected";
			$('return_trip_chk').value = 0;
			$('return_trip').className = "checkbox chk_unselected";
			$('return_date_container').style.visibility = 'hidden';
			//Effect.Opacity('return_date_container', { from: 1.0, to: 0.1, duration: 0.5 });

		}else{
			$('one_way').className = "checkbox chk_unselected";
			$('return_trip_chk').value = 1;
			$('return_trip').className = "checkbox chk_selected";
			$('return_date_container').style.visibility = 'visible';
			//Effect.Opacity('return_date_container', { from: 0.1, to: 1.0, duration: 0.5 });
		}
	}
	
	function changeTravelTabs(tab_nr){
		for(var i=1; i<=2; i++){
			if(tab_nr == i){
				document.getElementById('results_tab_'+i+'_link').className = "compare_result_list_tabs_active";
				document.getElementById('results_tab_'+i).style.display = "block";	
			}else{
				document.getElementById('results_tab_'+i+'_link').className = "";
				document.getElementById('results_tab_'+i).style.display = "none";
			}
		}
	}
	
	function showHideCarDetails(id){
		if($('details_'+id).style.display == "none"){
//			$('details_'+id).style.display = "block";
			Effect.SlideDown('details_'+id, { duration: 0.4 });
		}else{
//			$('details_'+id).style.display = "none";
			Effect.SlideUp('details_'+id, { duration: 0.4 });
		}
	}
	
	function hideShowMortgagesForm(id) {
		if($(id).style.display == "block"){
			$(id).style.display = 'none';
			//Effect.SlideDown(id, { duration: 0.7 });
		}else{
			$(id).style.display = 'block';
			//Effect.SlideUp(id, { duration: 0.7 });
		}
	}

	function cityTipsShowMore(id) {
		var myLink = $('tiplink'+id);
		if (myLink.getAttribute('rel') == 'closed') {
			Effect.Grow('tipfull' + id, {
				direction: 'top-left',
				duration: 0.3
			});
			myLink.update(myLink.getAttribute('langclose'));
			myLink.setAttribute('rel','open');
		} else {
			Effect.Shrink('tipfull' + id, {
				direction: 'top-left',
				duration: 0.3
			});
			myLink.update(myLink.getAttribute('langopen'));
			myLink.setAttribute('rel','closed');
		}
	}
	
	function providerRateAndReview(mInput,mLi){
		document.location = '/providers/' + mLi.id;
	}
	
	
	
function groupSelector (){
	
	this.incrementor  = new Array();
	this.selector = new Array();
	
	this.addElement = function (group, chk_id, style_id){
		if (!this.selector[group]) {
			this.selector[group] = new Array();
			this.incrementor[group] = 0;
		}
		this.selector[group][this.incrementor[group]] = new Array();
		this.selector[group][this.incrementor[group]]['chk_id'] =  chk_id;
		this.selector[group][this.incrementor[group]]['style_id'] =  style_id;	
		this.incrementor[group]++;	
		
			
	}
	
	this.checker = function (group, id){
		
		var status = 0;
		var status_a = 0;
		var filtersLength = 0;
		
		for(var i=0; i< this.incrementor[group] ;i++){
			if($(this.selector[group][i]['chk_id'])){
				if($(this.selector[group][i]['chk_id']).checked == true){
					status_a++;
				}	
				if(($(this.selector[group][i]['chk_id']).checked == true && this.selector[group][i]['chk_id'] != id) || ($(this.selector[group][i]['chk_id']).checked == false && this.selector[group][i]['chk_id'] == id)){
					status++;
				}
				filtersLength++;
			}	
		}
		
		var set = false;
		if(filtersLength > 2){
			
			if(status_a == (filtersLength)){
				set = true;
				for(var i=0; i< this.incrementor[group]; i++){
					if($(this.selector[group][i]['chk_id'])){
						if(this.selector[group][i]['chk_id'] == id){
							$(this.selector[group][i]['chk_id']).checked = true;
							$(this.selector[group][i]['style_id']).className = 'checkbox chk_selected';
						}else{
							$(this.selector[group][i]['chk_id']).checked = false;
							$(this.selector[group][i]['style_id']).className = 'checkbox chk_unselected';
						}
					}
				}
			}
			if(status == 0){
				set = true;
				for(var i=0; i< this.incrementor[group] ;i++){
					if($(this.selector[group][i]['chk_id'])){
						if(this.selector[group][i]['chk_id'] == id){
							$(this.selector[group][i]['chk_id']).checked = false;
							$(this.selector[group][i]['style_id']).className = 'checkbox chk_unselected';
						}else{
							$(this.selector[group][i]['chk_id']).checked = true;
							$(this.selector[group][i]['style_id']).className = 'checkbox chk_selected';
						}
					}
				}
			}
			
		}
		if(set == false){
			for(var i=0; i< this.incrementor[group] ;i++){
				if(this.selector[group][i]['chk_id'] == id){
					if($(id).checked == false) {
						$(this.selector[group][i]['chk_id']).checked = true;
						$(this.selector[group][i]['style_id']).className = 'checkbox chk_selected';
					}else{
						$(this.selector[group][i]['chk_id']).checked = false;
						$(this.selector[group][i]['style_id']).className = 'checkbox chk_unselected';
					}			
				}
			}	
		}
	}
	
}	

var groupSelector = new groupSelector();
