function ins(prop,type,what)
{
if (what == 1)
{
var input = document.newadd.body;
}
else if (what == 0)
{
var input = document.editadd.body;
}
var mysel;var text;
if (window.getSelection) mysel = window.getSelection();
else if (document.selection) mysel = document.selection.createRange().text;
else if (document.getSelection) mysel = document.getSelection();
b = (type == 0) ? '<'+prop+'>' : prop;
if (prop != 'br')
{
e = (type == 0) ? '</'+prop+'>' : '';
}
if (input.createTextRange)
{
var text;
input.focus(input.caretPos);
input.caretPos = document.selection.createRange().duplicate();
input.caretPos.text = (input.caretPos.text.length>0) ? b + input.caretPos.text + e : b + mysel + e;
}
else 
{
if (prop != 'br')
{
input.value += b + mysel + e;
}
else
{
input.value += b + mysel
} 
}
}

function list_prov(i)
{
var ind = i;
var b = document.getElementById('province').value;
window.open ('index.php?action=venue_view&p='+b+'&venue_ind='+ind,'_self',false);
}

function list_venue_ind(i)
{
var ind = i;
var p = document.getElementById('province').value;
window.open('index.php?action=venue_view&venue_ind='+i+'&p='+p, '_self',false);  
}

function venues_search()
{
var search = document.getElementById('search').value;
var prov = document.getElementById('province').value;
window.open('index.php?action=venues_search&search='+search+'&p='+prov, '_self', false);
}

function formCheck(form) {
if (form.subject.value == "") {
alert("Please enter your subject");
return false;
}
if (form.message.value == "") {
alert("Please enter your message");
return false;
}
if (document.form.submit.action != "") {
document.form.submit.disabled=1;
}
}

function countclick(link)
{
var linka = link;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
 {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","click_count.php?q="+linka, true);
xmlhttp.send();
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function remove_upload()
{
var file=getCookie("CM");
if (file!=null && file!="")
{
setCookie("CM","",-180); 
}
document.getElementById('upl').innerHTML = '';
document.getElementById('upl_button').style.display = "block";
}

function listcat()
{
var a = document.getElementById('catsearch').value;
if (document.getElementById('provsearch'))
{
var b = document.getElementById('provsearch').value;
}
if (a == '' || a == null)
{
return false;
}
if (a != 99)
{
if (document.getElementById('provsearch'))
{
ajaxpage('add_functions.php?action=selcat&selcat='+a+'&province='+b, 'selectedcat', '2');
}
else
{
ajaxpage('add_functions.php?action=selcat&sa=place&selcat='+a, 'selectedcat', '2'); 
}  
}
else if (a == 99)
{
document.getElementById('selectedcat').innerHTML = '';
}
}

function goBack()
{
window.history.back()
}

function goBack2()
{
window.history.go(-2)
} 
function goBack3()
{
window.history.go(-3)
} 

function validate_ad_1()
{
var x = 'newadd';
var b = document.getElementById('addheading').value;
var a = document.getElementById('type').value;
var c = document.getElementById('price').value;
var d = document.getElementById('body').value;
var e = document.getElementById('province').value;
if (b == '' || b == null || a == null || a == '' || a == '0' || c == '' || c == null || d == '' || d == null || e == '' || e == null || e == '0')
{
alert('Your ad has to be complete before you can upload an image.');
return false;
}
}
