jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}



$(document).ready(function(){
	
	/////////////////
		//property files///////
		//////////////////////

	$("#city, #type, #min, #max, #beds").change(function(){
		var s_select = $(this).attr('id');
			
			var city = $('#city').val();
			var type = $('#type').val();
			
			if(window.location.pathname=="/serviced-apartments/"){
				//update town/areas dropdown
				$.getJSON("/js/selects.php",{city:city, s_select:s_select, ajax: 'true'}, function(j){
					var options = '';
					for (var i = 0; i < j.length; i++) {
						options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
					}
					$("#town").html(options);
				})
			}else{
				var url = window.location.pathname;
				//update minimum
				$.getJSON("/js/selects.php",{type: type, url:url, s_select:s_select, ajax: 'true'}, function(j){
					var options = '';
					for (var i = 0; i < j.length; i++) {
						options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
					}
					$("#town").html(options);
				})
			}
		
		
	})
	
	$("#country").change(function(){
		var s_select = $(this).attr('id');
			
			var country = $('#country').val();
			var city = $('#city').val();	
			
			//update town/areas dropdown
			$.getJSON("/js/selects.php",{country:country, s_select:s_select, ajax:'true'}, function(j){
				var options = '';
				for (var i = 0; i < j.length; i++) {
					options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
				}
				$("#city").html(options);
			})
			
			
			$.getJSON("/js/selects.php",{country:country, s_select:'country-city', ajax:'true'}, function(j){
				var options = '';
				for (var i = 0; i < j.length; i++) {
					options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
				}
				$("#town").html(options);
			})
			
		
		
	})


	$(".unit .plus").click(function () {
		$(this).parent().find("div:first").slideToggle('medium');
		return false;
	});
	
	setTimeout(function(){ $(".success").fadeOut(500);}, 3000);
					   
	//$('#nav ul li a').corners("5px transparent");
	$('#header, #headerInternal').cycle({ 
		fx:    'fade', 
		speed:  1800, //speed of transition
		timeout: 3500, //how long the image stays for
		cleartypeNoBg:  true
	
	 });
	
	/*$(".type-choice1").click(function(){
		$("#perDiv").fadeIn(500);
		$("#per option:eq(1)").attr("selected","selected");
		
	return false; 
	})*/
	
	$("#s_type").change(function(){
		if($("#s_type").val()=="serviced apartment"){
			$("#perDiv").fadeIn(500);
			$("#priceDiv").fadeIn(500);
			$("#priceFrom").fadeIn(500);
			$("#propertyDiv").fadeIn(500);
			$("#minStayDiv").fadeIn(500);
			
			$("#per option:eq(1)").attr("selected","selected");
			$("#minStay option:eq(1)").attr("selected","selected");
			$("#price").val("");
			$("#bedrooms").val("");
			$("#flats").val("");
			
			$("#bedroomsDiv").hide();
			$("#flatsDiv").hide();
		}else if($("#s_type").val()=="long-term letting"){
			$("#perDiv").fadeIn(500);
			$("#priceDiv").fadeIn(500);
			$("#priceDiv").fadeIn(500);
			
			$("#per option:eq(1)").attr("selected","selected");
			$("#minStay option:eq(0)").attr("selected","selected");
			$("#price").val("");
			$('input[name=property]').attr('checked', false);
			
			$("#priceFrom").fadeOut(500);
			$("#propertyDiv").fadeOut(500);
			$("#minStayDiv").fadeOut(500);
		}else if($("#s_type").val()=="sale"){
			$("#priceDiv").fadeIn(500);
			
			$("#price").val("");
			$("#per option:eq(0)").attr("selected","selected");
			$("#minStay option:eq(0)").attr("selected","selected");
			$('input[name=property]').attr('checked', false);
			
			$("#priceFrom").fadeOut(500);
			$("#perDiv").fadeOut(500);
			$("#propertyDiv").fadeOut(500);
			$("#minStayDiv").fadeOut(500);
		}else if($("#s_type").val()=="none"){
			$("#price").val("");
			$("#per option:eq(0)").attr("selected","selected");
			$('input[name=property]').attr('checked', false);
			$("#minStay option:eq(0)").attr("selected","selected");
			
			$("#perDiv").fadeOut(500);
			$("#priceDiv").fadeOut(500);
			$("#priceFrom").fadeOut(500);
			$("#propertyDiv").fadeOut(500);
			$("#minStayDiv").fadeOut(500);
		}
		//$("#perDiv").fadeIn(500);
		//$("#per option:eq(1)").attr("selected","selected");
		
	return false; 
	})
	
	$("#type, #s_type").change(function(){
		if($("#type").val()=="site" && $("#s_type").val()=="serviced apartment"){
			$("#propertyDiv").fadeIn(500);
			
			$("#bedrooms").val("");
			$("#flats").val("");
			
			$("#flatsDiv").hide();
			$("#bedroomsDiv").hide()
		}
		
		if($("#type").val()=="site" && $("#s_type").val()!="serviced apartment"){
			$("#flatsDiv").fadeIn(500);
			
			$("#bedrooms").val("");
			$("#flats").val("");
			$('input[name=property]').attr('checked', false);
			
			$("#propertyDiv").hide();
			$("#bedroomsDiv").hide()
		}
		
		if($("#type").val()!="site" && $("#s_type").val()!="serviced apartment"){
			$("#bedroomsDiv").fadeIn(500);
			
			$("#bedrooms").val("");
			$("#flats").val("");
			$('input[name=property]').attr('checked', false);
			
			$("#propertyDiv").hide();
			$("#flatsDiv").hide()
		}
		
	return false; 
	})
	
	

	
	
	$("#editProp").click(function(){
		$("#editableProps").slideToggle(700);	
	return false; 
	})
	
	$("#toggleCurrency").click(function(){
		$("#currency").slideToggle(250);	
	return false; 
	})
	
	var currentUrl = window.location.pathname;
	if(currentUrl=="/serviced-apartments/" || currentUrl=="/long-term-lettings/" || currentUrl=="/sales/"){
		$("#content tr.propList").quickpaginate({ perpage: 4, showcounter: true, pager : $(".counter") });
	}
	
	var terms_prop = $('#upload_tc_prop'), interval;
		new AjaxUpload(terms_prop,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'tc',
				pid : $('#pid').val()
			},
			onSubmit : function(file, ext){
				// change terms6 text, when user selects file			
				terms_prop.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload terms6
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = terms_prop.text();
					if (text.length < 13){
						terms_prop.text(text + '.');					
					} else {
						terms_prop.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				terms_prop.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload terms6
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#tcfiles_prop').text(file);						
			}
		});	
		
		var floorplan_prop = $('#upload_floorplan_prop'), interval;
		new AjaxUpload(floorplan_prop,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'floorplan',
				pid : $('#pid').val()
			},
			onSubmit : function(file, ext){
				// change floorplan6 text, when user selects file			
				floorplan_prop.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload floorplan6
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = floorplan_prop.text();
					if (text.length < 13){
						floorplan_prop.text(text + '.');					
					} else {
						floorplan_prop.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				floorplan_prop.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload floorplan6
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#floorplanfiles_prop').text(file);						
			}
		});
		///////////////
		


	$("input[name='tp_type']").live('click', function(){
		var type = $(this).val();
		
		if(type=='London Underground'){
			$.post("/js/transport.php", {action:'underground'}, function(data){ 
				$('#tp_div').empty();
				$('#tp_div').append(data);
			});
			
		}else if(type=='First Capital Connect'){
			$.post("/js/transport.php", {action:'fcc'}, function(data){ 
				$('#tp_div').empty();
				$('#tp_div').append(data);
			});
			
		}else if(type=='other'){
			$.post("/js/transport.php", {action:'underground'}, function(data){ 
				$('#tp_div').empty();
				$('#tp_div').append('<strong>Train service (eg, London Underground, Virgin Trains etc)</strong><br/><input type="text" id="tp_type_custom" class="field1" /><br/><strong>Train station</strong><br/><input type="text" id="tp_station_custom" class="field1" /> <a href="#" style="font-size:10px;" onclick="tp_custom(\'train\'); return false;">save</a>');
			});
		
		}else{
			$.post("/js/transport.php", {action:'underground'}, function(data){ 
				$('#tp_div').empty();
				$('#tp_div').append('<strong>Train service</strong><br/><input value="'+stripslashes(type)+'" disabled="disabled" type="text" id="tp_type_custom" class="field1" /><br/><strong>Train station</strong><br/><input onkeyup="get_station();" type="text" id="tp_station_custom" class="field1" /> <a href="#" style="font-size:10px;" onclick="tp_custom(\'train\'); return false;">save</a>');
			});
		}
	})
	
	$("#tp_station").livequery('change',function (){
		var station = $(this).val();
		$.post("/js/transport.php", {action:'save', station: station}, function(data){ 
			$('#tp_div').empty();
			
			if(data==1){
				$('#tp_div').append('Transport link successfully added. Please wait for transport to be updated...');
				setTimeout(function(){ 
					$('#tp_div').empty(); 
					$('#tp_div').append('<label><input type="radio" name="tp_mode" onclick="tpmode(\'train\');" value="train" /> Train</label><br /><label><input type="radio" name="tp_mode" onclick="tpmode(\'plane\');" value="plane" /> Plane</label>');
					tpupdate();
				}, 2000);
				
				
				$('#tp_cancel').hide();
			}else{
				$('#tp_div').append(data);
			}
		});
	})

}); //document.ready close

function tpupdate(){
	$.post("/js/transport.php", {action:'update_tp_links'}, function(data){ 
		$('#tp_links').empty();
		$('#tp_links').append(data);
	});
	
}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}
function save_unit(uid, type){
	
	tinyMCE.triggerSave(true, true);
	var title = $("#title"+uid).val();
	var price = $("#price"+uid).val();
	var description = $("#description"+uid).val();
	var facilities = $("#facilities"+uid).val();
	
	if(type==1){	
		$("#unitAdmin"+uid).empty();
		$("#unitAdmin"+uid).append("Saving Unit...");
		
		$.post("update_unit.php", {title:title, price:price, description:description, facilities:facilities, uid:uid}, function(data){ 
			setTimeout(function(){ $("#unitAdmin"+uid).remove(); }, 1000)
		});
	}else if(type==2){
		$("#unitAdmin"+uid+" .unitRight").append("<p class=\"saving\">Saving Unit...</p>");
		
		$.post("update_unit.php", {title:title, price:price, description:description, facilities:facilities, uid:uid}, function(data){ 
			setTimeout(function(){ $(".saving").remove(); }, 1000);
		});
	}
}

function get_airport(){
	var airport = $('#tp_station_custom').val();
	$.post("/js/transport.php", {action:'suggest_airport', airport:airport}, function(data){ 
			
			$('#suggest').remove();
			$('#tp_div').append(data);
			
	});
}

function get_station(){
	var type = $('#tp_type_custom').val();
	var station = $('#tp_station_custom').val();
	$.post("/js/transport.php", {action:'suggest_station', type:type, station:station}, function(data){ 
			
			$('#suggest').remove();
			$('#tp_div').append(data);
			
	});
}

function fill_field(string){
	$('#tp_station_custom').val(string);
	$('#suggest').remove();
}


function tpmode(tp){
	
	$('#tp_cancel').show();
	if(tp=='train'){
		$.post("/js/transport.php", {action:tp}, function(data){ 
			$('#tp_div').empty();
			$('#tp_div').append(data);
			
		});
		
	}else if(tp=='plane'){
		$.post("/js/transport.php", {action:tp}, function(data){ 
			$('#tp_div').empty();
			$('#tp_div').append('<strong>Airport (eg, Luton, Heathrow etc)</strong><br/><input onkeyup="get_airport()"; type="text" id="tp_station_custom" class="field1" /><a href="#" style="font-size:10px;" onclick="tp_custom(\'plane\'); return false;">save</a>');
			
		});
	}
}

function tpcancel(){
	$.post("/js/transport.php", {action:'cancel'}, function(data){ 
		$('#tp_div').empty();
		$('#tp_div').append('<label><input type="radio" name="tp_mode" onclick="tpmode(\'train\');" value="train" /> Train</label><br /><label><input type="radio" name="tp_mode" onclick="tpmode(\'plane\');" value="plane" /> Plane</label>');
		
		$('#tp_cancel').hide();
		
	});
}

function tpdelete(tid){
	$.post("/js/transport.php", {action:'delete', tid:tid}, function(data){ 
		tpupdate();		
	});
}

function tp_custom(transport){
	
	var type = $("#tp_type_custom").val();
	var station = $("#tp_station_custom").val();
	
	$.post("/js/transport.php", {action:'custom_'+transport, type:type, station:station}, function(data){ 
		//$('#tp_div').empty();
		if(data==1){
				$('#tp_div').empty();
				$('#tp_div').append('Transport link successfully added. Please wait for transport to be updated...');
				setTimeout(function(){ 
					$('#tp_div').empty(); 
					$('#tp_div').append('<label><input type="radio" name="tp_mode" onclick="tpmode(\'train\');" value="train" /> Train</label><br /><label><input type="radio" name="tp_mode" onclick="tpmode(\'plane\');" value="plane" /> Plane</label>');
				}, 2000)
				$('#tp_cancel').hide();
				tpupdate();
			}else{
				$('#tp_div').append(data);
			}
			
		
	});
}

function delete_unit(uid){
	
	var title = $("#title"+uid).val();
	var price = $("#price"+uid).val();
	var description = $("#description"+uid).val();

	$("#unitAdmin"+uid).empty();
	$("#unitAdmin"+uid).append("Deleting Unit...");
	
	$.post("delete_unit.php", {uid:uid}, function(data){ 
		setTimeout(function(){ $("#unitAdmin"+uid).remove(); }, 1000)
	});
	
}

function feature_property(pid){
	
	if($('#featured'+pid).is(":checked")){
		$.post("feature_property.php", {pid:pid, feature:1}, function(data){ 
			//setTimeout(function(){ $("#unitAdmin"+uid).remove(); }, 1000)
			$('#featured'+pid).parent().addClass('featured');
		});
	}else{
		$.post("feature_property.php", {pid:pid, feature:0}, function(data){ 
			//setTimeout(function(){ $("#unitAdmin"+uid).remove(); }, 1000)
			$('#featured'+pid).parent().removeClass('featured');
		});
	}
}

function sort_props(filter){
	
		$(".propListSearch tbody").empty();
		$.post("/includes/search.php", {filter:filter, session:true}, function(data){ 
			$(".propListSearch tbody").append(data);
		});
	return false;
}

function getQueryString(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

function units(obj, unit_type, pid){

	
	if($(obj).is(':checked')){
		$.post("/admin/property/add_new_unit.php", {title: unit_type, pid:pid}, function(data){ 				
				$('#unitsDiv').empty();
				$('#unitsDiv').append(data);
				
				var sURL = getQueryString('pid');
				window.location.href = sURL;


				var editors = document.getElementsByTagName('textarea');
				for(var i = 0; i < editors.length; i++){
					//alert(editors[i].className);
					if(editors[i].className == 'field2 wysiwyg'){
						var id = editors[i].getAttribute('id');
							tinyMCE.execCommand('mceAddControl',true,id);
						
					}
				}
				
				//tinyMCE.execCommand("mceAddControl", true, div);
				
		});
	}else{
		var answer = confirm("Are you sure you want to remove this unit? Doing so, will erase all unit details and you will need to enter them again.\n\nClick ok to remove unit or cancel to keep the unit.");
		if(answer){
			$("#"+unit_type).parent().remove();
			
			$.post("/admin/property/delete_unit2.php", {pid: pid, title:unit_type}, function(data){ 
				var sURL = getQueryString('pid');
				window.location.href = sURL;
			});
		}else{
			$(obj).attr('checked', true);	
		}
	}
	
}

var currentUrl = window.location.pathname;
function uploadables(){
if(currentUrl=='/admin/property/edit.php' || currentUrl=='/admin/property/addUnit.php'){
		var terms1 = $('#upload_tc1'), interval;
		new AjaxUpload(terms1,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'tc',
				uid : $('#uid1').val()
			},
			onSubmit : function(file, ext){
				// change terms1 text, when user selects file			
				terms1.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload terms1
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = terms1.text();
					if (text.length < 13){
						terms1.text(text + '.');					
					} else {
						terms1.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				terms1.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload terms1
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#tcfiles1').text(file);						
			}
		});
		
		var floorplan1 = $('#upload_floorplan1'), interval;
		new AjaxUpload(floorplan1,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'floorplan',
				uid : $('#uid1').val()
			},
			onSubmit : function(file, ext){
				// change floorplan1 text, when user selects file			
				floorplan1.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload floorplan1
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = floorplan1.text();
					if (text.length < 13){
						floorplan1.text(text + '.');					
					} else {
						floorplan1.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				floorplan1.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload floorplan1
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#floorplanfiles1').text(file);						
			}
		});
		
		///////
		//////
		//////
		
		var terms2 = $('#upload_tc2'), interval;
		new AjaxUpload(terms2,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'tc',
				uid : $('#uid2').val()
			},
			onSubmit : function(file, ext){
				// change terms2 text, when user selects file			
				terms2.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload terms2
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = terms2.text();
					if (text.length < 13){
						terms2.text(text + '.');					
					} else {
						terms2.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				terms2.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload terms2
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#tcfiles2').text(file);						
			}
		});
		
		var floorplan2 = $('#upload_floorplan2'), interval;
		new AjaxUpload(floorplan2,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'floorplan',
				uid : $('#uid2').val()
			},
			onSubmit : function(file, ext){
				// change floorplan2 text, when user selects file			
				floorplan2.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload floorplan2
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = floorplan2.text();
					if (text.length < 13){
						floorplan2.text(text + '.');					
					} else {
						floorplan2.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				floorplan2.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload floorplan2
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#floorplanfiles2').text(file);						
			}
		});
		
		///////
		//////
		//////
		
		var terms3 = $('#upload_tc3'), interval;
		new AjaxUpload(terms3,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'tc',
				uid : $('#uid3').val()
			},
			onSubmit : function(file, ext){
				// change terms3 text, when user selects file			
				terms3.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload terms3
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = terms3.text();
					if (text.length < 13){
						terms3.text(text + '.');					
					} else {
						terms3.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				terms3.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload terms3
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#tcfiles3').text(file);						
			}
		});
		
		var floorplan3 = $('#upload_floorplan3'), interval;
		new AjaxUpload(floorplan3,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'floorplan',
				uid : $('#uid3').val()
			},
			onSubmit : function(file, ext){
				// change floorplan3 text, when user selects file			
				floorplan3.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload floorplan3
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = floorplan3.text();
					if (text.length < 13){
						floorplan3.text(text + '.');					
					} else {
						floorplan3.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				floorplan3.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload floorplan3
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#floorplanfiles3').text(file);						
			}
		});
		
		///////
		//////
		//////
		
		var terms4 = $('#upload_tc4'), interval;
		new AjaxUpload(terms4,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'tc',
				uid : $('#uid4').val()
			},
			onSubmit : function(file, ext){
				// change terms4 text, when user selects file			
				terms4.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload terms4
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = terms4.text();
					if (text.length < 13){
						terms4.text(text + '.');					
					} else {
						terms4.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				terms4.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload terms4
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#tcfiles4').text(file);						
			}
		});
		
		var floorplan4 = $('#upload_floorplan4'), interval;
		new AjaxUpload(floorplan4,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'floorplan',
				uid : $('#uid4').val()
			},
			onSubmit : function(file, ext){
				// change floorplan4 text, when user selects file			
				floorplan4.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload floorplan4
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = floorplan4.text();
					if (text.length < 13){
						floorplan4.text(text + '.');					
					} else {
						floorplan4.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				floorplan4.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload floorplan4
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#floorplanfiles4').text(file);						
			}
		});
		
		///////
		//////
		//////
		
		var terms5 = $('#upload_tc5'), interval;
		new AjaxUpload(terms5,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'tc',
				uid : $('#uid5').val()
			},
			onSubmit : function(file, ext){
				// change terms5 text, when user selects file			
				terms5.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload terms5
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = terms5.text();
					if (text.length < 13){
						terms5.text(text + '.');					
					} else {
						terms5.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				terms5.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload terms5
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#tcfiles5').text(file);						
			}
		});
		
		var floorplan5 = $('#upload_floorplan5'), interval;
		new AjaxUpload(floorplan5,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'floorplan',
				uid : $('#uid5').val()
			},
			onSubmit : function(file, ext){
				// change floorplan5 text, when user selects file			
				floorplan5.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload floorplan5
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = floorplan5.text();
					if (text.length < 13){
						floorplan5.text(text + '.');					
					} else {
						floorplan5.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				floorplan5.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload floorplan5
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#floorplanfiles5').text(file);						
			}
		});
		
		///////
		//////
		//////
		
		var terms6 = $('#upload_tc6'), interval;
		new AjaxUpload(terms6,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'tc',
				uid : $('#uid6').val()
			},
			onSubmit : function(file, ext){
				// change terms6 text, when user selects file			
				terms6.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload terms6
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = terms6.text();
					if (text.length < 13){
						terms6.text(text + '.');					
					} else {
						terms6.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				terms6.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload terms6
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#tcfiles6').text(file);						
			}
		});
		
		var floorplan6 = $('#upload_floorplan6'), interval;
		new AjaxUpload(floorplan6,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'floorplan',
				uid : $('#uid6').val()
			},
			onSubmit : function(file, ext){
				// change floorplan6 text, when user selects file			
				floorplan6.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload floorplan6
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = floorplan6.text();
					if (text.length < 13){
						floorplan6.text(text + '.');					
					} else {
						floorplan6.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				floorplan6.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload floorplan6
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#floorplanfiles6').text(file);						
			}
		});
		
		
		
		var terms7 = $('#upload_tc7'), interval;
		new AjaxUpload(terms7,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'tc',
				uid : $('#uid7').val()
			},
			onSubmit : function(file, ext){
				// change terms7 text, when user selects file			
				terms7.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload terms7
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = terms7.text();
					if (text.length < 13){
						terms7.text(text + '.');					
					} else {
						terms7.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				terms7.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload terms7
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#tcfiles7').text(file);						
			}
		});
		
		var floorplan7 = $('#upload_floorplan7'), interval;
		new AjaxUpload(floorplan7,{
			//action: 'upload-test.php', // I disabled uploads in this example for security reasons
			action: 'upload_file.php', 
			name: 'tc',
			data: {
				type : 'floorplan',
				uid : $('#uid7').val()
			},
			onSubmit : function(file, ext){
				// change floorplan7 text, when user selects file			
				floorplan7.text('Uploading');
				
				// If you want to allow uploading only 1 file at time,
				// you can disable upload floorplan7
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = floorplan7.text();
					if (text.length < 13){
						floorplan7.text(text + '.');					
					} else {
						floorplan7.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){
				//alert(response);
				floorplan7.text('Upload');
							
				window.clearInterval(interval);
							
				// enable upload floorplan7
				this.enable();
				
				// add file to the list
				$('<li></li>').appendTo('#floorplanfiles7').text(file);						
			}
		});
		
		
	}
}

$(window).load(function(){
	uploadables();	
})