
/**
 * if textarea is valid sets task to sendMessage and submits form
 *
*/

function getcontent(id){
    if (document.getElementById){
    	el=document.getElementById(id);
    	if (el) return el.innerHTML;
    }
    return '&nbsp;';
}


function sendMessage() {

	sUrl = '/includes/ajax/ajax.php?com=com_adsman&data=contact&from=' + document.getElementById('from').value + '&to=' + document.getElementById('to').value + '&message=' + document.getElementById('message_textarea').value + '&id=' + document.getElementById('id').value;  

	//alert(sUrl);

	contact_ajax_form(sUrl);

}

function reply(to) {
	document.getElementById('to').value=to;	
	//SelectTab('send');
}

function SelectTab(tab)
{

    if ( (tab=="messages" || document.location.hash=='#messages') && tabPane1.pages.length>1){
    	tabPane1.setSelectedIndex(1);
    }
    if ((tab=="send" || document.location.hash=='#send') && tabPane1.pages.length>2){
         tabPane1.setSelectedIndex(2);
    }
}

function validateAdd(){
	
	if (require_terms)
		var terms = document.getElementById('terms').checked;
	else 
		var terms = 1;
	
	var title = document.getElementById('title').value;
	
	var price = document.getElementById('askprice').value;
	
	var valid_price = true;
	
	if (isNaN(price)) valid_price = false;	
	if((require_price)&&( price=="")) valid_price = false;
	
			
	if( (terms ) && title!="" && valid_price){
		document.adsForm.submit();
	}else{
		if(!terms) alert(language["adsman_err_terms"]);
		if(title=="") alert(language["adsman_err_enter_title"]);
		if (!valid_price)	alert(language["adsman_err_price_valid"]);
	}
	
	
}

function tableAdsOrdering( order, dir) {
	var form = document.adsForm;

	form.filter_order.value 	= order;
	form.filter_order_Dir.value	= dir;
	form.submit();
}


// AJAX call for contact form



function contact_ajax_form(sUrl) {



// Create a shorthand for YAHOO.util.Connect
var YUC = YAHOO.util.Connect;

/*
 * Create an object to handle all of the Connection Manager custom events.
 *
 * NOTE: You can also choose to represent your event handlers as global
 * functions instead of object members, and omit the scope argument from
 * subscribe().
 */
var handleEvents = {
	start:function(eventType, args){
	// do something when startEvent fires.
	// Argument eventType will have a string value of: startEvent
	// Argument args is an array, and the response object will be the
    // first element in the array.  The response object will have one
    // property: tId (the transaction ID).
    },

	complete:function(eventType, args){
	// do something when completeEvent fires.
	},

	success:function(args){
	// do something when successEvent fires.

	messages = YAHOO.lang.JSON.parse(args.responseText);


	document.getElementById("nexstar_classifieds_contact_form").style.display = 'none';
    document.getElementById("nexstar_classifieds_contact_response").innerHTML = messages.message;
	},

	failure:function(eventType, args){
	// do something when failureEvent fires.
    document.getElementById("nexstar_classifieds_contact_response").innerHTML = '<div style="padding-top: 20px; text-align: center; width: 100%;">There was an error with your submission.  Please try again.</div>';
	},

	// Define this event handler for file upload transactions *only*.
	// This handler will not be used for any other transaction cases.
	upload:function(eventType, args){
	// do something when uploadEvent fires.
	},

	abort:function(eventType, args){
	// do something when abortEvent fires.
	}
};

/*
 * This example shows how to subscribe to all custom events fired at the
 * Connection Manager level.  When subscribed, the custom event will fire
 * for all transactions.
 */

// Subscribe to all custom events fired by Connection Manager.
// Pass in the *globalEvents* object as the second argument to provide
// the necessary scope correction for any usage of the *this* keyword
// in any of the handler functions.
YUC.startEvent.subscribe(handleEvents.start, handleEvents);
YUC.completeEvent.subscribe(handleEvents.complete, handleEvents);

// This event will not fire for file upload transactions.  Instead,
// subscribe to the uploadEvent.
YUC.successEvent.subscribe(handleEvents.success, handleEvents);

// This event will not fire for file upload transactions.  Instead,
// subscribe to the uploadEvent.
YUC.failureEvent.subscribe(handleEvents.failure, handleEvents);

// This event is fired only for file upload transactions in place of
// successEvent and failureEvent
YUC.uploadEvent.subscribe(handleEvents.upload, handleEvents);
YUC.abortEvent.subscribe(handleEvents.abort, handleEvents);

/*
 * NOTE: You do not need to pass a callback object to asyncRequest()
 * since your handlers are already subscribed at the Connection
 * Manager level.  The callback object omits any success or failure
 * logic since those cases are already available and subscribed to as
 * custom events.  You can still include callback.success and
 * callback.failure, and they will be processed; but, it will also be
 * a redundant action.
 */

var transaction = YUC.asyncRequest('GET', sUrl, handleEvents, { timeout: 3000 });

}