
window.onload = initialise;

function positionFooter()
{
    var footer = document.getElementById("footer");
    if (footer) { footer.style.bottom = "-1px"; }
    var search = document.getElementById("search");
    if (search) { search.style.bottom = "-1px"; }
}
		

function initialise()  {
    var x = document.getElementsByTagName('a');
    for (var i=0;i<x.length;i++) {
	if (x[i].getAttribute('type') == 'popup') {
		x[i].onclick = function () {
			return pop(this.href)
		}
		x[i].title += ' (Popup)';
	}
    }
}

function pop(url) {
	newwindow=window.open(url,'name','height=500,width=500');
	if (window.focus) {newwindow.focus()}
	return false;
}
   
function areYouSure(text)
{
     return confirm(text);
}

function show(id) {
    document.getElementById(id).style.display = "block";
}

function hide(id) {
    document.getElementById(id).style.display = "none";
}

function toggleVisible(id) {
    myElement = document.getElementById(id);
    if(myElement.style.display == "none") {
        myElement.style.display = "block";
    } else {
        myElement.style.display = "none";
    }
}

function setActiveStyleSheet(title) {
    var i, a, main;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
            a.disabled = true;
            if(a.getAttribute("title") == title) a.disabled = false;
        }
    }
}

function fillPostalAddress(formId) {
    var myForm = document.getElementById(formId);
    myForm.post_address.value = myForm.street_address.value;
    myForm.post_address2.value = myForm.street_address2.value;
    myForm.post_suburb.value = myForm.street_suburb.value;
    myForm.post_postcode.value = myForm.street_postcode.value;
    myForm.post_state.value = myForm.street_state.value;
}

function makeAnOffer()
{
    var offerlabel = document.getElementById('item_offer_label');
    var offerinput = document.getElementById('item_offer_input');
    
    offerlabel.style.display = '';
    offerinput.style.display = '';
}

function checkOffer()
{
    var itemprice = parseFloat(document.getElementById('item_orig_price').value);
    var offerprice = parseFloat(document.getElementById('item_offer_input').value);
    
    if(offerprice > itemprice)
    {
        alert("Your offer must be less than the buy now price!");
	return false;
    }
    
    return true;
}

function checkItemInsert()
{
    var debug = 'false';

    //Make it so that all commas are removed from the item price.
    var price_remove = ",";
    var price_replace = "";
    
    var temp = "" + document.getElementById('item_price').value; // temporary holder

    while (temp.indexOf(price_remove)>-1) {
        pos= temp.indexOf(price_remove);
        temp = "" + (temp.substring(0, pos) + price_replace + 
        temp.substring((pos + price_remove.length), temp.length));
    }
    document.getElementById('item_price').value = temp;

    var itemprice = parseFloat(document.getElementById('item_price').value);
    var category_id = document.getElementById('category_id').value;
    var item_name = document.getElementById('item_name').value;
    var item_suburb = document.getElementById('item_suburb').value;
    var item_desc = document.getElementById('item_desc').value;
    var postage_price = document.getElementById('item_postage_price').value;

    
    

    if(document.getElementById('make_id'))
    {
        var make_id = document.getElementById('make_id').value;
    } else
    {
        var make_id = 'all';
    }
    
    if(document.getElementById('model_id'))
    {
        var model_id = document.getElementById('model_id').value;
    } else
    {
        var model_id = 'all';
    }

    if(document.getElementById('new_make'))
    {
        var new_make = document.getElementById('new_make').value;
    } else
    {
        var new_make = '';
    }
    
    if(document.getElementById('new_model'))
    {
        var new_model = document.getElementById('new_model').value;
    } else
    {
        var new_model = '';
    }
    if(document.getElementById('item_postage_comment'))
    {
        var postage_comment = document.getElementById('item_postage_comment').value;
    } else
    {
        var postage_comment = '';
    }
    var errormessage = '';
    
    if(debug == 'true')
    {
        alert("DEBUG FOR CATEGORIES\n"+
              "category_id:"+category_id+"\n"+
	      "model_id:"+model_id+"\n"+
	      "make_id:"+make_id+"\n"+
	      "new_make:"+new_make+"\n"+
	      "new_model:"+new_model+"\n");
    }
	  
    
    //alert("DEBUG::model_id:"+model_id+"::make_id:"+make_id+"::category_id:"+category_id);
    
    if(itemprice <= 0.00)
    {
        var errormessage = errormessage + "Please Enter Item Price\n";
    }

    if(category_id == 'all' 
    || (make_id == 'all' && new_make == '')
    || (model_id == 'all' && new_model == ''))
    {
        var errormessage = errormessage + "Please Select A Valid Category, Make and Model\n";
    }
    
    if(item_name == '')
    {
        var errormessage = errormessage + "Please Enter A Valid Item Title\n";
    }
    
    if(item_desc == '')
    {
        var errormessage = errormessage + "Please Enter A Valid Item Description\n";
    }
    if(item_suburb == '')
    {
        var errormessage = errormessage + "Please Enter A Valid Location\n";
    }
    
    if(errormessage != '')
    {
        alert(errormessage);
        return false;
    } else
    {
        return true;
    }
}

function updateItemForm()
{
    var item_type = document.getElementById('item_type');
    if(item_type.value == 'COMPLETE')
    {
        document.getElementById('item_year_li').style.display          = '';
        document.getElementById('item_part_number_li').style.display   = 'hide';
        document.getElementById('item_part_category_li').style.display = 'hide';
        document.getElementById('item_details_fieldset').style.display = '';
        document.getElementById('submit_button').style.display         = '';
    } else if(item_type.value == 'PART')
    {
        document.getElementById('item_year_li').style.display          = 'hide';
	document.getElementById('item_details_fieldset').style.display = '';
	document.getElementById('item_part_category_li').style.display = '';
	document.getElementById('item_part_number_li').style.display   = '';
	document.getElementById('submit_button').style.display         = '';
    }
}

function updateSearchAction(checked, form)
{
    if(checked.value == 'COMPLETE' || checked.value == 'PART')
    {
        form.action = "/items/";
    } else if(checked.value == 'WANTED')
    {
        form.action = "/wanteditems/";
    }
}

// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}}
