﻿function customInit()
{
	if (document.getElementById('divContainerDef'))
	{
		 //YAHOO.popup.divPopup = new YAHOO.widget.Overlay('divContainerDef', { visible:false });
		 //YAHOO.popup.divPopup.render();
	}
	if (document.getElementById('divBigPic'))
	{
		YAHOO.popup.divBigPic = new YAHOO.widget.Overlay('divBigPic', { visible:false });
		YAHOO.popup.divBigPic.render();
	}
}

/*function SimpleICalc()
{
	document.getElementById("calcResult").innerHTML = 'Your monthly payment would be $' + (((document.getElementById("pAmount").value - document.getElementById("downPmt").value - document.getElementById("tradeValue").value) * (((document.getElementById("interestRate").value * 1) / 100) + 1))/(document.getElementById("termYears").value * 12)).toFixed(2) + '.';
	document.getElementById("calcResultFrame").style.visibility = 'visible';
}
function ResetSimpleCalc()
{
	document.getElementById("calcResultFrame").style.visibility = 'hidden';
	document.getElementById("pAmount").value = '';
	document.getElementById("interestRate").value = '';
	document.getElementById("termYears").value = '';
	document.getElementById("tradeValue").value = '';
	document.getElementById("downPmt").value = '';
}*/

//Estimate Payments  calculator
function checkForZero(field)
{
    if (field.value == 0 || field.value.length == 0) {
        //alert ("This field can't be 0!");
        field.focus(); }
    else{
        MonthlyPaymentCalc();
		calculateDesired();
	}
}

function MonthlyPaymentCalc()
{
	//document.getElementById("monthlyPaymentDue").value = 10;
	var price=convertformatCurrency(document.getElementById("pAmount").value);	
	var dp=0;	
	var ir=document.getElementById("interestRate").value;
	var term=document.getElementById("numberPayments").value;
	princ = price - dp;
	intRate = (ir/100) / 12;
	months = term;
	document.getElementById("monthlyPaymentDue").value = formatCurrency(Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100);		
	calculateDesired();	
	var principalGoal=convertformatCurrency(document.getElementById("principalGoal").value);
	
	document.getElementById("pAmount").value=formatCurrency(document.getElementById("pAmount").value);
		
	document.getElementById("calcResult").innerHTML = '<strong><span><em style="color:#FF0000">' + formatCurrency(price-principalGoal) + '</em></strong>&nbsp;&nbsp;&nbsp;&nbsp; ADDITIONAL DP NEEDED</span>';
	document.getElementById("calcResultFrame").style.visibility = 'visible';
}

function ResetCalc()
{
	//document.getElementById("calcResultFrame").style.visibility = 'hidden';
	document.getElementById("pAmount").value = '';
	document.getElementById("interestRate").value = '';
	document.getElementById("numberPayments").value = '';
	document.getElementById("monthlyPaymentDue").value = '';
	document.getElementById("paymentDesired").value = '';
	document.getElementById("interestRateDesired").value = '';
	document.getElementById("numberPaymentsDesired").value = '';
	document.getElementById("principalGoal").value = '';	
}

function calculateDesired()
{
	var paymentDesired=convertformatCurrency(document.getElementById("paymentDesired").value);
	var interestRateDesired=document.getElementById("interestRateDesired").value;
	var numberPaymentsDesired=document.getElementById("numberPaymentsDesired").value;	
	intRate = (interestRateDesired/100) / 12;
	//document.getElementById("principalGoal").value=10;	
	document.getElementById("principalGoal").value=formatCurrency(Math.floor(paymentDesired*(1-Math.pow(1+intRate,(-1*numberPaymentsDesired)))/intRate));
	document.getElementById("paymentDesired").value=formatCurrency(document.getElementById("paymentDesired").value);
}

function convertformatCurrency(num) {
	//alert('tjc');
	return num.toString().replace(/\$|\,/g,'');
}

function formatCurrency(num) {
	//alert('tjc');
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

//End Estimate Payments  calculator


function showThis(imgId)
{
	document.getElementById('mainImage').src = '/dyn_image.aspx?id=' + imgId + '&s=n';
	//document.getElementById('imgBigPic').src = '/dyn_image.aspx?id=' + imgId + '&s=l';
	document.getElementById('hidSelectedImageId').value = imgId;
}
function openLargeImage()
{
	//var relUrl = '/dyn_image.aspx?id=' + document.getElementById('hidSelectedImageId').value + '&s=l';
	//document.getElementById('imgBigPic').src = relUrl;
	setTimeout('doOpenLargeImage()', 250);
}
function closeLargeImage()
{
	//document.getElementById('divBigPic').style.visibility = 'hidden';
	//document.getElementById('divBigPic').style.display = 'none';
	YAHOO.popup.divBigPic.hide();
}
function doOpenLargeImage()
{
	  YAHOO.popup.divBigPic.show();
	//document.getElementById('divBigPic').style.display = 'block';
	//document.getElementById('divBigPic').style.visibility = 'visible';
}
var detailOn = false;
function showDetail()
{
	if (detailOn)
	{
		 document.getElementById('divDetail').style.visibility = 'hidden';
		 document.getElementById('divDetail').style.display = 'none';
		 detailOn = false;
	 }
	 else
	 {
		 document.getElementById('divDetail').style.visibility = 'visible';
		 document.getElementById('divDetail').style.display = 'block';
		 detailOn = true;
	 }
}

var requestDetailOn = false;
function showRequestDetail()
{
	if (requestDetailOn)
	{
		 document.getElementById('divRequestDetail').style.visibility = 'hidden';
		 document.getElementById('divRequestDetail').style.display = 'none';
		 requestDetailOn = false;
	 }
	 else
	 {
		 document.getElementById('divRequestDetail').style.visibility = 'visible';
		 document.getElementById('divRequestDetail').style.display = 'block';
		 requestDetailOn = true;
	 }
}

var submitOfferOn = false;
function submitOffer()
{
	if (submitOfferOn)
	{
		 document.getElementById('divSubmitOffer').style.visibility = 'hidden';
		 document.getElementById('divSubmitOffer').style.display = 'none';
		 submitOfferOn = false;
	 }
	 else
	 {
		 document.getElementById('divSubmitOffer').style.visibility = 'visible';
		 document.getElementById('divSubmitOffer').style.display = 'block';
		 submitOfferOn = true;
	 }
}


var puTo;
function loadPopup(leftImage, content, rightImage, obj)
{
	obj.style.borderColor = 'yellow';
	document.getElementById('divPopupContent').innerHTML = content;
	document.getElementById('imgLeft').src = leftImage;
	document.getElementById('imgRight').src = rightImage;
    setHeight = findPosY(obj) + obj.offsetHeight;
    
    //Get the Window size
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
       myWidth = window.innerWidth;
       myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
       //IE 6+ in 'standards compliant mode'
       myWidth = document.documentElement.clientWidth;
       myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      myWidth = document.body.clientWidth;
      myHeight = document.body.clientHeight;
    }
    
   //Get the ScrollTop  
   var scrOfX = 0, scrOfY = 0;
   if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
   } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
   } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }  
    //alert(setHeight + ":" + document.getElementById('divContainerDef').offsetHeight + ":" + scrOfY +  "+ myHeight");
    if(setHeight + document.getElementById('divContainerDef').offsetHeight-scrOfY > myHeight) {       
        //window.scrollBy(0,document.getElementById('divContainerDef').offsetHeight);              
        YAHOO.popup.divPopup.cfg.setProperty('y', findPosY(obj)-document.getElementById('divContainerDef').offsetHeight);
    } else {
        //alert(document.getElementById('divContainerDef').offsetHeight);
        YAHOO.popup.divPopup.cfg.setProperty('y', findPosY(obj)+ obj.offsetHeight);
    }       
	YAHOO.popup.divPopup.cfg.setProperty('x', findPosX(obj) + 70);
	obj.style.backgroundColor = '#CCCCCC';
	//puTo = setTimeout('doLoadPopup()', 250);
}
function doLoadPopup()
{
	YAHOO.popup.divPopup.show();
}
function hidePopup(obj, oldColor)
{
	if (puTo)
		clearTimeout(puTo);
	YAHOO.popup.divPopup.hide();
	obj.style.backgroundColor = oldColor;
	obj.style.borderColor = '';
}
function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	  while(1)
	  {
		 curtop += obj.offsetTop;
		 if(!obj.offsetParent)
			break;
		 obj = obj.offsetParent;
	  }
	else if(obj.y)
	  curtop += obj.y;
	return curtop;
}
function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	  while(1) 
	  {
		 curleft += obj.offsetLeft;
		 if(!obj.offsetParent)
			break;
		 obj = obj.offsetParent;
	  }
	else if(obj.x)
	  curleft += obj.x;
	return curleft;
}

function goBack() {
    history.back();
}

function openMapImage(id)
	{	
		doOpenMapImage(id);
	}
function closeMapImage(id)
{	
	document.getElementById(id).style.visibility = 'hidden';
	document.getElementById(id).style.display = 'none';
	
	var selects = document.getElementsByTagName("select");
	for (i = 0; i < selects.length; i ++ )
	{
	    selects[i].style.visibility = 'visible';
	}
	
}
function doOpenMapImage(id)
{
	/*document.getElementById(id).style.display = 'block';
	document.getElementById(id).style.visibility = 'visible';
	
	var selects = document.getElementsByTagName("select");
	for (i = 0; i < selects.length; i ++ )
	{
	    selects[i].style.visibility = 'hidden';
	}*/
	
	if (id == 'concordmapPic')
	{
		window.open('/images/concord_map.jpg', 'ConcordMap', 'width=500,height=462'); 
	}
	else
	{
	    window.open('/images/marion_map.jpg', 'MarionMap', 'width=500,height=501');
	}
}

function pdfFormConfirmation(obj, pdfFileName) {
    var answer = confirm("In order to ensure a secure transfer of your private information, Tom Johnson " +
                "Camping Center currently only accepts applications via fax, us postal service or " +
                "personally turning in forms to one of our dealerships. To help expedite the " +
                "application process, we have provided copies of our application forms on-line " +
                "for you to print out in the comfort of your own home. If you have any questions " +
                "about these forms, feel free to email us at RVDan@TomJohnsonCamping.com " +
                "or call us either location.");
    if (answer==true){        
        obj.target='_blank';
        obj.href="/pdf/" + pdfFileName;
    } else {
        return false;
    }    
}  
