
$().ready(function(){
	/*if(index_item!==undefined && index_item>0)
	{
		$(".hide-"+index_item).show();
		$("#show-"+index_item).hide();
		$("#hide-"+index_item).show();
	}*/
	 /**
	  * public function
	  */
	$("#contactLink").click(function(){
		if ($("#contactForm").is(":hidden")){
			$("#contactForm").slideDown("slow");
		}
		else{
			$("#contactForm").slideUp("slow");
		}
	});
	$("#contactForm-close").click(function(){
		$("#contactForm").slideUp("slow");
	});
	$("#contactForm2-close").click(function(){
		$("#contactForm2").slideUp("slow");
	});
	$("#contactForm3-close").click(function(){
		$("#contactForm3").slideUp("slow");
	});
	$("#contactLink2").click(function(){
		if ($("#contactForm2").is(":hidden")){
			$("#contactForm2").slideDown("slow");
		}
		else{
			$("#contactForm2").slideUp("slow");
		}
	});
	
	$("#contactLink3").click(function(){
		if ($("#contactForm3").is(":hidden")){
			$("#contactForm3").slideDown("slow");
		}
		else{
			$("#contactForm3").slideUp("slow");
		}
	});
	
	$("#btnSearch").click(function(){
		//alert($("#keyword").val());
		var key = $.trim($("#keyword").val());
		
		if(key.length>0)
		{
			if(key=="từ khóa ...")
			{
				alert("Bạn chưa nhập từ khóa!");
				return false;
			}
			else
			{
				var regex = /\s+/g;
				key = key.replace(regex,'+');
			
				var action = "";
				window.location.href=getBaseURL()+"Tim-kiem?keyword="+key;
				//alert(action);
				//document.frmSearch.action=action;
				//document.frmSearch.submit();
			}
		}
		else
		{
			alert("Bạn chưa nhập từ khóa!");
		}
		return false;
		});
		$("#btnSearchDetail").click(function(){			
		var key = $.trim($("#search-detail").val());
		
		if(key.length>0)
		{
			if(key=="từ khóa ...")
			{
				alert("Bạn chưa nhập từ khóa!");
				return false;
			}
			else
			{
				var regex = /\s+/g;
				key = key.replace(regex,'+');
			
				var action = "";
				window.location.href=getBaseURL()+"Tim-kiem?keyword="+key;
				//alert(action);
				//document.frmSearch.action=action;
				//document.frmSearch.submit();
			}
		}
		else
		{
			alert("Bạn chưa nhập từ khóa!");
		}
		return false;
	});
	 $(".province-choose").click(function(){
		 
		 var id = this.id;
		 id = id.substring(16,id.length);
		 
		 $.ajax({
			   type: "GET",
			   url: "process.php?act=province&pid="+id,
			   /*data: {province_id:$.trim($("#pid option:selected").val())},*/
			   beforeSend: function(req){ 
	 			//$("#cmt_loader").show();				   
			   },
			   error: function(req, status, info){
			   	   //alert("CÃ³ lá»—i ");
			   	   //alert(info);
			   },			   
			   complete: function(res, s){
				   //alert(res.responseText);
				   //$("#did").html(res.responseText);
				   //go back to current url
				   //alert($('#hddCat').val());
				   //var backUrl =  window.location.href;		
				   //backUrl = backUrl.replace(/#/,"");
				   var cid =$.trim($('#hddCat').val());
				   var curl = $.trim($('#hddCatUrl').val());
				   var url = getBaseURL();				   
				   if(cid>0)
				   {
					   url = url+curl;
				   }
				   if((cid==0) && (curl!='tat-ca') && curl.length>0)
				   {
					   url = url+curl;
				   }
				   if(curl=='tat-ca')
				   {
					   url = url+"Muc-tin";
				   }
					window.location.href = url;
			    }
		});
		
	 });
	 
	 /**
	  * public function
	  */
	 $(".back-to-province").click(function(){
		 var id = this.id;
		 id = id.substring(17,id.length);		 
		 $.ajax({
			   type: "GET",
			   url: "process.php?act=province&pid="+id,			  
			   beforeSend: function(req){	 			   
			   },
			   error: function(req, status, info){			   	   
			   },			   
			   complete: function(res, s){				   
				   var cid =$.trim($('#hddCat').val());
				   var curl = $.trim($('#hddCatUrl').val());
				   var url = getBaseURL();				   
				   if(cid>0)
				   {
					   url = url+curl;
				   }
				   if((cid==0) && (curl!='tat-ca') && curl.length>0)
				   {
					   url = url+curl;
				   }
				   if(curl=='tat-ca')
				   {
					   url = url+"Muc-tin";
				   }
					window.location.href = url;
			    }
		});		
	 });
	 
	 $(".district-choose").click(function(){
		 //id obj
		 var id = this.id;
		 id = id.substring(16,id.length);
		 
		 //all parameters
		 var mod = $("#hdCurrentUrl").val();
		 var catParentUrl = $("#hddCatParentUrl").val();
		 //alert(catParentUrl);
		 $.ajax({
			   type: "GET",
			   //url: "process.php?act=district&did="+id+"&url="+mod,
			   url: "process.php?act=district&did="+id+"&catParentUrl="+catParentUrl,
			   /*data: {province_id:$.trim($("#pid option:selected").val())},*/
			   beforeSend: function(req){ 
	 			//$("#cmt_loader").show();				   
			   },
			   error: function(req, status, info){
			   	   //alert("CÃ³ lá»—i ");
			   	   //alert(info);
			   },			   
			   complete: function(res, s){
				   var cid =$.trim($('#hddCat').val());
				   var curl = $.trim($('#hddCatUrl').val());
				   //alert("this is getBaseUrl: " +getBaseURL());
				   var url = getBaseURL();
				   if(cid>0)
				   {
					   url = url+curl;
				   }
				   if((cid==0) && (curl!='tat-ca') && curl.length>0)
				   {
					   url = url+curl;
				   }
				   if(curl=='tat-ca')
				   {
					   url = url+"Muc-tin";
				   }
				   //alert(curl);
					window.location.href = url;				   
			    }
		});
		
	 });
	 
	 /**
	  * public function for choosing province in Project Area of Left Menu 
	  */
	 $(".prj-province-choose").click(function(){
		 var id = this.id;
		 id = id.substring(20,id.length);
		 $.ajax({
			   type: "GET",
			   url: "process.php?act=prjProvince&pid="+id,			   
			   beforeSend: function(req){	 			
			   },
			   error: function(req, status, info){
			   },			   
			   complete: function(res, s){				   
				   var currentProjectUrl =$.trim($('#hddPrjUrl').val());
				   var currentCatParentUrl =$.trim($('#hddCatParentUrl').val());				   
				   var returnUrl = getBaseURL();
				   returnUrl = returnUrl + "du-an_danh-sach_" + currentCatParentUrl ;					  
				   window.location.href=returnUrl;
			    }
			    
		});
		
	 });
	 
	 /**
	  * public function for choosing province in District Area of Left Menu From  "du-an" page. Note this differ from the above function   
	  */
	 $(".proj-province-choose").click(function(){
		 var id = this.id;
		 id = id.substring(21,id.length);
		 $.ajax({
			   type: "GET",
			   url: "process.php?act=prjProvince&pid="+id,			   
			   beforeSend: function(req){	 			
			   },
			   error: function(req, status, info){
			   },			   
			   complete: function(res, s){				   
				   var currentCatParentUrl =$.trim($('#hddCatParentUrl').val());
				   var returnUrl = getBaseURL();				   
				   returnUrl = returnUrl + "Muc-tin_" + currentCatParentUrl;
				   
				   window.location.href=returnUrl;
			    }
			    
		});
		
	 });
	 
	 $(".project-choose").click(function(){
		 var id = this.id;
		 id = id.substring(15,id.length);
		 $.ajax({
			   type: "GET",
			   url: "process.php?act=project&prjId="+id,			   
			   beforeSend: function(req){	 							   
			   },
			   error: function(req, status, info){
			   },			   
			   complete: function(res, s){
				   //var cid =$.trim($('#hddCat').val());
				   //var curl = $.trim($('#hddCatUrl').val());
				   //var url = "/";
				   //if(cid>0)
				   //{
					 //  url = url+"chuyen-muc"+"_"+curl+"_"+cid;
				   //}
					
					//window.location.href = url;		
			    }
		});
		
	 });

	 $(".prj-district-choose").click(function(){
		 //id of district choose
		 var id = this.id;
		 id = id.substring(16,id.length);
		 
		 $.ajax({
			   type: "GET",
			   url: "process.php?act=district&did="+id,			   
			   beforeSend: function(req){	 			   
			   },
			   error: function(req, status, info){			   	   
			   },			   
			   complete: function(res, s){				   
				   var url = getBaseURL() + "Muc-tin";
				   var currentCatParentUrl =$.trim($('#hddCatParentUrl').val());
				   url = url + "_" + currentCatParentUrl;
				   window.location.href = url;				   
			    }
		});
	 });
	 $(".titleQuestion").click(function(){
		 	var id = this.id;		 	
		 	id = id.substring(13,id.length);		 
		 	$('[class=boxreply]').each( function()
		 	{
		 		var boxReplyId = this.id;		 		
		 		boxReplyId = boxReplyId.substring(8,boxReplyId.length);
		 		var boxId = '#boxreply'+boxReplyId;
		 		if (id == boxReplyId)
		 		{		 					 					 			
		 			if ($(boxId).is(":hidden")){
						$(boxId).slideDown("slow");
					}
					else{
						$(boxId).slideUp("slow");
					}		 				 		
		 		}
		 		else
		 		{
		 			$(boxId).slideUp("slow");
		 			//alert ("khác nhau rồi đấy thấy chưa");
		 		}
		 	});		 				 			
		 });
	 
	 $(".boxreply .textblue").click(function(){
		 var id = this.id;
		 id = id.substring(14,id.length);
		 var boxId = '#boxreply'+ id;
		 $(boxId).slideUp("slow");
	 });
	 $("#upload_cid").change(
		 function()
		 {
			var value = $.trim($(this).val()) ;
			
				$.ajax({
					   type: "GET",
					   url: "process.php?act=category&pid="+value,			   
					   beforeSend: function(req){	 			   
					   },
					   error: function(req, status, info){			   	   
					   },			   
					   complete: function(res, s){				   
						   $("#upload_sub_cid").html(res.responseText);				   
					    }
				});
			
			return false;
		 }
	 );
	 
	 $("#upload_pid").change(
		 function()
		 {
			var value = $.trim($(this).val()) ;
			if(value>=0)
			{
				$.ajax({
					   type: "GET",
					   url: "process.php?act=upload-province&pid="+value,			   
					   beforeSend: function(req){	 			   
					   },
					   error: function(req, status, info){			   	   
					   },			   
					   complete: function(res, s){				   
						   $("#upload_did").html(res.responseText);				   
					    }
				});
			}
			return false;
		 }
	 );
	 
	 /**
	  * 
	  */
	 $.validator.addMethod("validBoth", function(value, element,param) {
		 if($.trim($(param).val())<1){ return false;}
		 else
		 {
			 if(value<1) return false;
			 else return true;
		 }
			//return !this.optional(element) ;
		}, "Please select both the item and its amount.");
	 
	 /**
	  * method price to check price of real estate
	  * return boolean
	  */
	 $.validator.addMethod("price", function(value,element) {
		 value = $.trim(value);
		 var val = value.toLowerCase();
		 if(val==""){ return true;}
		 else if(val=="vnd"){ return true;}
		 else
		 {
			 return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
		 }
		 
		}, 'Please enter "price"!');
	 
	 /**
	  * method price to check user phone
	  * return boolean
	  */
	 $.validator.addMethod("phone", function(value,element) {
		 value = $.trim(value);
		 if(value.length>50) return false;
		 else return this.optional(element) || /(\(?[+]?[0-9]{2}\))?([-]?[0-9]+)+$/.test(value);
		 
		}, 'Please enter your phone!');
	 
	 /**
	  * valid upload form 
	  */
	 var container = $("#formUpload div.alert");
	 $("#formUpload").validate(
	 {
		 invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? '<img src="public/themes/default/images/alert.gif"/> <font style="font-weight:bold;">Có tất cả ' + errors + ' lỗi xảy ra trong quá trình đăng tin</font>. <br/> <div style="margin-left:20px;font-size:10px;">(Click vào biểu tượng <span class="formInfo"><a name="" class="jTip" href="#">?</a></span> để xem hướng dẫn chi tiết)</div>'
					: '<img src="public/themes/default/images/alert.gif"/> <font style="font-weight:bold;">Có tất cả ' + errors + ' lỗi xảy ra trong quá trình đăng tin</font>. <br/> <div style="margin-left:20px;font-size:10px;">(Click vào biểu tượng <span class="formInfo"><a name="" class="jTip" href="#">?</a></span> để xem hướng dẫn chi tiết)</div>';
				$("div.rowdangtin div.alert").html(message);
				$("div.rowdangtin div.alert").show();
				//$("div.mark_warning").show();
			} else {
				$("div.rowdangtin div.alert").hide();
				//$("div.mark_warning").hide();
			}
		},
		errorPlacement: function(error, element) {			
			//error.appendTo($(element).parents("div.rowdangtin"));			
			//error.appendTo( element.parent().next() );
		},
		highlight: function(element, errorClass) {
			$(element).addClass(errorClass).parent().prev().prev().children("select").addClass(errorClass);
			$(element).parents("div.rowdangtin").addClass("invalid");
		},
		unhighlight: function( element, errorClass, validClass ) {
			$(element).removeClass(errorClass).addClass(validClass);
			$(element).parents("div.rowdangtin").removeClass("invalid");
		},
		onkeyup: false, 
		//errorContainer: container,
		//errorLabelContainer: $("ul", container),
		//wrapper: 'li',
		rules: {
			title: {
			  required:true,
			  maxlength:255
		  	},		  	
		  	upload_sub_cid:
		  	{		  		
		  		required:true,
		  		validBoth:'#upload_cid',
		  		min:1
		  	},
		  	upload_did:
		  	{
		  		required:true,
		  		validBoth:'#upload_pid',
		  		min:1
		  	},
		  	price:
		  	{
		  		price:true
		  	},		  	
			verify: {
			  required:true			  
		  	},
		  	fullname: 
		  	{
				required:true			  
			},
			phone: 
		  	{
				required:true,
				phone:true
			},
			email: 
		  	{
				required:true,
				email:true			  
			}
		},
		messages: {
			title:{
				required:" ",
				maxlength: " "
			},
		  	upload_sub_cid:
		  	{
		  		required:" ",
		  		validBoth:" ",
		  		min:" "
		  	},		  	
		  	upload_did:
		  	{
		  		required:"Bạn chưa chọn quận huyện",
		  		validBoth:' ',
		  		min:"Bạn chưa chọn quận huyện"
		  	},
		  	price:
		  	{		  		
		  		price: "Giá tiền phải nhập bằng các chữ số"
		  	},		  	
			verify:{
				required:"Bạn chưa nhập mã xác nhận"				
			},
		  	fullname: 
		  	{
				required:"Bạn chưa nhập Họ và Tên"			  
			},
			phone: 
		  	{
				required:"Bạn chưa nhập số điện thoại",
				phone:"Số điện thoại không hợp lệ"
			},
			email: 
		  	{
				required:"Bạn chưa nhập địa chỉ Email",
				email:"Email không chính xác - Ex: ten-email@domain.com"
			}
		}

	 });
	 
	 /* upload preview*/
	 $("#btnPreview").click(function()
	 {		 
		 var content = CKEDITOR.instances.description.getData();
		 $("#light.white_content .titlexemtruoc").html('Người đăng: <b>'+ $("#fullname").val() +'</b>  |  ĐT: <b>'+ $("#phone").val() +'</b>  |  Email: <font class="textblue"><a href="mailto:'+ $("#email").val() +'"><b>'+ $("#email").val() +'</b></a></font><br />	Chuyên mục: <b>'+ $("#upload_cid option:selected").text() +'</b>,  Loại hình: <b>'+ $("#upload_sub_cid option:selected").text() +'</b><br />Nơi đăng: <b>'+ $("#upload_did option:selected").text() +' - '+ $("#upload_pid option:selected").text() +'</b><br /><br />');
		 $("#light.white_content .contentxemtruoc").html('Tiêu đề tin:<br /><font class="texttitle">'+ $("#title").val() +'</font><br /><br />'+ content +'');
		 
		 //show information
		 $('#light').show();
		 $('#fade').show();
		 $('#iframeIE').show();
		 
		 //go to top page
		 scroll(0,0);
		 
		 return false;
	 });
	 
	 /* close upload preview*/
	 $("#btnPreviewClose").click(function()
	 {
		 //hide information
		 $('#light').hide();
		 $('#fade').hide();
		 $('#iframeIE').hide();
		 return false;
	 });
	 
	 $("#addImage").click(function(){
		 //alert($("upload"));
		 var index = $("#pIndex").val();
		 fobj = document.getElementById("formUpload");
		 regex = "upload";
		 re = new RegExp(regex);
		 Obj = 0;
		 for(i = 0; i < fobj.elements.length; i++) 
		 {
			 elm = fobj.elements[i];
			 if (elm.type == 'file') 
			 {
				 if (re.test(elm.name)) 
				 {
					 var ext = $.trim(getExt(elm.value))+"";
					 //alert(ext);
					 if(ext==""){alert("Bạn chưa chọn ảnh tải lên!"); return false;}
					 if(ext=="jpg" || ext=="jpeg" || ext=="png" || ext=="gif")
					 {
						 
					 }
					 else
					 {
						 alert("Bạn chỉ được chọn file có định dạng mở rộng là: *.jpg, *.png, *.gif");
						 return false;
					 }
					 
					 Obj++;
				 }
			 }
		 }
		 
		 if(Obj==5)
		 {
			 alert("Bạn chỉ được tải lên tối đa là 5 ảnh");
			 return false;
		 }
		 else
		 {
			 $("#upload-image").append("<li id='li-upload-"+index+"'><input type='file' name='upload[]' id='upload-"+index+"' onChange='checkFile()' /><label id='lbl-upload-"+index+"'><a id='lbl-upload-"+index+"' href='#' onclick='deleteImage(\"lbl-upload-"+index+"\")'>xóa</a></label><br /></li>");
			 index ++;
		 }
		 
		 $("#pIndex").val(index);
		 return false;
	 });
	 
	 $(".show-all").click(function(){
		 var objID = this.id;
		 index = objID.substring(5,objID.length);
		 $(".hide-"+index).show();
		 $("#show-"+index).hide();
		 $("#hide-"+index).show();
	 });
	 $(".hide-all").click(function(){
		 var objID = this.id;
		 index = objID.substring(5,objID.length);
		 $(".hide-"+index).hide();
		 $("#show-"+index).show();
		 $("#hide-"+index).hide();
	 });
	 
	 $(".rows_per_page").click(function(){
		 var row_id = this.id;
		 var number_row = row_id.substr(5,row_id.length);
		 var url = window.location.href;
		 var mod = $("#hdModLink").val();
		 $.ajax({
			   type: "GET",
			   //url: "process.php?act=district&did="+id+"&url="+mod,
			   url: "process.php?act=rows_change&new="+number_row+"&url="+mod,
			   /*data: {province_id:$.trim($("#pid option:selected").val())},*/
			   beforeSend: function(req){ 
	 			//$("#cmt_loader").show();				   
			   },
			   error: function(req, status, info){
			   	   //alert("CÃ³ lá»—i ");
			   	   //alert(info);
			   },			   
			   complete: function(res, s){
					window.location.href = url;				   
			    }
		});
		 
	 });
});
$(document).ready(
		function ()
		{		
			$("#pikame").PikaChoose({show_captions:true, slide_enabled:false, delay_caption:false, show_prev_next:false,slide_speed:0,slide_enabled:false,thumb_width: 58,thumb_height: 47});
		}
);
function closeForm(){
	$("#messageSent").show("slow");
	setTimeout('$("#messageSent").hide();$("#contactForm").slideD("slow");$("#contactLink").slideUp("slow");', 2000);
}
/**
 * get current url and params
 * @param fname
 * @param act
 * @return
 */
$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});

function ChangeTextDefault(obj,string)
{
	var value = obj.value;
    value = value.toLowerCase();
    var strDefault = string.toLowerCase();
    
    if(value=='')
    {
        obj.value=string;obj.style.color='#666666';
        obj.style.fontStyle='italic';
    }
    else if(value==strDefault)
    {
        obj.style.color='#666666';
        obj.style.fontStyle='italic';
    }
    else
    {
        obj.style.color='#000000';
        obj.style.fontStyle='normal';
    }
}

function ChangeTextFocus(obj,string)
{
    var value = obj.value;
    value = value.toLowerCase();
    var strDefault = string.toLowerCase();
    
	if(value==strDefault)
    {
        obj.value='';
        obj.color='#000000';
        obj.style.fontStyle='normal';
    }
}

function deleteImage(id)
{	
	var obj_id = id.substr(4,id.length);	
	jQuery("#li-"+obj_id).remove();
	return false;
}
function getExt(file){
	return file.substr(file.indexOf(".")+1,file.length);
}
function getSize(filepath)
{
	var myFSO = new ActiveXObject("Scripting.FileSystemObject");
	//var filepath = document.upload.file.value;
	var thefile = myFSO.getFile(filepath);
	var size = thefile.size;
	alert(size + " bytes");
}
function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));
   

    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        //alert(pathname);
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }

}
function cleanWordFormat(c){
    c = c.replace(/<\!--[\s\S]*?-->/g, '');
    c = c.replace(/<o:p>\s*<\/o:p>/g, '');
    c = c.replace(/<o:p>[\s\S]*?<\/o:p>/g, '&nbsp;');
    c = c.replace(/\s*mso-[^:]+:[^;"]+;?/gi, '');
    c = c.replace(/\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*;/gi, '');
    c = c.replace(/\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*"/gi, '"');
    c = c.replace(/\s*TEXT-INDENT: 0cm\s*;/gi, '');
    c = c.replace(/\s*TEXT-INDENT: 0cm\s*"/gi, '"');
    c = c.replace(/\s*TEXT-ALIGN: [^\s;]+;?"/gi, '"');
    c = c.replace(/\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, '"');
    c = c.replace(/\s*FONT-VARIANT: [^\s;]+;?"/gi, '"');
    c = c.replace(/\s*tab-stops:[^;"]*;?/gi, '');
    c = c.replace(/\s*tab-stops:[^"]*/gi, '');
    
        //c = c.replace(/\s*face="[^"]*"/gi, '');
        //c = c.replace(/\s*face=[^ >]*/gi, '');
        //c = c.replace(/\s*FONT-FAMILY:[^;"]*;?/gi, '');
    
    c = c.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, '<$1$3');
    
    //c = c.replace(/<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, '<$1$3');

    c = c.replace(/<STYLE[^>]*>[\s\S]*?<\/STYLE[^>]*>/gi, '');
    c = c.replace(/<(?:META|LINK)[^>]*>\s*/gi, '');
    c = c.replace(/\s*style="\s*"/gi, '');
    c = c.replace(/<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;');
    c = c.replace(/<SPAN\s*[^>]*><\/SPAN>/gi, '');
    c = c.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, '<$1$3');
    c = c.replace(/<SPAN\s*>([\s\S]*?)<\/SPAN>/gi, '$1');
    c = c.replace(/<FONT\s*>([\s\S]*?)<\/FONT>/gi, '$1');
    c = c.replace(/<\\?\?xml[^>]*>/gi, '');
    c = c.replace(/<w:[^>]*>[\s\S]*?<\/w:[^>]*>/gi, '');
    c = c.replace(/<\/?\w+:[^>]*>/gi, '');
    c = c.replace(/<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;');
    c = c.replace(/<H\d>\s*<\/H\d>/gi, '');
    c = c.replace(/<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none[\s\S]*?<\/\1>/ig, '');
    c = c.replace(/<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, '<$1$3');
    c = c.replace(/<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, '<$1$3');
    c = c.replace(/<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, '<$1$3');

    c = c.replace(/<H1([^>]*)>/gi, '<div$1><b><font size="6">');
    c = c.replace(/<H2([^>]*)>/gi, '<div$1><b><font size="5">');
    c = c.replace(/<H3([^>]*)>/gi, '<div$1><b><font size="4">');
    c = c.replace(/<H4([^>]*)>/gi, '<div$1><b><font size="3">');
    c = c.replace(/<H5([^>]*)>/gi, '<div$1><b><font size="2">');
    c = c.replace(/<H6([^>]*)>/gi, '<div$1><b><font size="1">');
    c = c.replace(/<\/H\d>/gi, '</font></b></div>');
    var f = new RegExp('(<P)([^>]*>[\\s\\S]*?)(</P>)', 'gi');
    c = c.replace(f, '<div$2</div>');
    c = c.replace(/<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '');
    c = c.replace(/<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '');
    c = c.replace(/<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '');

    return c;
}