
function disable()
{
	document.getElementById("from_date").style.display="none";
	document.getElementById("to_date1").style.display="none";
}

function enable()
{
	
	if(document.all)
	{	
	document.getElementById('to_date1').style.display="block";
	document.getElementById('from_date').style.display="block";
}
else
{
	document.getElementById('to_date1').style.display="table-row";
	document.getElementById('from_date').style.display="table-row";
}
}

function count()
{
	var maxchar=500;

	if(document.form1.add_desc.value.length > maxchar)
	{
		document.form1.add_desc.value=document.form1.add_desc.value.substring(0,maxchar);
	}
	var a=document.form1.add_desc.value;
	var alength=a.length;
	var remainchar=maxchar-alength;
	document.getElementById('charlen').innerHTML=remainchar;
}	

// ----------------START  validation for checkbox to Delete post ----------------------------------// 
		 
function del()
{
	var chk = false;
	var chk_li_flag = "";
	var a=document.form1["chk[]"].length;
		if(a)
	{
		for(i=0; i < document.form1["chk[]"].length; i++)
		{  	
			if(document.form1["chk[]"][i].checked)
			{
				chk_li_flag += document.form1["chk[]"][i].value + ",";	
				chk=true;					
			}
		}
		
	}	
	else
	{		
		if(document.form1["chk[]"].checked)
			{
				chk_li_flag += document.form1["chk[]"].value + ",";	
				chk=true;					
			}
	}	
				
		if(chk_li_flag == "")
		{
			alert("Please select one Listing to Delete...!!!!");
			return false;
		}		
}

// ---------------- END validation for checkbox to Delete post----------------------------------// 


// ----------------START  validation for checkbox to blacklist post ----------------------------------// 
		 
function black()
{
	var chk = false;
	var chk_li_flag = "";
	var a=document.form1["chk[]"].length;
		if(a)
	{
		for(i=0; i < document.form1["chk[]"].length; i++)
		{  	
			if(document.form1["chk[]"][i].checked)
			{
				chk_li_flag += document.form1["chk[]"][i].value + ",";	
				chk=true;					
			}
		}
		
	}	
	else
	{		
		if(document.form1["chk[]"].checked)
			{
				chk_li_flag += document.form1["chk[]"].value + ",";	
				chk=true;					
			}
	}	
				
		if(chk_li_flag == "")
		{
			alert("Please select atleast one for blacklist...!!!!");
			return false;
		}		
}

// ---------------- END validation for checkbox to Delete post----------------------------------// 



// ----------------START validation for checkbox to Save post ----------------------------------// 

function ins()
{
	var chk = false;
	var chk_li_flag = "";
	var a=document.form1["chk[]"].length;
	
	if(a)
	{
		for(i=0; i < document.form1["chk[]"].length; i++)
		{  	
			if(document.form1["chk[]"][i].checked)
			{
				chk_li_flag += document.form1["chk[]"][i].value + ",";	
				chk=true;					
			}
		}
		
	}	
	else
	{		
		if(document.form1["chk[]"].checked)
			{
				chk_li_flag += document.form1["chk[]"].value + ",";	
				chk=true;					
			}
	}	
		if(chk_li_flag == "")
		{
			alert(" Please Select one Listing to Save...!!!");
			return false;
		}		
}

// ---------------- END validation for checkbox to Save post----------------------------------// 

/*
var a = false;

function del()
{	
	
	a = confirm("Are you sure to delete post ?");
	return check();
}

function check()
{
	if(a==true)
	{
		return true;
	}
	
	return false;
}*/

function validation_form()
{

	valid=true;
	var msg="";
	
	var a=document.form1.title1.value;
	//var b=document.form1.url.value;
	var c=document.form1.add_desc.value;
	var d=document.form1.category.value;
	var e=document.form1.sub_category.value;
	var g=document.form1.email.value;
	var h=document.form1.c_person.value;
	var j=document.form1.state.value;
	var k=document.form1.city.value;
	var l=document.form1.phone.value;
	var i=document.form1.f_captcha.value;
	var flag=0;	
	

   for (var i=0; i < document.form1.duration.length; i++)
   {
		  if(document.form1.duration[i].checked==true)
		  {
			
			  flag=1;
			  var rad_val = document.form1.duration[i].value;
			  
	//		  alert(rad_val);
		      //var rad=document.form1.duration[i].checked;
			  //alert(rad);
			
		  }
   }

	  if(flag==0)
	  {
    	 msg=msg + " * Please select Advt Duration \n";
	  }


	
	if(a=="")
	{
		msg=msg + " * Please enter Title \n";
	}
	
	/*if(b=="")
	{
		msg=msg + " * Please enter URL \n";
	}*/
	
	if(c=="")
	{
		msg=msg + " * Please enter Additional Information \n";
	}
	
	if(d=="0")
	{
		msg=msg + " * Please enter Category \n";
	}
	
	if(e=="0")
	{
		msg=msg + " * Please enter Sub Category \n";
	}

	/*
	if(h=="")
	{
		msg=msg + " * Please enter Contect Person Name \n";
	}
	*/
	
	if(j=="0")
	{
		msg=msg + " * Please enter State \n";
	}
	
	if(k=="0")
	{
		msg=msg + " * Please enter City \n";
	}
	
	if(g=="")
	{
		msg=msg + " * Please enter e-mail \n";
	}
	
	if(g.length!=0)
	{
		var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(!regex.test(g))
			{
				msg=msg + "* Enter correct e-mail address.\n";
			}
	}
	
	if(l=="")
	{
		msg=msg + " * Please enter Phone Number \n";
	}

	if(i=="")
	{
		msg=msg + " * Please enter Verification code \n";
	}
	
	if(msg!="")
	{
		var msg2 = " There is a problem with the information You have provided \n\n";
 		msg2+= msg;
		alert (msg2);
		valid=false;
	}
	
	return valid; 
}
/* ----- START - MERGE CATEGORY AND SUB-CATEGORY VALIDATION ------ */

function mergcatval_form()
{	
	valid=true;
	var msg="";
	
	var aa=document.mergcat.category.value;
	var ab=document.mergcat.category1.value;
	
	if(aa == "")
	{
		msg = msg + " Please enter Category 1\n";
	}
	
	if(ab == "")
	{
		msg = msg + " Please enter Category  2\n";
	}
	
	


	var cat_flag = 0;
		for(i=0;i<document.mergcat.r1.length;i++)
		{
			if(document.mergcat.r1[i].checked)
			{
				var chk_cat_val=document.mergcat.r1[i].value;
				cat_flag = 1;
			}
		}
		
	if(cat_flag == 0)
	{
		msg = msg + " please select any one category to merge..\n";
		valid=false;
	}
	
	if(msg!="")
	{
		var msg2 = " There is a problem with the information You have provided \n\n";
 		msg2+= msg;
		alert (msg2);
		valid=false;
	}
	return valid;
}


function mergsubcatval_form()
{
	valid=true;
	var msg="";
	
	var x=document.mergsubcat.category.value;
	var y=document.mergsubcat.sub_category.value;
	var z=document.mergsubcat.sub_category2.value;
	
	if(x == "")
	{
		msg = msg + " Please enter Category 1\n";
	}
	
	if(y == "")
	{
		msg = msg + " Please enter Sub Category 1\n";
	}
	if(z == "")
	{
		msg = msg + " Please enter Sub Category 2\n";
	}
	var cat_flag = 0;
		for(i=0;i<document.mergsubcat.r1.length;i++)
		{
			if(document.mergsubcat.r1[i].checked)
			{
				var chk_cat_val=document.mergsubcat.r1[i].value;
				cat_flag = 1;
			}
		}
		
	if(cat_flag == 0)
	{
		msg = msg + " please select any one category to merge..\n";
		valid=false;
	}
	if(msg!="")
	{
		var msg2 = " There is a problem in info You have provided \n\n";
 		msg2+= msg;
		alert (msg2);
		valid=false;
	}
	return valid;
}

/* ----- END - MERGE CATEGORY AND SUB-CATEGORY VALIDATION ------ */



/* ------------------ start validate black listed contact us ----------------------------------*/
function validate_contactusb()
{

	valid=true;
	var msg="";
	
		
	var email=document.form1.email.value;
	var user_name=document.form1.user_nm.value;
	var user_contact=document.form1.user_contact.value;
	var message=document.form1.message.value;
	var f_captcha=document.form1.f_captcha.value;
	
	var flag=0;	
	
	if(email=="")
	{
		msg=msg + " * Please enter email \n";
	}
 	
	if(user_name=="")
	{
		msg=msg + " * Please enter your name \n";
	}

	if(user_contact=="")
	{
		msg=msg + " * Please enter your phone number \n";
	}

	if(message=="")
	{
		msg=msg + " * Please enter message \n";
	}
	
	if(f_captcha=="")
	{
		msg=msg + " * Please enter security code \n";
	}
	
	
	if(msg!="")
	{
		var msg2 = " There is a problem with the information You have provided \n\n";
 		msg2+= msg;
		alert (msg2);
		valid=false;
	}
	
	return valid; 
}
/* ------------------ end validate black listed contact us ----------------------------------*/


function validation_adm_add()
{

	valid=true;
	var msg="";
	
	var a=document.form1.title1.value;
	//var b=document.form1.url.value;
	var c=document.form1.add_desc.value;
	var d=document.form1.category.value;
	var e=document.form1.sub_category.value;
	var g=document.form1.email.value;
	var h=document.form1.c_person.value;
	var j=document.form1.state.value;
	var k=document.form1.city.value;
	var l=document.form1.phone.value;
	//var i=document.form1.f_captcha.value;
	
	if(a=="")
	{
		msg=msg + " * Please enter Title \n";
	}
	
	/*if(b=="")
	{
		msg=msg + " * Please enter URL \n";
	}*/
	
	if(c=="")
	{
		msg=msg + " * Please enter Additional Information \n";
	}
	
	if(d=="0")
	{
		msg=msg + " * Please enter Category \n";
	}
	
	if(e=="0")
	{
		msg=msg + " * Please enter Sub Category \n";
	}

	
	
	if(j=="0")
	{
		msg=msg + " * Please enter State \n";
	}
	
	if(k=="0")
	{
		msg=msg + " * Please enter City \n";
	}
	
	
	if(l=="")
	{
		msg=msg + " * Please enter Phone Number \n";
	}

	/*if(i=="")
	{
		msg=msg + " * Please enter Verification Image \n";
	}*/
	
	if(msg!="")
	{
		var msg2 = " There is a problem with the information You have provided \n\n";
 		msg2+= msg;
		alert (msg2);
		valid=false;
	}
	
	return valid; 
}


function preview_ad()
{
	var ab=$("#tplformbox").offset();

		$("<iframe />").attr("id","maskdiviframe")
		.attr("src","")
		.attr("frameborder","0")
		.css("opacity",1)
		.css("z-index",998)
		.css("background-color","#FFFFFF")
		.css("top",ab.top)
		.css("left",ab.left)
		.css("height",$("#tplformbox").height()-40)
		.css("width",$("#tplformbox").width())
		.css("position", "absolute")
	.appendTo("BODY");

		$("<div />").attr("id","maskdiv")
		.css("opacity",1)
		.css("z-index",999)
		.css("background-color","#FFFFFF")
		.css("top",ab.top)
		.css("left",ab.left)
		.css("height",$("#tplformbox").height()-40)
		.css("width",$("#tplformbox").width())
		.css("position", "absolute")
		.css("overflow","auto")
		.css("border","1px solid #B99D6F")
	.appendTo("BODY");
	
	
	$("#close_1").css("display","");
	$("#preview_1").css("display","none");
	
	
var table_data = '<table width="100%" border="0" cellspacing="4" bgcolor="#F1EBE1"  cellpadding="0"><tr><td width="100%" colspan="4"><table cellpadding="2" cellspacing="2" width="100%"><td width="40%">&nbsp;</td><td width="20%" style="padding:2px 4px 2px 4px; color:#FFFFFF" bgcolor="#C0A67B" align="center"><h4><b>Full Ad</b></h4></td><td width="40%" align="right" valign="top">&nbsp;<a onclick="javascript:close_preview();" style="cursor:pointer"><img src="images/close.gif"></a></td></table></td></tr><tr><td width="23%" align="left" valign="top"><h3><b>Ad Title</b></h3></td><td width="2%" align="left" valign="top"><h3>:</h3></td><td colspan="2" align="left" valign="top"><h4 id="ad_title"></h4></td></tr><tr><td align="left" valign="top"><h3><b>Ad Description</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td colspan="2" align="left" valign="top"><h3 id="ad_desc"></h3></td></tr><tr><td align="left" valign="top"><h3><b>Ad Posted on</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="ad_date"></h3></td><td width="20%" rowspan="10" align="center" id="ad_img"></td></tr><!-- DURATION-DT-ST--><tr><td align="left" valign="top"><h3><b>Ad Valid</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3></h3></td></tr><tr><td align="left" valign="top"><h3><b>From</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="frm_dt"></h3></td></tr><tr><td align="left" valign="top"><h3><b>To</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="to_dt"></h3></td></tr><!-- DURATION-DT-EN--><tr><td align="left" valign="top"><h3><b>Contact Person</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td width="51%" align="left" valign="top"><h3 id="cont_person"></h3></td></tr><!--ADD-ST--><tr><td align="left" valign="top"><h3><b>Address</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="cont_address"></h3></td></tr><!--ADD-EN--><tr><td align="left" valign="top"><h3><b>e-mail</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="cont_email"></h3></td></tr><!--FAX-ST--><!--URL-ST--><tr><td align="left" valign="top"><h3><b>Website URL</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="web_url"></h3></td></tr><!--URL-EN--><tr><td align="left" valign="top"><h3><b>Phone</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="cont_phone"></h3></td></tr><tr><td align="left" valign="top"><h3><b>Mobile</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="cont_mobile"></h3></td></tr><tr><td align="left" valign="top"><h3><b>Fax</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="cont_fax"></h3></td></tr><!--FAX-EN--><!--TOLLFREE-ST--><tr><td align="left" valign="top"><h3><b>Toll Free</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="cont_toll_no"></h3></td></tr><!--TOLLFREE-EN--></table><table width="100%" border="0" cellspacing="5" cellpadding="0" style="margin:5px 0px 5px 0px; background-color:#FFFBF4;"><tr><td align="center"><h3 id="cat_txt">&nbsp;</h3></td></tr></table>';



var limited_ad = '<!-- DURATION-DT-ST--><tr><td align="left" valign="top"><h3><b>Ad Valid</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3></h3></td></tr><tr><td align="left" valign="top"><h3><b>From</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="frm_dt"></h3></td></tr><tr><td align="left" valign="top"><h3><b>To</b></h3></td><td align="left" valign="top"><h3>:</h3></td><td align="left" valign="top"><h3 id="to_dt"></h3></td></tr><!-- DURATION-DT-EN-->';


   for (var i=0; i < document.form1.duration.length; i++)
   {
		  if(document.form1.duration[i].checked==true)
		  {
			  flag=1;
			  var rad_val = document.form1.duration[i].value;
		
		  }
   }

if(rad_val!="Time_limited")
{
	table_data = table_data.replace(limited_ad,"");
}
$("#maskdiv").html(table_data);

var month_arr= ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var today = new Date();
year  = today.getFullYear();
month = month_arr[today.getMonth()];
date = today.getDate()-1;
hours  = today.getHours();
minute  =today.getMinutes();

var ad_title = document.form1.title1.value;
var ad_desc  = document.form1.add_desc.value;
var cont_person = document.form1.c_person.value;

ad_desc = ad_desc.replace(/\n/g, "<Br>");


$("#ad_title").html(ad_title);
$("#ad_desc").html(ad_desc);
$("#ad_date").html(date +" "+month+" " +year+" "+ hours+":"+minute);

	if($.trim(cont_person)=="")
	{
		cont_person="--";
	}

	$("#cont_person").html(cont_person);

	v_address  = "";
	if(document.form1.address.value!=="")
	{
		v_address  = document.form1.address.value +", ";		
	}
	v_address   = v_address + "<br>" + document.form1.state.value + ", "+document.form1.city.value;
	v_address = v_address.replace(/\n/g, "<Br>");

	
var	web_url = document.form1.url.value;
var cont_email = document.form1.email.value;

var cont_phone = document.form1.phone.value;
var cont_mobile = document.form1.mobile.value;

var cont_fax  = document.form1.fax.value;
var cont_toll_no = document.form1.toll_no.value;
var imgpath = document.form1.upload_file.value;

if($.trim(imgpath)!="")
{
 i_arr  = imgpath.split(/\\/);
 imgpath = i_arr[i_arr.length-1];
}

if($.trim(web_url) == "")
{
	web_url="--";
}
if($.trim(v_address) == "")
{
	v_address="--";
}
if($.trim(cont_email) == "")
{
	cont_email="--";
}

if($.trim(cont_phone) == "")
{
	cont_phone="--";
}

if($.trim(cont_mobile) == "")
{
	cont_mobile="--";
}

if($.trim(cont_fax) == "")
{
	cont_fax="--";
}
if($.trim(cont_toll_no) == "")
{
	cont_toll_no="--";
}


	$("#web_url").html(web_url);
	$("#cont_address").html(v_address);
	$("#cont_email").html(cont_email);
	$("#cont_phone").html(cont_phone);
	$("#cont_mobile").html(cont_mobile);
	$("#cont_fax").html(cont_fax);
	$("#cont_toll_no").html(cont_toll_no);
	$("#frm_dt").html(document.form1.frm1_date.value);
	$("#to_dt").html(document.form1.to_date.value);




	if(imgpath != "")
	{
	$("#ad_img").html("<img id='imgprv' src='files/tmp_img/"+imgpath+"'/>");
	}

	var newImg = document.getElementById('imgprv');
	var h = newImg.clientHeight;
	var w = newImg.clientWidth;

	msize=200;
	if(w >msize)
	{
		h =(msize * h)/ w;
		w = msize;
	}
	if(h > msize)
	{
		w =(msize * w)/ h;
		h = msize;
	}
		size =[h,w]


	$("#imgprv").css('height',h);
	$("#imgprv").css('width',w);
	var cat_txt = 'Category : <b>'+document.form1.category.value+'</b>&nbsp;&raquo;&nbsp;<b>'+document.form1.sub_category.value+'</b>';
	$("#cat_txt").html(cat_txt);
}

function close_preview()
{
$("#close_1").css("display","none");
$("#preview_1").css("display","");

$("#maskdiviframe").remove();
$("#maskdiv").remove();

}


function image_validate(val)
{
var valid_img = ",jpeg,jpg,png,bmp,gif";
t_arr  = val.split(".");

if(t_arr.length > 0)
{
	img_ext = t_arr[t_arr.length-1];
	
	if(valid_img.indexOf(img_ext)==-1)
	{
		alert("Invalid image, please select another image");
	}
	else
	{
		getImgPre();
	}
}
else
{
	alert("Invalid Image, please select another image");
}
}

var a=0;
function showsignin()
{
	$("#txtlogin").val("");
	$("#txtpwd").val("");
	$("#signinbox1").slideToggle('slow');
	if(a==0)
	{
		a=1;
//		$(".loginbox2").css("width","300px");
	$('.loginbox2').animate({
    width: '+=180'
  }, 500, function() {
    // Animation complete.
  });

	}
	else
	{
		a=0;
		$('.loginbox2').animate({
    width: '-=180'
  }, 500, function() {
    // Animation complete.
  });

	//	$(".loginbox2").css("width","120px");
	}
	
	
}


function getImgPre()
{
	document.form1.target="IframeImg";
	document.form1.action="imgPreview.php";
	document.form1.submit();
	document.form1.target="";
	document.form1.action="";
	
}

function checkretrive()
{
	email = document.getElementById('txtemail').value;

	if(email=="")
	{
		alert("Please provide e-mail Address");
			return false;
	}
	else
	{
		if(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/) == -1)
		{

			alert("Invalid e-mail Address");
			return false;
		}
	}
}



