// JavaScript Document
function setHeight(obj,height){
	try{
		obj.style.height = height +'px';
	}catch (e){
		try{
			document.getElementById(obj).style.height = height + 'px';
		}catch(e){
			//do nohting	
		}
	}
}

function equalHeight(objs){
	var i;
	var maxHeight = 620;
	for (i = 0; i < objs.length; i++){
		objs[i].style.height = null;
		//objs[i] = document.getElementById(objs[i]);	
		if (objs[i].offsetHeight > maxHeight){
			maxHeight = objs[i].offsetHeight;	
		}
	}
	for (i = 0; i < objs.length; i++){
		objs[i].style.height = maxHeight + 'px';	
	}
}


//ajax functions
var myHttpSocket = false;

function createSocket(){
	//set up the socket
	if (checkSocket(myHttpSocket)){
		//we got a socket, make sure it's not inuse and then return it
		//we're doing this because of a bug in IE7
		myHttpSocket.abort();
		return myHttpSocket;
	}
	//var xmlHttp;
	try{ 
		// Firefox, Opera 8.0+, Safari  
		myHttpSocket=new XMLHttpRequest();  
	}catch (e){
		// Internet Explorer
		try{
			myHttpSocket=new ActiveXObject("Msxml2.XMLHTTP");    
		}catch (e){
			try{
				myHttpSocket=new ActiveXObject("Microsoft.XMLHTTP");      
			}catch (e){
				//alert("Sorry, this function is not available");
				return false;
			}
		}
	}
	return myHttpSocket;
}

function checkSocket(obj){
	try
	{
		if (obj == false) return false;
	}catch(e)
	{
		if (e == "[object Error]"){
			//we got the object, continue
		}else{
			return false;
		}
	}
	return true;
}

function ajaxPostRequest(url,parameters,whereTo,sync,onPostComplete){
	var xmlHttp = createSocket();
	if (checkSocket(xmlHttp) == false) return false;
	
	if (sync == true){
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4) {
				if (whereTo) document.getElementById(whereTo).innerHTML = xmlHttp.responseText;
				try{
					onPostComplete();	
				}catch (e) {
					//do nothing
				}
			}
		}
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", parameters.length);
	    xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(parameters);
	
	}else{
		xmlHttp.open("POST",url,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", parameters.length);
	    xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(parameters);
		if (whereTo) document.getElementById(whereTo).innerHTML = xmlHttp.responseText;
		try{
			onPostComplete();
		}catch (e){
			//do nothing, you don't have to pas a funciton.	
		}
	}
}


//specific to this site
function swapBidButtons(){
	document.getElementById('bidButton1').style.display = 'none';
	document.getElementById('bidButton2').style.display = 'block';
}

function submitAuctionBid(){
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var phone_number = document.getElementById('phone_number').value;
	var max_bid = document.getElementById('max_bid').value;
	
	//staic, change these if you need to..i think you will
	var terms_agree = 'yes';
	var submit_bid = 'yes';
	
	//so build the post data now:
	var postData = 'name=' + escape(name) + '&email=' + escape(email) + '&phone_number=' + escape(phone_number) + '&max_bid=' + escape(max_bid) + '&terms_agree=' + escape(terms_agree) + '&submit_bid=' + escape(submit_bid) + '&ajax=submit-bid';
	
	ajaxPostRequest('index.php',postData,'auction_panel',false,swapBidButtons)
}