function displayTextForm(obj,companyID,formFile,paidListing,companyName) {
	Element.show(obj);
	var fixURL = fixURI(formFile);
	var numberObj = companyID + '_to_mobile';
	var description = '';
	var smsNumber = readCookie('sms_number');
	if (companyName != undefined) { description = '<b>Send details of <i>'+ companyName +'</i>\'s listing direct to your mobile!</b><br>'; }
	var myHTML = description +'<span class="enter_number">Please enter a valid mobile number:- </span>';
	myHTML += '<input id="'+ numberObj +'" type="text" name="mobile_number" size="14" class="text_number" value="'+ smsNumber +'" />';
	myHTML += hoverImage(companyID + '_send','sms.gif','sms-over.gif',fixURL);
	myHTML += hoverImage(companyID + '_cancel','cancel.gif','cancel-over.gif',fixURL);
	$(obj).innerHTML = wrapOutput(myHTML,paidListing);
   Event.observe(companyID + '_send', 'click', function(){sendText(obj,formFile,numberObj,companyID,paidListing)});
	Event.observe(companyID + '_cancel', 'click', function(){hide(obj)});
}

function sendText(obj,formFile,numberObj,companyID,paidListing) {
	var mobileNumber = Form.Element.getValue(numberObj);
	var myHTML = '<span class="enter_number">Attempting to send company details to your mobile...<br><br>If you see this message for more than 2 minutes then there may be problems with the network.  If this is the case, please click on the listing\'s "text" button to try again.</span>';
	$(obj).innerHTML = wrapOutput(myHTML,paidListing);
	var success = function(t){messageSent(t,obj,formFile,companyID,paidListing);};
	var failure = function(){hide(obj);};
	var url = formFile;
	var pars = 'mobile_number='+ mobileNumber +'&company_id='+ companyID;
	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars,onSuccess:success,onFailure:failure});
}

function messageSent(t,obj,formFile,companyID,paidListing) {
	var fixURL = fixURI(formFile);
	var hideObj = companyID + '_cancel';
	var myHTML = t.responseText +'<br>'+ hoverImage(hideObj,'sms_close.gif','sms_close-over.gif',fixURL);
	$(obj).innerHTML = wrapOutput(myHTML,paidListing);
	Event.observe(hideObj, 'click', function(){hide(obj)}, false);
}

function wrapOutput(myHTML,paidListing) {
	if (paidListing) {
		return '<div class="address-bottom"><div class="address-top">'+ myHTML + '</div></div>';
	} else {
		return myHTML;
	}
}

function hide(obj) {
	Element.hide(obj);
}

function fixURI(myURL) {
	if (myURL.slice(0,2) == './') {
		return './';
	} else {
		return '../';
	}
}

function loadInline(url,obj) {
	Element.show(obj);
	$(obj).innerHTML = "Loading, please wait...";
	var myAjax = new Ajax.Updater(obj, url);
}

function hoverImage(id,mainImg,hoverImg,fixURL) {
	return '<img id="'+ id +'" src="'+ fixURL +''+ mainImg +'" onmouseover="this.src=\''+ fixURL +''+ hoverImg +'\'" onmouseout="this.src=\''+ fixURL +''+ mainImg +'\'" style=\"cursor:pointer;cursor:hand;\" />';
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

