/*
*************************************************************************
*	Sample of Open Window 												*
*************************************************************************
function openADViewWindow(ad_id, width, height){
	if(ad_id!=0){
		var args = 'width='+(String)(parseFloat(width)+20)+',height='+(String)(parseFloat(height)+20)+',status=0,address=0,resize=0';
		var popwindow = window.open('index.php?view=ad_view&ad_id='+ad_id,'ad_stat', args);
		if(!popwindow){
			alert("Your POP UP Blocker blocking a new window\n\nPlease disable any POP UP Blocker,\nor hold down CNTRL key while clicking on button/link");
		}
	}else{
		alert('Invalid operation !!');
	}
}
*************************************************************************


*************************************************************************
*	Sample of Ajax Usage												*
*************************************************************************
function toggle_user_status(user_id, stat){
	if(user_id!=0 && (stat==0 || stat==1)){
		new ajax ('ajax.php', {postBody: 'method=toggle_user_status&user_id='+user_id+'&stat='+stat, onComplete: toggle_user_status_callback});
		document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		document.getElementById("WAIT").style.display = '';
		document.getElementById("COVER").style.display = '';
		document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	}else{
		alert("Invalid operation. Please try later on !!");
	}
}

function toggle_user_status_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';//$("WAIT").hide();
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			alert("The users status has been changed successfully !!\n\nYou need to refresh this page to see the updated status");
			window.location.reload();
		}else{
			alert("We were not able to process your request\n\nPlease try later on");
		}
	}else{
		alert("We were not able to process your request\n\nPlease try later on");
	}
}
*************************************************************************
*/

/*===========Function For Showing City according to Country=================*/
function showLocation(country_id,city_combo,selected_value){
	
var userVarArray=new Array();
userVarArray[0]=city_combo;
userVarArray[1]=selected_value;


new ajax ('ajax.php', {postBody: 'method=statecitycombolist&country_id='+country_id, onComplete: showLocation_callback,userVariable: userVarArray});
}

function showLocation_callback(request,uservar){
	if(request!=null){
		
		
			
			
			if(request.responseText!=''){
					
									var city_combo=uservar[0];
									var selected_value=uservar[1];
						
							
								
									clearCombo(city_combo,'city');
									cntrl = document.getElementById(city_combo);
									var newOption, NameValuePair;		
									var tmpArr = request.responseText.split("^");
									for(i=0;i<tmpArr.length;i++){
										NameValuePair = tmpArr[i].split("|");
										newOption = new Option();
										newOption.value = NameValuePair[0];
										newOption.text = NameValuePair[1];
										cntrl.options[cntrl.options.length]=newOption;
									}
									if(selected_value!="")
									cntrl.value=selected_value;
									
								
						
			}
			
			
		
	}else{
		alert("We were not able to process your request\n\nPlease try later on");
	}
}

function clearCombo(ComboID,locationtype){
	var cntrl = document.getElementById(ComboID);
	while(cntrl.options.length>0){
		cntrl.options[cntrl.options.length-1] = null;
	}
	var newOption = new Option();
	newOption.value = 0;
	if(locationtype=='state')
	newOption.text = "Select State";
	if(locationtype=='city')
	newOption.text = "Select City";
	cntrl.options[cntrl.options.length]=newOption;
}
/*=====================================================================*/

<!--/*=========================Check User Name and email-->

function emailajax(email)
{
	//alert(email);
	new ajax ('ajax.php', {postBody: 'method=emailajax&email='+email, onComplete: emailajax_callback});

}

function emailajax_callback(request)
{
		if(request!=null)
		{
		
			if(request.responseText!="")
			{
					if(request.responseText=="Yes"){
						document.getElementById("spanemail").innerHTML="This email already exist,try another.";
					}
			
			}
		}
		
}

function usernameajax(username)
{
	//alert(email);
	new ajax ('ajax.php', {postBody: 'method=usernameajax&username='+username, onComplete: usernameajax_callback});

}

function usernameajax_callback(request)
{
		if(request!=null)
		{
		
			if(request.responseText!="")
			{
					if(request.responseText=="Yes"){
						document.getElementById("spaneusername").innerHTML="This user name already exist,try another.";
					}
			
			}
		}
		
}


function passwordmatch(confirmpassword,password)
{
	new ajax ('ajax.php', {postBody: 'method=passwordmatchajax&confirmpassword='+confirmpassword+'&password='+password, onComplete: passwordmatch_callback});

}

function passwordmatch_callback(request)
{
		if(request!=null)
		{
		
			if(request.responseText!="")
			{
					if(request.responseText=="No"){
						document.getElementById("spanpasswordmatch").innerHTML="Password and confirm password does not match.";
					}
			
			}
		}
		
}
							
/**************************************************************************/

function locationOption(id){
	
	if(id==1){
		$('locationOptionTable').show();
	}else{
		$('locationOptionTable').hide();
		$('holidayTable').hide();
		$('anotherDesiredLocation').hide();
		$('thirdDesiredLocation').hide();
	}
	
}

function holidayDisplay(id){
	
	if(id==1){
		$('holidayTable').show();
	}else{
		$('holidayTable').hide();
		$('anotherDesiredLocation').hide();
		$('thirdDesiredLocation').hide();
	}
	
}

function dateOption(id){
	
	if(id==1){
		$('dateOptionTable').show();
	}else{
		$('dateOptionTable').hide();
		$('dateTable').hide();
		$('anotherTravelDate').hide();
		$('thirdTravelDate').hide();
	}
	
}

function dateDisplay(id){
	
	if(id==1){
		$('dateTable').show();
	}else{
		$('dateTable').hide();
		$('anotherTravelDate').hide();
		$('thirdTravelDate').hide();
	}
	
}
function check_valid_date_range(result){
	if(result){
		//==================first date pair==================================   
		var FromVal1 = $('availabledate').value;
		var ToVal1 = $('availabledate_to').value;
	
		if(FromVal1=="" && ToVal1!="" ){
			alert("From date must be entered.");
			return false;
		}
		if(FromVal1!="" && ToVal1=="" ){
			alert("To date must be entered.");
			return false;
		}
		if(FromVal1!="" && ToVal1!="" ){		
			var tmpArrFromDate1 = FromVal1.split("-");
			var tmpArrToDate1 = ToVal1.split("-");
			
			var FromDate = new Date(tmpArrFromDate1[2], tmpArrFromDate1[0]-1, tmpArrFromDate1[1]);
			var ToDate = new Date(tmpArrToDate1[2], tmpArrToDate1[0]-1, tmpArrToDate1[1]);
			
			if(ToDate<=FromDate){		
				alert("To date must be greater than From date\n");
				return false;
			}
		}
		//===================================================================   
		
		//================== compare second pair ============================
		var FromVal2 = $('availabledate2').value;
		var ToVal2 = $('availabledate2_to').value;
	
		if(FromVal2=="" && ToVal2!="" ){
			alert("From date must be entered.");
			return false;
		}
		if(FromVal2!="" && ToVal2=="" ){
			alert("To date must be entered.");
			return false;
		}
		if(FromVal2!="" && ToVal2!="" ){		
			var tmpArrFromDate2 = FromVal2.split("-");
			var tmpArrToDate2 = ToVal2.split("-");
			
			var FromDate2 = new Date(tmpArrFromDate2[2], tmpArrFromDate2[0]-1, tmpArrFromDate2[1]);
			var ToDate2 = new Date(tmpArrToDate2[2], tmpArrToDate2[0]-1, tmpArrToDate2[1]);
			
			if(ToDate2<=FromDate2){		
				alert("To date must be greater than From date\n");
				return false;
			}
		}
		//===================================================================   

		//==================== compare third pair ===========================
		var FromVal3 = $('availabledate3').value;
		var ToVal3 = $('availabledate3_to').value;
	
		if(FromVal3=="" && ToVal3!="" ){
			alert("From date must be entered.");
			return false;
		}
		if(FromVal3!="" && ToVal3=="" ){
			alert("To date must be entered.");
			return false;
		}
		if(FromVal3!="" && ToVal3!="" ){		
			var tmpArrFromDate3 = FromVal3.split("-");
			var tmpArrToDate3 = ToVal3.split("-");
			
			var FromDate3 = new Date(tmpArrFromDate3[2], tmpArrFromDate3[0]-1, tmpArrFromDate3[1]);
			var ToDate3 = new Date(tmpArrToDate3[2], tmpArrToDate3[0]-1, tmpArrToDate3[1]);
			
			if(ToDate3<=FromDate3){		
				alert("To date must be greater than From date\n");
				return false;
			}
		}
		//===================================================================
 	}
	return result;
}



function dateAddExtention(p_Interval, p_Number){
    var thing = new String(); 
    //in the spirt of VB we'll make this function non-case sensitive 
    //and convert the charcters for the coder. 
    p_Interval = p_Interval.toLowerCase();     
    if(isNaN(p_Number)){ 
     
        //Only accpets numbers 
        //throws an error so that the coder can see why he effed up     
        throw "The second parameter must be a number. \n You passed: " + p_Number; 
        return false; 
    } 

    p_Number = new Number(p_Number); 
    switch(p_Interval.toLowerCase()){ 
        case "yyyy": {// year 
            this.setFullYear(this.getFullYear() + p_Number); 
            break; 
        } 
        case "q": {        // quarter 
            this.setMonth(this.getMonth() + (p_Number*3)); 
            break; 
        } 
        case "m": {        // month 
            this.setMonth(this.getMonth() + p_Number); 
            break; 
        } 
        case "y":        // day of year 
        case "d":        // day 
        case "w": {        // weekday 
            this.setDate(this.getDate() + p_Number); 
            break; 
        } 
        case "ww": {    // week of year 
            this.setDate(this.getDate() + (p_Number*7)); 
            break; 
        } 
        case "h": {        // hour 
            this.setHours(this.getHours() + p_Number); 
            break; 
        } 
        case "n": {        // minute 
            this.setMinutes(this.getMinutes() + p_Number); 
            break; 
        } 
        case "s": {        // second 
            this.setSeconds(this.getSeconds() + p_Number); 
            break; 
        } 
        case "ms": {        // second 
            this.setMilliseconds(this.getMilliseconds() + p_Number); 
            break; 
        } 
        default: { 
            throw    "The first parameter must be a string from this list: \n" + 
                    "yyyy, q, m, y, d, w, ww, h, n, s, or ms. You passed: " + p_Interval; 
            return false; 
        } 
    } 
    return this; 
} 
Date.prototype.dateAdd = dateAddExtention; 


function CalculateToDate(FromField, HowManyDays){
	tmparr = $(FromField).value.split("-");
	dt = new Date(tmparr[2], tmparr[0]-1, tmparr[1]);
	dt = dt.dateAdd('d', HowManyDays);
	return dt.getMonth()+"-"+dt.getDay()+"-"+dt.getFullYear();
}



function activityDisplay(id){
	
	if(id==1){
	$('activityTable').show();
	}else{
	$('activityTable').hide();
	}
	
}


function anotherTraveldateDisplay(){
	
	$('anotherTravelDate').toggle();
	
}

function thirdTraveldateDisplay(){
	
	$('thirdTravelDate').toggle();
	
}

function anotherholidayDisplay(){
	
	$('anotherDesiredLocation').toggle();
	
}

function thirdholidayDisplay(){
	
	$('thirdDesiredLocation').toggle();
	
}

function destinationTimeDisplay(val,spanid){
	
	if(val==0)
	$(spanid).hide();
	if(val==1)
	$(spanid).show();
	
}

function checkAllCheckBoxes(){

	if(document.frm_registration.AllInterest.checked){
				for(var i=0;i<document.frm_registration.interest.length;i++){
				document.frm_registration.interest[i].checked=true;
				}
	}else{
				for(var i=0;i<document.frm_registration.interest.length;i++){
				document.frm_registration.interest[i].checked=false;
				}
	}

}

function checkAllPropertyCheckBoxes(){

	if(document.frm_property.AllInterest.checked){
				for(var i=0;i<document.frm_property.feature.length;i++){
				document.frm_property.feature[i].checked=true;
				}
	}else{
				for(var i=0;i<document.frm_property.feature.length;i++){
				document.frm_property.feature[i].checked=false;
				}
	}

}

function showLabelPopup(field){
   
   $('labelPopupDIV').show();
   
   if(field=='skype_id')
   $('labelPopupContent').innerHTML='Your skype address may help communications with other members.';
   if(field=='company')
   $('labelPopupContent').innerHTML='For our statistical data, helps us streamline our product for our members.';
   if(field=='dateofbirth')
   $('labelPopupContent').innerHTML='For our statistical data, helps us streamline our product for our members.';
    if(field=='income')
   $('labelPopupContent').innerHTML='For our statistical data, helps us streamline our product for our members.';
   if(field=='income')
   $('labelPopupContent').innerHTML='For our statistical data, helps us streamline our product for our members.';
   if(field=='country_id')
   $('labelPopupContent').innerHTML='If you would like to receive free weekly emails from us with listings from countries that you would like to visit, input your desired country/ies here.';
    if(field=='city_id')
   $('labelPopupContent').innerHTML='If you would like to receive free weekly emails from us with listings from cities that you would like to visit, input your desired city/ies here';
    if(field=='vacationtime')
   $('labelPopupContent').innerHTML='If you would like to receive free weekly emails from us with listings that match when you are free to vacation, fill in the dates here.';
   if(field=='interest')
   $('labelPopupContent').innerHTML='If you would like to receive free weekly emails from us with listings that match what you want to do when on vacation, fill in these activities here. If there are activities you would like added please contact us, and we will be glad to help.';
   if(field=='detail')
   $('labelPopupContent').innerHTML='Please write a short introduction about yourselves that other members will read when they are looking at your listing. E.g. My name is Jan, and I live together with my partner Bob, our children Jane, 13 and Bill 10, and our two dogs Rover and Roger. We enjoy the outdoors - hiking, skiing and being on the water. We have a neighbour who will happily look after our dogs if you do not wish to - although they are very friendly!';
    if(field=='feature')
   $('labelPopupContent').innerHTML='Please click on the appropriate features located close by. This help other members when they conduct a search.';
    if(field=='title')
   $('labelPopupContent').innerHTML='This appears at the top of your listing page after someone has conducted a search. Examples of titles could be &quot;Great Upper East Side Apartment&quot;, &quot;Ski field on your doorstep&quot; or  &quot;Apartment with view of Tower Bridge&quot;.';
    if(field=='nearest_city')
   $('labelPopupContent').innerHTML='Please put the closest city/town so people can locate your general location on a map.';
    if(field=='propertytype_id')
   $('labelPopupContent').innerHTML='This helps others when searching for a home that suits them. If you have a house but are willing to have people stay in a room, then please fill in two separate listing forms &ndash;one for &quot;house&quot; and the other for &quot;room&quot;. To do this, click on the &quot;add another listing&quot; link, after you have completed this entire section. An identical form will then appear for you to complete.';
    if(field=='latitude')
   $('labelPopupContent').innerHTML='We generate this information from your pin placement. It is used for people conducting a radius search from a certain position.';
    if(field=='longitude')
   $('labelPopupContent').innerHTML='We generate this information from your pin placement. It is used for people conducting a radius search from a certain position.';
   if(field=='details')
   $('labelPopupContent').innerHTML='This is a short blurb about your home for viewers to read.';
   if(field=='memberdetail')
   $('labelPopupContent').innerHTML='Please write a small blurb about yourself and your family. This will be viewed by people viewing your listing, or if you contact another member requesting to stay in their home.';
   if(field=='allavailabledates')
   $('labelPopupContent').innerHTML='Anytime signifies your home is available at anytime, or it is simply easier for someone to email you to enquire about available dates.';
    if(field=='addstate')
   $('labelPopupContent').innerHTML='If your choice is not displayed, please click "add another state", type in your destination and click "add". Then click "refresh states" and your choice will be added to the list on the drop down menu.';
    if(field=='addcity')
   $('labelPopupContent').innerHTML='If your choice is not displayed, please click "add another city", type in your destination and click "add". Then click "refresh states" and your choice will be added to the list on the drop down menu.';
   if(field=='map_popup')
   $('labelPopupContent').innerHTML='Clicking ONCE on the map will reposition the balloon to where your cursor is placed. We recommend using the following procedure to position the balloon on your home.<br> 1. Zoom out using the "-" sign on the left hand side of the map.<br> 2. Click ONCE on the map in the general area of your home.<br> 3. Zoom in using the "+" sign <br> 4. Repeat steps 2&3 until the balloon is at your home location. <br> Because the general public can view this page, we recommend that you place the balloon on a landmark near your home (e.g. park, shopping centre etc), and guide interested members to your exact address by email. If the balloon gets jammed click "continue" at the bottom of the page, then navigate back to this page using the back arrow and try again.';
   
}
	
	

function closeLabelPopupDIV(){
	$('labelPopupDIV').hide();
}


function showPointsPopup(field){
   
   $('pointsPopupDIV').style.left = (Screen.getViewportWidth()/2 - (720/2))+"px";
	$('pointsPopupDIV').style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-600)+"px";
	$('pointsPopupDIV').show();
	$('COVER').show();
	$('COVER').style.height = Screen.getDocumentHeight()+'px';
   
   //$('pointsPopupDIV').show();
   
   if(field=='buyingpoints')
   $('pointsPopupContent').innerHTML="Note 1: Reciplocation deducts 10 account points from your account balance every time points are added or deducted from your account. Therefore you may need to purchase extra account points to allow for this.For example, if you are staying at another member's home and need to purchase 300 points for the exchange, you will need to purchase 320 points to account for the transactions into and out of your account.<br><br>Note 2:At present Reciplocation.com uses the paypal system for the purchase and redemption of account points. If you need to join paypal please click here (link to paypal application form.<br>";
	
	if(field=='sellingpoints')
   $('pointsPopupContent').innerHTML="Reciplocation deducts a 10 account points transaction fee from the amount you withdraw. For example, if you withdraw $300 account points $290 (less paypal fees) will be credited to your bank account.<br>";
																																																																																																																																																									 
  
}

function closePointsPopupDIV(){
	$('pointsPopupDIV').hide();
	$('COVER').hide();
}

function showPointTables(val){
	
	if(val=='buy'){
		$('buytable').toggle();	
		$('saletable').hide();
		$('exchangetable').hide();
	}
	if(val=='sale'){
		$('buytable').hide();	
		$('saletable').toggle();
		$('exchangetable').hide();
	}
	if(val=='exchange'){
		$('buytable').hide();	
		$('saletable').hide();
		$('exchangetable').toggle();
	}
	
}

function showFeedbackPopup(field){
   
  	$('pointsPopupDIV').style.left = (Screen.getViewportWidth()/2 - (720/2))+"px";
	$('pointsPopupDIV').style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-600)+"px";
	$('pointsPopupDIV').show();
	
	if(field=='feedback')
   	$('pointsPopupContent').innerHTML="Feedback will be available shortly. We apologise for the inconvenience. <br>";
	
																																																																																																																																																								 
  
}
//============================add state======================
function popupAddState(country_id)
{
	
window.open("index.php?view=addstate&country_id="+country_id,"Sendphoto","toolbar=0,scrollbars=1,location=0,status=0,menubars=0,resizable=0,width=450,height=200,top=200,left=200,maximize=no"); 

}

function popupMakefeatured(property_id)
{
	
window.open("index.php?view=makefeatured&property_id="+property_id,"Makefeatured","toolbar=0,location=0,status=0,menubars=0,resizable=0,width=580,height=400,top=200,left=200,maximize=no"); 

}


function validateStateAdd(country_id){
	
	var state_name = document.getElementById("state_name").value;
	
	if(state_name==""){
	alert("Please enter a State Name:");
	}else{
	addstateajax(country_id,state_name);
	}

}



function addstateajax(country_id,state_name)
{
	
	new ajax ('ajax.php', {postBody: 'method=state_add&country_id='+country_id+"&state_name="+state_name, onComplete: addstateajax_callback,userVariable: country_id});

}

function addstateajax_callback(request,uservar)
{
		if(request!=null)
		{
		
			if(request.responseText!="")
			{
					
					window.close();
					
			}
		}

		
}
//===========================add state=========================
//============================add city======================
function popupAddCity(state_id)
{
	
window.open("index.php?view=addcity&state_id="+state_id,"Sendphoto","toolbar=0,scrollbars=1,location=0,status=0,menubars=0,resizable=0,width=450,height=200,top=200,left=200,maximize=no"); 

}


function validateCityAdd(state_id){
	
	var city_name = document.getElementById("city_name").value;
	
	if(city_name==""){
	alert("Please enter a City Name:");
	}else{
	addcityajax(state_id,city_name);
	}

}

function addcityajax(state_id,city_name)
{
	
	new ajax ('ajax.php', {postBody: 'method=city_add&state_id='+state_id+"&city_name="+city_name, onComplete: addcityajax_callback,userVariable: state_id});

}

function addcityajax_callback(request,uservar)
{
		if(request!=null)
		{
		
			if(request.responseText!="")
			{
					
					window.close();
					
			}
		}

		
}
//===========================add city=========================

//========= file upload callback ==========
function album_image_upload_done(result, fileName){
	$('div_uploading_wait').hide();
	if(result==1){
		var tr, td;
		tr = $('tbl_uploaded_images').insertRow($('tbl_uploaded_images').rows.length);
		td = tr.insertCell(0);
		td.style.width = "250px";
		td.style.height = "50px";
		td.className = 'tableImage';
		td.innerHTML = "<img style=\"cursor:pointer\" height=\"80\" width=\"100\" align=\"center\" src=\"uploads/propertyimage/small/"+fileName+"\"/>";
		td = tr.insertCell(1);
		td.style.width = "50px";
		td.style.height = "50px";
		td.className = 'tableImage';
		td.align = 'center';
		td.innerHTML = "<img style=\"cursor:pointer\" alt=\"Remove\"  title=\"Remove\" align=\"center\" src=\"images/error_icon.gif\"  onclick=\"del_uploaded_image(this, '"+fileName+"')\"/>";
		$('SaveFileTd').show();
		$('ImageAddLabel').innerHTML="Add Another Image";
		
		}else{
		alert("file not uploaded");
	}
}
//=========================================

function del_uploaded_image(img, fileName){
	new ajax ('ajax.php', {postBody: 'method=delete_uploaded_picture&filename='+fileName, onComplete: del_uploaded_image_callback, userVariable: img});
}

function del_uploaded_image_callback(request, uservar){
	
		if(request!=null)
		{
			if(request.responseText!="")
			{
					if(confirm("Do you really want to remove this attached image?")){
					var img = Element.extend(uservar);
					img.up(1).remove();
					}
			}
		}
}

function uploadFinalImages(){

if(confirm("Do you really want to add these images to your property?"))
document.finalImagePost.submit();
}


function new_image_uploaded(result, img_id, file_name, str_title){
	$('div_uploading_wait').hide();
	if(result==1){
		var tr;
		var td;
		var str_html = "";
		str_html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"  class=\"TableblueBorder\" style=\"background:url(images/image_blue_strip.jpg); background-position:top;\">";
		str_html += "<tr>";
		str_html += "<td width=\"171\" height=\"20\" colspan=\"2\" align=\"center\" class=\"LinkGrayBold\"></td>";
		str_html += "</tr>";
		str_html += "<tr>";
		str_html += "<td height=\"101\" colspan=\"2\" align=\"center\"><a href=\"uploads/propertyimage/large/"+file_name+"\" class=\"lightwindow\"><img src=\"uploads/propertyimage/small/"+file_name+"\" alt=\"\" width=\"120\" height=\"90\" border=\"0\" class=\"TableBlackBorder\" /></a></td>";
		str_html += "</tr>";
		str_html += "<tr>";
		str_html += "<td height=\"18\" colspan=\"2\" align=\"center\" class=\"orangeFontSmall\">"+str_title+"</td>";
		str_html += "</tr>";
		str_html += "<tr>";
		str_html += "<td height=\"18\" align=\"center\" class=\"orangeFontSmall\">";
		str_html += "<a href=\"javascript:confirmInactive("+img_id+")\" class=\"orangeBlueSmallUnderline\">Make Inactive</a>";
		str_html += "&nbsp;&nbsp;&nbsp;</td>";
		str_html += "<td align=\"center\" class=\"orangeFontSmall\"><input type=\"checkbox\" name=\"propertyimage_id[]\" id=\"propertyimage_id\" value=\""+img_id+"\" /></td>";
		str_html += "</tr>";
		str_html += "<tr>";
		str_html += "<td colspan=\"2\" align=\"center\">&nbsp;</td>";
		str_html += "</tr>";
		str_html += "</table>";     
		if((TotalImageCount%3)==0){
			tr = $('tbl_existing_images').insertRow($('tbl_existing_images').rows.length);
		}else{
			tr = $('tbl_existing_images').rows[$('tbl_existing_images').rows.length-1];
		}
		td = tr.insertCell(tr.cells.length);
		td.innerHTML = str_html;
		TotalImageCount++;
	}else{
		alert('Image upload failed !! Try another image');
	}
}

function get_cities(country_id, state_id, StateDropDown, CityDropDown, CountryDropDown){
	if(country_id==0 && state_id==0){
		var cmbState = $(StateDropDown);
		var cmbCity = $(CityDropDown);
		
		if($(CountryDropDown).selectedIndex==0){	
				/*================= Clear previous loaded states ==============*/
				tmp = cmbState.options.length;
				for(i=0; i<tmp; i++){
					cmbState.options[0] = null;
				}
				/*=============================================================*/
				var optn = new Option();
				optn.value = 0;
				optn.text = "Select State";
				cmbState.options[0]=optn;
				/*================= Clear previous loaded cities ==============*/
		}
		
		tmp = cmbCity.options.length;
		for(i=0; i<tmp; i++){
			cmbCity.options[0] = null;
		}
		optn = new Option();
		optn.value = 0;
		optn.text = "Select City";
		cmbCity.options[0]=optn;
		/*=============================================================*/
	}else{
		new ajax ('ajax.php', {postBody: 'method=get_cities&state_id='+state_id+"&country_id="+country_id, onComplete:get_cities_callback, userVariable: Array(StateDropDown, CityDropDown)});
	}
}

function get_cities_callback(request, uservar){
	if(request!=null){
		if(request.responseText.isJSON()){
			response = request.responseText.evalJSON();
			var StateDropDown = $(uservar[0]);
			var CityDropDown = $(uservar[1]);
			var i;
			var tmp;
			var optn;
			
			if(parseInt(response.refresh_state)==1){
				/*================= Clear previous loaded states ==============*/
				tmp = StateDropDown.options.length;
				for(i=0; i<tmp; i++){
					StateDropDown.options[0] = null;
				}
				optn = new Option();
				optn.value = 0;
				optn.text = "Select State";
				StateDropDown.options[0]=optn;
				/*=============================================================*/
				/*====================== Load new states ======================*/
				for(i=0; i<response.states.length; i++){
					optn = new Option();
					optn.value = response.states[i].state_id;
					optn.text = response.states[i].state_name;
					StateDropDown.options[StateDropDown.options.length] = optn;
				}
				/*=============================================================*/
			}
			/*================= Clear previous loaded cities ==============*/
			tmp = CityDropDown.options.length;
			for(i=0; i<tmp; i++){
				CityDropDown.options[0] = null;
			}
			optn = new Option();
			optn.value = 0;
			optn.text = "Select City";
			CityDropDown.options[0]=optn;
			/*=============================================================*/
			/*====================== Load new Cities ======================*/
			for(i=0; i<response.cities.length; i++){
				optn = new Option();
				optn.value = response.cities[i].city_id;
				optn.text = response.cities[i].city_name;
				CityDropDown.options[CityDropDown.options.length] = optn;
			}
			/*=============================================================*/
		}else{
			alert("We were not able to communicate with the server. Please try after sometime");
		}
	}else{
		alert("Could not connect to server. Please try later on");
	}
}