//DESC: Function to make our request Object
function makeObject(){
        var x;
        var browser = navigator.appName;

        if(browser == "Microsoft Internet Explorer"){
                x = new ActiveXObject("Microsoft.XMLHTTP");
        }//end if IE
        else{
                x = new XMLHttpRequest();
        }//end if not IE

return x;
}//end makeObject

function updateRateAJAX(plan,promocode) 
{
	var YardSignPrice=19.95;
        var request = makeObject();
        var planText='';
        var newAmount=0.00;
        
	/*
	var signShipping = document.getElementById("freesign");
        var addAfter;
        // MLR 2/08 - No Sign Shipping Charges if (signShipping && signShipping.checked) addAfter='&addAfter=7.50';
	if (signShipping && signShipping.checked) addAfter='&addAfter=0.00';
        else addAfter='&';
	*/
        
	if (plan.checked)
	{
		planText = plan.value;
	}
        else 
	{
                for (var i=0; i<plan.length;i++) {
                        if (plan[i].checked) {
                                planText = plan[i].value;
                                break;
                        }
                }
        }
        //alert(promocode);
	
        var str = 'update_amount.php?plan='+planText+'&promocode='+promocode;
        //if (addAfter) str = str + addAfter;

	if(planText.length>0)
	{
        request.open('GET',str,false);
        request.send(null);
        newAmount = request.responseText;
	}


	if(document.getElementById('freesign').checked)
	{
		newAmount=parseFloat(newAmount.replace(/,/g,''))+parseFloat(YardSignPrice);
	}

	if(newAmount.toFixed)
	{
        	document.getElementById("prorated").innerHTML = '$'+newAmount.toFixed(2);
		//Update_Listings_Type_Amount('prorated','listings_type','lastupdateamount');
	}
	else
	{
		document.getElementById("prorated").innerHTML = '$'+newAmount;
		//Update_Listings_Type_Amount('prorated','listings_type','lastupdateamount');
	}


}

function updateListingCart()
{
        var YardSignPrice=19.95;
        var newAmount=document.getElementById("orgtotalcharge").value.replace(/,/g,'');

        cbSigns = document.getElementsByName('freesigns[]');
        for(i = 0;i<cbSigns.length;i++)
	{
                if(cbSigns[i].checked)
		{
	        	newAmount=parseFloat(newAmount)+parseFloat(YardSignPrice);
		}
        }

	if(newAmount.toFixed)
	{
        	document.getElementById("totalcharge").innerHTML = '$'+newAmount.toFixed(2);
	}
	else
	{
		document.getElementById("totalcharge").innerHTML = '$'+newAmount;
	}
}


function updateRateAJAX_cart(price,promocode) {

	//make sure we have a promocode first
	if(promocode=='')
	{
		try
		{
		document.getElementById("totalcharge").innerHTML = '$' + price;
		}
		catch(e)
		{
		document.getElementById("prorated").innerHTML = '$' + price;
		}
	}

        var request = makeObject();
        var addAfter;

        var str = 'update_amount.php?price='+price+'&promocode='+promocode;
        var newAmount;
        request.open('GET',str,false);
        request.send(null);
        newAmount = request.responseText;

	try
	{
        document.getElementById("totalcharge").innerHTML = newAmount;
	}
	catch(e)
	{
	document.getElementById("prorated").innerHTML = newAmount;
	}

}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}



 
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}


//########[ Function for adding bookmarks ]########
var urlAddress = "http://www.rentalhouses.com//secure/listing_cart.php";
var pageName = document.title;

function addToFavorites(){ 

	if (window.external) 
	{ 
		window.external.AddFavorite(urlAddress,pageName) 
	}
 
	else 
	{ 
		alert("Sorry! Your browser doesn't support this function."); 
	}
} 


//  End -->

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function closeSample(){
        document.getElementById('sampleCheck').style.display = 'none';
        return true;
}

function openSample(e){
        //get ref to the sample div
        var ckdiv = document.getElementById('sampleCheck');

        //get ref to the promo code label cell, for positioning the sample
        var pcell = document.getElementById('promoCell');

        //get the position of the bank name
        var pcellPos = findPos(pcell);

        ckdiv.style.left = pcellPos[0];
        ckdiv.style.top = pcellPos[1];
        ckdiv.style.display = 'block';
        return true;
}

function findPos(obj) {
        var curleft = curtop = 0;
        if (obj.offsetParent) {
                curleft = obj.offsetLeft
                curtop = obj.offsetTop
                while (obj = obj.offsetParent) {
                        curleft += obj.offsetLeft
                        curtop += obj.offsetTop
                }
        }
        return [curleft,curtop];
}

function switchTransMethod(rdo){
	if(rdo.value=='CC'){
		document.getElementById('ccTable').style.display = 'block';
		document.getElementById('ckTable').style.display = 'none';
	}
	else{
		document.getElementById('ckTable').style.display = 'block';
		document.getElementById('ccTable').style.display = 'none';
	}
}

//function copyPromo(x){
//	if(x.id=='promocodeCC')
//		document.getElementById('promocodeCK').value = x.value;
//	else
//		document.getElementById('promocodeCC').value = x.value;
//}

function SwitchButton(ButtonID,CheckBox)
{
	if (document.getElementById(CheckBox).checked)
	{
		document.getElementById(ButtonID).src='/images/btn_buynow.gif';
	}
	else
	{
               document.getElementById(ButtonID).src='/images/btn_buynow_grey.gif';
	}
}


function showShip(){
	//check for checked freesigns boxes
	cbSigns = document.getElementsByName('freesigns[]');
	showShipInfo = false;
	for(i = 0;i<cbSigns.length;i++){
		if(cbSigns[i].checked)
			showShipInfo = true;
	}
	if(showShipInfo){
		for(i = 1;i<9;i++)
			document.getElementById('ship'+i).style.display = '';
	}
	else{
		for(i = 1;i<9;i++)
			document.getElementById('ship'+i).style.display = 'none';
	}
}

