var mySlideC;
var mySlideCC;
$(document).addEvent('domready', function() {
    initSliders();
    cleanCookie();
    $(document).getElements('div[class=vehicleTileHighlight]').each(function(item, index){
        item.removeClass('vehicleTileHighlight');
        item.addClass('vehicleTile');
    });
});
function defaultImageAff(img){
	img.src= BASE_CONTEXT + "/assets/en/images/pricing/affordability/default.png";

}

function resetFields(){
	document.AffordabilityCalculatorForm.txtMonthlyPayment.value = "100";
	document.AffordabilityCalculatorForm.txtDownPayment.value = "0";
	document.AffordabilityCalculatorForm.txtTradeValue.value = "0";
	document.AffordabilityCalculatorForm.txtApr.value = "0";
}
function cleanInputs (domObj, v){
	if (domObj.value.trim().length == 0){
		domObj.value = v;
	}else{
		if ((domObj.value.trim().length != 0) && (domObj.value == v)){
			domObj.value = "";
		}else{
			domObj.value = domObj.value;
		}
	}
}

function cleanInputsOnBlur (domObj, v){
	if(domObj.name=="txtMonthlyPayment"){
		if(domObj.value<100){
			domObj.value = "100";
			mySlideC.setMin(parseInt("100"));
		}else if(domObj.value > 2000){
			domObj.value = "2000";
			mySlideC.setMin(parseInt("2000"));
		}else{
			mySlideC.setMin(parseInt(domObj.value));
		}
	}else if(domObj.name=="txtDownPayment" ){
		if(domObj.value<0){
			domObj.value = "0";
			mySlideCC.setMin(parseInt("0"));
		}else if(domObj.value > 10000){
			domObj.value = "10000";
			mySlideCC.setMin(parseInt("10000"));
		}else{
			mySlideCC.setMin(parseInt(domObj.value));
		}
	}else{
		if (domObj.value.trim().length == 0){
			domObj.value = v;
		}
	}
}

var decimal = '';
var object = '';
function validateNumberFormat(domObj){
	var regEx =  /(^\d+$)|(^\d+\.$)|(^\d+\.\d{1}$)|(^\d+\.\d{2}$)/;
	var str = domObj.value;
	if(domObj.id !== object){
		decimal = '';
		object = domObj.id;
	}
	if(regEx.test(str)){
		decimal = str;
	} else{
		if(str === ''){
			domObj.value = '';
			decimal = '';
		} else {
			domObj.value = decimal;
		}
	}
	//var size = /(^\d+\.\d{2}$)/;
	//if (size.test(str)){
		//domObj.setAttribute('maxLength', str.length);
	//} else {
		//domObj.setAttribute('maxLength', 8);
	//}
}


// -----new js for the new affordability page -----
var page = function() {
	var private_var;
	function private_method() {
		// do stuff here
	}
	return {

		showYear : function(src) {

			for (loop = 0; loop < src.options.length; loop++) {
				($('group'+src.options[loop].value)).className = "vehicleGroup";
			}
			//css.addClassName($('group'+year), 'active');
			($('group'+src.options[src.selectedIndex].value)).className = "vehicleGroupActive";

			currentYear = src.options[src.selectedIndex].value;
			//pickVehicle(src.options[src.selectedIndex].value,vehicleHLArray[src.options[src.selectedIndex].value]['index']);
			showVehicleNum(src.options[src.selectedIndex].value);
		},
		// --------------------------------------------------------------
		// getQsParams: generic name/value pair function
		// return a hash (of sorts) of name value pairs from the querystring
		// uasge: var qsParams = getQsParams();
		// then: qsParams['url'] whould equal whatever url=XXX in the querystring

		getQsParams : function() {
			var qs = location.search;
			qs = qs.substring(1);
			// create an 'array' called newArray with the name value pairs from the querystring
			var qsArray = new Array;
			qsArray = qs.split('&'); //creating an array in which the values are separated by ampersands in the code//
			var keyValueArray = new Array; //this one loads the names and values into a hash (of sorts)//
			for(i=0; i<qsArray.length; i++) {
				var nameValue = qsArray[i].split('='); //splitting what we find between each ampersand into key value pairs //
				keyValueArray[nameValue[0]] = unescape(nameValue[1]); //we are then turning all the escaped characters back into the 'real thing' ie. %3F turns into a '?' //
			}
			return keyValueArray;
		},

		anotherFunction : function(form) {
			return true;
		}
	};
}();

function zipLoad(){
	setTimeout("validateCookie(this,'loadPage()','byo',false)",2000);
	var winMaskDiv = document.getElementById("winMask");
	winMaskDiv.style.display = "";
	winMaskDiv.style.height = "2000px" ;
    winMaskDiv.style.width = "100%";
    winMaskDiv.style.visibility = "visible";


}
function loadPage(){
	zipLoc = getDefaultLocation();
	var url = window.location.href.split("?");
	window.location.href=url[0]+"?zipCode="+zipLoc.zipcode+"&regionCode="+zipLoc.region.code+"&countyCode="+zipLoc.county.code;
	//console.log(url[0]+"?zipCode="+zipLoc.zipcode+"&regionCode="+zipLoc.region.code+"&countyCode="+zipLoc.county.code);
}

/*function poCheckZip(src,form){
	mouseEvent = src;
	vZipInfo = null;
	zipDialogLocation = null;
	var zipValue = form.zipCode.value;
	if ((zipValue == '') || (zipValue == 'Enter ZIP')) {
		alert('Please enter a valid Zip Code');
		form.zipCode.value = '';
		form.zipCode.focus();
		return false;
	}

	if (zipValue.length != 5) {
		alert('The Zip Code must have 5 digits');
		form.zipCode.focus();
		return false;
	}
	vZipInfo = new zipcodeUtil(zipValue);
	vZipDialog = new zipDialog('loadPage()', false, src, 'byoDialog');
	if (vZipInfo.isValid) {
		zipDialogLocation = new Location();
		var counties = vZipInfo.getCounties();
		var regions = vZipInfo.getRegions(counties[0].code);

		zipDialogLocation.zipcode = zipValue;
		zipDialogLocation.county = new County(counties[0].code,counties[0].description);
		zipDialogLocation.region = new Region(regions[0].code,regions[0].description, vZipInfo.getDmaByRegion(regions[0].code));
		zipDialogLocation.isMultiCounty = vZipInfo.isMultiCounty;
		zipDialogLocation.isMultiRegion = vZipInfo.isMultiRegion;

		if (vZipInfo.isMultiCounty) {
			getCountyDialog();
		} else if (vZipInfo.isMultiRegion) {
			getRegionDialog();
		} else {

			saveDefaultLocation(zipDialogLocation.zipcode,
					zipDialogLocation.region, zipDialogLocation.county, zipDialogLocation.isMultiCounty, zipDialogLocation.isMultiRegion);
			executeResponse(vZipDialog.response, vZipDialog.isURL);
			return false;
		}
	} else {
		alert('Please enter a valid Zip Code');
		form.zipCode.value = '';
		form.zipCode.focus();
		return false;
	}

}*/

function closeZipDialog(id) {
	if ($(id) != null) {
		document.body.removeChild($(id));
	}
	return false;
}



function pickVehicle(year, index){
    var vehicleCompleateName = '';
    var divisionObj = DIVISION.toUpperCase();
	if(vehicleHLArray[year]['size']!=0){
		if(vehicleArray[vehicleHLArray[year]['year']][vehicleHLArray[year]['index']][8] != "vehicleTileHide"){//don't touch the hidden ones
			document.getElementById(vehicleHLArray[year]['name']+vehicleHLArray[year]['year']).className = "vehicleTile";
			vehicleArray[vehicleHLArray[year]['year']][vehicleHLArray[year]['index']][8] = "vehicleTile";
		}
		document.getElementById(vehicleArray[year][index][0]+year).className = "vehicleTileHighlight";

		vehicleArray[year][index][8] = "vehicleTileHighlight";
		vehicleHLArray[year]['name'] = vehicleArray[year][index][0];
		vehicleHLArray[year]['year'] = year;
		vehicleHLArray[year]['index'] = index;
                vehicleCompleateName = vehicleArray[year][index][0] +  ' ' + year;
		if(currentYear == year){
			cardChange(year,index);
		}
	}
	i = index;
	
		var pageMaskDiv = document.getElementById("pageMask");
		pageMaskDiv.style.display = "";
		pageMaskDiv.style.height = "2000px" ;
    	pageMaskDiv.style.width = "100%";
    	pageMaskDiv.style.visibility = "visible";
		document.getElementById("pRight").style.display = "block";
        clickTrack({pageName: divisionObj+' | DIVISIONAL | PRICING | LANDING PAGE',
        prop1: 'DIVISIONAL',
        prop2: 'PRICING',
        prop3: 'DIVISIONAL | PRICING',
        prop4: 'LANDING PAGE',
        prop5: 'PRICING | LANDING PAGE',
        prop6: 'DIVISIONAL | PRICING | LANDING PAGE',
        prop7: 'POP UP',
        prop8: 'LANDING PAGE | POP UP',
        prop9: 'PRICING | LANDING PAGE | POP UP',
        prop10: 'DIVISIONAL | PRICING | LANDING PAGE | POP UP',
        prop11: vehicleCompleateName.toUpperCase(),
        prop12: 'POP UP | ' + vehicleCompleateName.toUpperCase(),
        prop13:'LANDING PAGE | POP UP | ' + vehicleCompleateName.toUpperCase(),
        prop14:'PRICING | LANDING PAGE | POP UP | ' + vehicleCompleateName.toUpperCase(),
        prop15:'DIVISIONAL | PRICING | LANDING PAGE | POP UP | ' + vehicleCompleateName.toUpperCase(),
        prop17:'PRICING',
        prop18:'SHOPPING',
        prop24:'EN', prop25:divisionObj,
        prop26:(new Date()).getHours(),
        prop27: weekday[(new Date()).getDay()]});

}


function filterDisplayVehicles(year, index){
	if(vehicleHLArray[year]['size']!=0){
		if(vehicleArray[vehicleHLArray[year]['year']][vehicleHLArray[year]['index']][8] != "vehicleTileHide"){//don't touch the hidden ones
			document.getElementById(vehicleHLArray[year]['name']+vehicleHLArray[year]['year']).className = "vehicleTile";
			vehicleArray[vehicleHLArray[year]['year']][vehicleHLArray[year]['index']][8] = "vehicleTile";
		}
		document.getElementById(vehicleArray[year][index][0]+year).className = "vehicleTileHighlight";

		vehicleArray[year][index][8] = "vehicleTileHighlight";
		vehicleHLArray[year]['name'] = vehicleArray[year][index][0];
		vehicleHLArray[year]['year'] = year;
		vehicleHLArray[year]['index'] = index;
		if(currentYear == year){
			cardChange(year,index);
		}
	}
	i = index;
}

function cardChange(year,index){

	var params = page.getQsParams();
	
	


	var html = '';
	html += '<div id="leftArrow" class="showArrow" onClick="leftArrowClick(\''+year+'\')">&nbsp;</div>';
	html += '<div id="offerContent"><div id="offerLt">';
	html += '<div class="offerHeader" id="cardTitle_'+year+vehicleArray[year][index][0]+'">'+year+' '+ vehicleArray[year][index][1]+'</div>';
	html += '<div class="offerImg" style="height:183px;*height:155px;"><img src="'+BASE_CONTEXT+vehicleArray[year][index][6]+'" alt=""/></div>' +
			'<div style="float:left;margin-left:10px;">For details on cash and finance offers:</div>' +
			'</div>';	
	html += '<div id="offerRt"><div class="offerPrice"><div class="closeBt"><a href="#" onClick="closeCard();return false;"><b>Close X</b></div></a><br/><ul id="offerPriceList""></ul>';

	html += '</div>';
	
	html += '<div id="regTag" class="priceRegTag"></div>';
	html += '<br style="clear:both"/>';
	html += '<div class="offerBottom">';
	//html += '<div class="offerFooter">Price estimates include available cash offers for the '+year+' '+ vehicleArray[year][index][1]+' and are not compartible with low-rate GMAC finance program.</div>';
	//html += '<div class="offerClick">Click below to see details on cash offers and APR finance programs for this vehicle</div>';
	
	if (params["regionCode"] == null || params["county"] == null || params["zipCode"] == null){
		var locstr = getDefaultLocation();
		var zipcode;
		var region;
		var county;

		if (locstr != null) {
			try {
				zipcode = locstr["zipcode"];
				region = locstr["region"].code;
				county = locstr["county"].code;				
				
				html += '<a class="offerButton" id="cardOffers_'+year+vehicleArray[year][index][0]+'" href="'+ BASE_CONTEXT +'/tools/currentoffers/results.do?year='+ year +'&brand=' + vehicleArray[year][index][0] +'&zipCode='+ zipcode +'&region='+ region +'&county='+ county +'">See All [Model] Offers</a>';
				var test = '<a class="offerButton" id="cardOffers_'+year+vehicleArray[year][index][0]+'" href="'+ BASE_CONTEXT +'/tools/currentoffers/results.do?year='+ year +'&brand=' + vehicleArray[year][index][0] +'&zipCode='+ zipcode +'&region='+ region +'&county='+ county +'">See All [Model] Offers</a>';
	
			} catch (e) {alert(e);}
		}
	}else{	
		html += '<a class="offerButton" id="cardOffers_'+year+vehicleArray[year][index][0]+'" href="'+ BASE_CONTEXT +'/tools/currentoffers/results.do?year='+ year +'&brand=' + vehicleArray[year][index][0] +'&zipCode='+ params["zipCode"] +'&region='+ params["regionCode"] +'&county='+ params["countyCode"] +'">See All [Model] Offers</a>';
		var test = '<a class="offerButton" id="cardOffers_'+year+vehicleArray[year][index][0]+'" href="'+ BASE_CONTEXT +'/tools/currentoffers/results.do?year='+ year +'&brand=' + vehicleArray[year][index][0] +'&zipCode='+ params["zipCode"] +'&region='+ params["regionCode"] +'&county='+ params["countyCode"] +'">See All [Model] Offers</a>';
	}
	
	
//console.log(test);
	var isMultiCounty = document.getElementById("isMultiCounty").value;
	html += '<div class="offerLink"><a href="'+BASE_CONTEXT+'/vehicles/'+year+'/'+vehicleArray[year][index][0]+'/build.do?isMultiCounty='+isMultiCounty+'">Build Your Own</a>&nbsp;&nbsp;<a href="'+BASE_CONTEXT+'/tools/messaging/raq.do?year='+year+'&brand='+vehicleArray[year][index][0]+'">Request a Quote</a></div>';
	html += '</div></div></div>';
	html += '<div id="rightArrow" class="showArrow" onClick="rightArrowClick(\''+year+'\')">&nbsp;</div>';
	document.getElementById("pRightContent").innerHTML = html;
	
	if(vehicleArray[year][index][7]!=""){
			document.getElementById("regTag").innerHTML = "<a href='"+vehicleArray[year][index][7]+"' target='_blank'>redtag</a>";
	}else{
			document.getElementById("regTag").innerHTML = "";
	}

	//console.log(currentYear+"/"+index+"/"+arrowArray[currentYear]['firstIndex']+"/"+arrowArray[currentYear]['lastIndex']);
	document.getElementById("leftArrow").className = "showArrow";
	document.getElementById("rightArrow").className = "showArrow";
	
	/* -------------Pricing box code------------------- */
	var priceBlockPO = new PricingBlock('offerPriceList');
	priceBlockPO.setBaseMSRP(vehicleArray[year][index][10],"MSRP starting at");
	priceBlockPO.setDFC(vehicleArray[year][index][11],null);	
	if(vehicleArray[year][index][13][0]!=null){
		priceBlockPO.setPromotion(vehicleArray[year][index][13][1],vehicleArray[year][index][13][0]);
		priceBlockPO.setIcon(vehicleArray[year][index][13][2]);
	}
	priceBlockPO.setCashOffers(vehicleArray[year][index][12],"Total Cash Offers");
	priceBlockPO.showBox("PO");
	/* -------------Pricing box code------------------- */
}

function closeCard(){
	var pageMaskDiv = document.getElementById("pageMask");
   	pageMaskDiv.style.visibility = "hidden";
	document.getElementById("pRight").style.display = "none"; 
}

function brandCurrentOffer(){
	var params = page.getQsParams();
	window.location.href = BASE_CONTEXT+"/tools/currentoffers/results.do?year="+ currentYear +"&brand=" + vehicleArray[currentYear][vehicleHLArray[currentYear]['index']][0] +"&zipCode="+ params['zipCode'] +"&region="+ params['regionCode'] +"&county="+ params['countyCode'];
}

function leftArrowClick(year,index){
	var showIndex = arrowArray[year]['show'].split(',');
	var temp1 = 0;
	for(var i=0; i<showIndex.length; i++){
		if(vehicleHLArray[year]['index'] == showIndex[i])
			temp1 = i;
	}

	if(temp1==1)
	temp1=showIndex[showIndex.length-1] ;
	else temp1 = showIndex[temp1-1] ;

	pickVehicle(year, temp1);
}
function rightArrowClick(year,index){
	var showIndex = arrowArray[year]['show'].split(',');
	var temp2 = 0;
	for(var i=0; i<showIndex.length; i++){
		if(vehicleHLArray[year]['index'] == showIndex[i])
			temp2 = i;
	}
	if(temp2==(showIndex.length-1))
	temp2=0;
	else temp2 = showIndex[temp2+1] ;
	pickVehicle(year, temp2);
}

msrpValue = "9999999999";
function calculator(){
	var monthlyPayment = document.AffordabilityCalculatorForm.txtMonthlyPayment.value;
	monthlyPayment = parseFloat(monthlyPayment.replace("$",""));
	var downPayment = document.AffordabilityCalculatorForm.txtDownPayment.value;
	downPayment = parseFloat(downPayment.replace("$",""));
	var tradeValue = parseFloat(document.AffordabilityCalculatorForm.txtTradeValue.value);
	var apr = parseFloat(document.AffordabilityCalculatorForm.txtApr.value);
	//var duration = parseFloat(document.AffordabilityCalculatorForm.cmbDuration.options[document.AffordabilityCalculatorForm.cmbDuration.selectedIndex].value);
	var duration = document.AffordabilityCalculatorForm.cmbDuration.options[document.AffordabilityCalculatorForm.cmbDuration.options.selectedIndex].value;
	var msrp = 0.0;
	var temp = monthlyPayment+","+downPayment+","+tradeValue+","+apr+","+duration;
	apr = (apr / 1200.00);
	if(apr > 0.0){
		msrp = (monthlyPayment * (
					(Math.pow(1.00 + apr, duration) - 1.00))
					/ (apr * (Math.pow(1.00 + apr, duration))) + (downPayment + tradeValue));
	}else{
		msrp = (monthlyPayment * duration) + (downPayment + tradeValue);
	}
	console.log("msrp calculated: "+msrp+" "+monthlyPayment+"/"+downPayment+"/"+tradeValue+"/"+tradeValue+"/"+duration);
	msrpValue = msrp;
	reDisplayVehicle(msrp);
	temp = msrp+","+temp;
	cookie.create("calculator",temp,1);
}

function loadCookie(year){
	var cookieValue = cookie.read("calculator");
	var cookieArray = cookieValue.split(',');
	mySlideC.setMin(parseInt(cookieArray[1]));
	document.AffordabilityCalculatorForm.txtMonthlyPayment.value = cookieArray[1];
	mySlideCC.setMin(parseInt(cookieArray[2]));
	document.AffordabilityCalculatorForm.txtDownPayment.value = cookieArray[2];
	document.AffordabilityCalculatorForm.txtTradeValue.value = cookieArray[3];
	document.AffordabilityCalculatorForm.txtApr.value = cookieArray[4];
	document.AffordabilityCalculatorForm.cmbDuration.options[parseInt(cookieArray[5])/12-1].selected = true;
	//console.log("msrp passed from cookie: "+cookieArray[0]);
	msrpValue = cookieArray[0];
	reDisplayVehicle(parseFloat(cookieArray[0]));

}

function cleanCookie(){
	cookie.erase("calculator");
	mySlideC.setMin(100);
	document.AffordabilityCalculatorForm.txtMonthlyPayment.value = "100";
	mySlideCC.setMin(0);
	document.AffordabilityCalculatorForm.txtDownPayment.value = "0";
	document.AffordabilityCalculatorForm.txtTradeValue.value = "0";
	document.AffordabilityCalculatorForm.txtApr.value = "0";
	document.AffordabilityCalculatorForm.cmbDuration.options[0].selected = true;
	//console.log("msrp passed from cookie: "+cookieArray[0]);
	//reDisplayVehicle(parseFloat(cookieArray[0]));
	msrpValue = "9999999999";
	reDisplayVehicle("9999999999");
}

var conflict = true; //assume we hide the vehicle which is currently hightlighted
function reDisplayVehicle(msrp){
	msrpValue = msrp;
	var vehicleMsrp=0;
	for(var i=0; i<yearArray.length; i++){ //loop each year
		arrowArray[yearArray[i]]['show'] = "";
		for(var j=0; j<vehicleArray[yearArray[i]].length; j++){ //loop each vehicle of each year
			vehicleMsrp = removeComma(vehicleArray[yearArray[i]][j][4].substring(1));
			if(vehicleMsrp > msrp){//hide the vehicle that's great than msrp
					document.getElementById(vehicleArray[yearArray[i]][j][0]+yearArray[i]).className = "vehicleTileHide";
					vehicleArray[yearArray[i]][j][8] = "vehicleTileHide";
			}else{//show the vehicle that's less than msrp
				document.getElementById(vehicleArray[yearArray[i]][j][0]+yearArray[i]).className = "vehicleTile";
				vehicleArray[yearArray[i]][j][8] = "vehicleTile";
				arrowArray[yearArray[i]]['show'] = arrowArray[yearArray[i]]['show']+","+j;
			}
		}
		for(var j=0; j<vehicleArray[yearArray[i]].length; j++){
			if(vehicleArray[yearArray[i]][j][8] == "vehicleTile"){
				arrowArray[yearArray[i]]['firstIndex'] = j;
				break;
			}
		}
		for(var j=vehicleArray[yearArray[i]].length-1; j>-1; j--){
			if(vehicleArray[yearArray[i]][j][8] == "vehicleTile"){
				arrowArray[yearArray[i]]['lastIndex'] = j;
				break;
			}
		}
		vehicleHLArray[yearArray[i]]['size'] = 0;
		for(var k=0; k<vehicleArray[yearArray[i]].length; k++){//loop vehicles again
			if(vehicleArray[yearArray[i]][k][8] == "vehicleTile"){//for the ones shown
				vehicleHLArray[yearArray[i]]['size']++;//get the new size
				if(vehicleHLArray[yearArray[i]]['index'] == k){//hightlight it again
					conflict = false;
					filterDisplayVehicles(yearArray[i],k);
				}
			}
		}
		if(conflict){//loop through the vehicle array again to hightlight the first one not hidden
			for(var k=0; k<vehicleArray[yearArray[i]].length; k++){
				if(vehicleArray[yearArray[i]][k][8] == "vehicleTile"){
					filterDisplayVehicles(yearArray[i],k);
					break;
				}
			}
		}
		//console.log(yearArray[i]+"/size: "+vehicleHLArray[yearArray[i]]['size']);
		if(currentYear == yearArray[i]) showVehicleNum(yearArray[i]);
		conflict = true;
		firstShow = 0, lastShow = 0;
	}
}

function showVehicleNum(year){
	if(vehicleHLArray[year]['size'] == 0){
		document.getElementById("pRightContent").innerHTML = "<div class='empty'>Based on the payment criteria you entered below no vehicles are available, please try to change your criteria and update.</div>";
	}
	if(msrpValue != "9999999999")
		document.getElementById("vehicleNumText").innerHTML = "<span class='numBig'>"+vehicleHLArray[year]['size']+"</span> of "+vehicleHLArray[year]['totalSize']+" vehicles meet my desired monthly payment";
	else
		document.getElementById("vehicleNumText").innerHTML = "<span class='numBig'>0</span> of "+vehicleHLArray[year]['totalSize']+" vehicles meet my desired monthly payment";
}

function addComma(value){
		// change 12000 to 12,000
		var valueString = ""+value;
		if(value>=1000){
			valueString = valueString.substring(0, valueString.length-3)+","+valueString.substring(valueString.length-3);
		}
    return valueString;
}
function removeComma(value){
		// change 12,000 to 12000
		var valueString = ""+value;
		if(valueString.indexOf(',')!=-1){
			valueString = valueString.substring(0, valueString.indexOf(',')) + valueString.substring(valueString.indexOf(',')+1);
		}
    return parseFloat(valueString);
}

var promoCurrent = 1;
function promoLeft(){
	var temp = promoCurrent;
	promoCurrent--;
	promoAction(temp,promoCurrent);
}
function promoRight(){
	var temp = promoCurrent;
	promoCurrent++;
	promoAction(temp,promoCurrent);
}
function promoIndex(index){
	promoAction(promoCurrent, index);
	promoCurrent = index;
}
function promoAction(previous, now){
	if(now==1){
		document.getElementById("promoArrowLt").style.visibility = "hidden";
	}else{
		document.getElementById("promoArrowLt").style.visibility = "visible";
	}
	if(now==promoTotal){
		document.getElementById("promoArrowRt").style.visibility = "hidden";
	}else{
		document.getElementById("promoArrowRt").style.visibility = "visible";
	}
	document.getElementById("promo"+previous).style.display = "none";
	document.getElementById("promo"+now).style.display = "block";
	document.getElementById("promoNum"+previous).style.display = "none";
	document.getElementById("promoNum"+now).style.display = "block";
	document.getElementById("promoNumLink"+previous).style.display = "block";
	document.getElementById("promoNumLink"+now).style.display = "none";

}

function showTooltipLt(img,tip){
	img.src = BASE_CONTEXT+"/assets/en/images/pricing/affordability/mark0.jpg";
	document.getElementById(tip).className = "tooltipLtActive";
	document.getElementById("cmbDuration").style.visibility = "hidden";
}
function showTooltipRt(img,tip){
	img.src = BASE_CONTEXT+"/assets/en/images/pricing/affordability/mark0.jpg";
	document.getElementById(tip).className = "tooltipRtActive";
}
function hideTooltip(img,tip){
	img.src = BASE_CONTEXT+"/assets/en/images/pricing/affordability/mark.jpg";
	document.getElementById(tip).className = "tooltip";
	document.getElementById("cmbDuration").style.visibility = "visible";
}

function initSliders(){
    mySlideC = new Slider($('slider_gutter_C'), $('slider_knob_C'), $('slider_bkg_img_C'),{
        start: 100,
        end: 2000,
        offset:0,
        snap:true,
        numsteps:380,
        onChange: function(pos){
            document.AffordabilityCalculatorForm.txtMonthlyPayment.value = pos;
        }
    }, null).setMin(100);
    mySlideCC = new Slider($('slider_gutter_CC'), $('slider_knob_CC'), $('slider_bkg_img_CC'),{
        start: 0,
        end: 10000,
        offset:0,
        snap:true,
        numsteps:200,
        onChange: function(pos){
            document.AffordabilityCalculatorForm.txtDownPayment.value = pos;
        }
    }, null).setMin(0);
}



