function openprice(status,id) {
	
	if(status == 0)
		document.getElementById(id).disabled = false;
	if(status == 1)
		document.getElementById(id).disabled = true;	
}

function openbox(id) {
	
	var value = document.getElementById(id).disabled;
	if(value == false)
		document.getElementById(id).disabled = true;
	if(value == true)
		document.getElementById(id).disabled = false;	
}

function changeProvince(provCtrl, countryCtrl, cindex,id) {
	
	var indexv = countryCtrl.options[cindex].value;
	
	var data = 'code='+escape(indexv);
	var url = 'ajxpro?cache=' + (new Date()).getTime();
	var prov = [];

	window.httpInstance = createXMLHTTPObject();
		
	if(window.httpInstance) {
			
		window.httpInstance.onreadystatechange = function()
		{
			if (window.httpInstance.readyState == 4 && window.httpInstance.status == 200)
			{
				for (i = provCtrl.options.length; i >= 0; i--) {
    					provCtrl.options[i] = null; 
  				}
			 	var prov_xml = window.httpInstance.responseXML;
			  	var pxml = prov_xml.getElementsByTagName("item");
			 
			 	for (var i = 0; i < pxml.length; i++){
			 
			 		prov[i] = new Array(pxml[i].getElementsByTagName("iso")[0].firstChild.nodeValue,
			 						pxml[i].getElementsByTagName("name")[0].firstChild.nodeValue
			 						);
			 	}
			
				if(pxml.length > 0) {

	
					document.getElementById('prov').disabled = false;
									
  					/*for (i = provCtrl.options.length; i >= 0; i--) {
  						
    					provCtrl.options[i] = null; 
  					}*/
  					
  					var y = '';
  					for (i = 0; i < prov.length; i++) {
  						
  						if(id == 1) {
  							
  							y += '<OPTION value="" selected>All provinces</OPTION>'+
								 '<OPTION value="">---</OPTION>';
							y+= '<option value='+prov[i][0]+'>'+prov[i][1].replace('&amp;','&')+'</option>';	  
  							//provCtrl.options[i] = new Option(prov[i][1]);
  							//provCtrl.options[i].value = prov[i][0];
  						
  						} else {
  							
  							y+= '<option value='+prov[i][0]+'>'+prov[i][1].replace('&amp;','&')+'</option>';
  							//provCtrl.options[i] = new Option(prov[i][1]);
  							//provCtrl.options[i].value = prov[i][0];
  						}
  							
  							id = -1;	
  					}
  	  					
  					if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1 || navigator.userAgent.indexOf("Opera")!=-1) {
								provCtrl.innerHTML = y;
					}
						
					if (navigator.userAgent.indexOf("MSIE")!=-1) {

							var iy = '<select id="prov" name="s">'+
								'<optgroup label="Provinces">';

  							provCtrl.outerHTML = iy+y+'</optgroup></select>';
					}  		
  					
  				
				} else {
				
					document.getElementById('prov').disabled = true;		
				}	
  			}
		}
			window.httpInstance.open('POST', url , true);
			window.httpInstance.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			window.httpInstance.setRequestHeader('Content-length', data.length);
			window.httpInstance.setRequestHeader('Connection', 'close');
			window.httpInstance.send(data);
	}			
	else {

	}
}

function changePostProvince(provCtrl, countryCtrl, cindex) {
	
	var indexv = countryCtrl.options[cindex].value;
	
	var data = 'code='+escape(indexv);
	var url = 'ajxpro?cache=' + (new Date()).getTime();
	var prov = [];

	window.httpInstance = createXMLHTTPObject();
		
	if(window.httpInstance) {
			
		window.httpInstance.onreadystatechange = function()
		{
			if (window.httpInstance.readyState == 4 && window.httpInstance.status == 200)
			{
				
			 	var prov_xml = window.httpInstance.responseXML;
			  	var pxml = prov_xml.getElementsByTagName("item");
			 
			 	for (var i = 0; i < pxml.length; i++){
			 
			 		prov[i] = new Array(pxml[i].getElementsByTagName("iso")[0].firstChild.nodeValue,
			 						pxml[i].getElementsByTagName("name")[0].firstChild.nodeValue
			 						);
			 	}
			
				if(pxml.length > 0) {

	
					document.getElementById('prov').disabled = false;
									
  					/*for (i = provCtrl.options.length; i >= 0; i--) {
  						
    					provCtrl.options[i] = null; 
  					}*/
  					
  					var y = '';
  					
  					for (i = 0; i < prov.length; i++) {
  													
  						y+= '<option value='+prov[i][0]+'>'+prov[i][1].replace('&amp;','&')+'</option>';
	
  					}
  	  					
  					if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1 || navigator.userAgent.indexOf("Opera")!=-1) {
								provCtrl.innerHTML = '<OPTION value="" selected>-- Select Province --</OPTION>'+y;
					}
						
					else if (navigator.userAgent.indexOf("MSIE")!=-1) {

							for (i = provCtrl.options.length; i >= 0; i--) {
  						
    								provCtrl.options[i] = null; 
  							}
							var iy = '<select id="prov" name="ad_province">'+
								'<OPTION value="" selected>-- Select Province --</OPTION>'+
								'<optgroup label="Provinces">';

  							provCtrl.outerHTML = iy+y+'</optgroup></select>';
					}else {
						
						provCtrl.innerHTML = '<OPTION value="" selected>-- Select Province --</OPTION>'+y;
					}  		
  					
  				
				} else {
				
					document.getElementById('prov').disabled = true;		
				}	
  			}
		}
			window.httpInstance.open('POST', url , true);
			window.httpInstance.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			window.httpInstance.setRequestHeader('Content-length', data.length);
			window.httpInstance.setRequestHeader('Connection', 'close');
			window.httpInstance.send(data);
	}			
	else {

	}
}

function createXMLHTTPObject()
{
	//var httpObj = false;
		
	if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		var axo = ['Microsoft.XMLHTTP', 
				'MSXML2.XMLHTTP',
				'MSXML2.XmlHttp.3.0',
				'MSXML2.XmlHttp.4.0',
				'MSXML2.XmlHttp.5.0'
			];

		for (var i = axo.length - 1; i > -1; i--)
		{
			try
			{
				httpObj = new ActiveXObject(axo[i]);
				return httpObj;
			}
			catch(e) {}
		}
	}

	//throw new Error('XMLHTTP not supported');
	
}



function deleteAd(loc) {
	
	var response = confirm('Are you sure you want to delete this ad?');
	
	if(response == true)
		window.location = loc;
	
}
function reportAd(typ,id,tid) {
	
	var response = confirm('Report this ad as '+typ+'?');
	
	if(response == true)
		window.location = 'view_ad?rep='+id+'&typ='+tid;
	
}