/**
 *  SWETHA code
 */

/****************************Ajax HTTP Request CODE START****************************/
var xmlHttp; 
if (window.XMLHttpRequest)
{
    try 
    {
        xmlHttp = new XMLHttpRequest();
    } catch (e) { xmlHttp = false; }
}
else if (window.ActiveXObject) {
    try {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) { xmlHttp = false; }
    }
}
//alert(scid);
var xmlhttp=false;	
try{
	xmlhttp=new XMLHttpRequest();
}
catch(e)	{		
	try{			
		xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e){
		try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e1){
			xmlhttp=false;
		}
	}
}
/****************************Ajax HTTP Request CODE END****************************/ 
function validate_desc()
{
	//alert ("hai");
}
function getcategories(scid)
{
	xmlhttp.open('GET', weblink+"welcome/getsubcategories/" + scid , false);
	xmlhttp.send(null); 
	str=xmlhttp.responseText;
	str=str.replace(/^\s*([\S\s]*)\b\s*$/, '$1');
	//alert(str);
	if(str=="0")
	{
		var slen=document.getElementById("adsubcategory").options.length;
		for(j=slen;j>=0;j--)
		{
			document.getElementById("adsubcategory").remove(j);
		}	
		var optn = document.createElement("OPTION");
		optn.text = "Select Sub Category";
		optn.value = "0";
		document.getElementById("adsubcategory").options.add(optn);
	}
	
	else
	{
		var myarray=str.split("~");
		//alert(myarray);
		var idarr1=myarray[0];
		//alert(idarr1);
		var routearr1=myarray[1];
		//alert(routearr1);
		var idarr=idarr1.split(",");
		//alert(idarr);
		//alert(idarr.length)
		var routearr=routearr1.split(",");
		//alert(routearr)
		var slen=document.getElementById("adsubcategory").options.length;
		for(j=slen;j>=0;j--)
		{
			document.getElementById("adsubcategory").remove(j);
		}	
		var optn = document.createElement("OPTION");
		optn.text = "Select Sub Category";
		optn.value = "0";
		document.getElementById("adsubcategory").options.add(optn);
		for (i=0;i<(idarr.length)-1;i++)
		{
			var optn = document.createElement("OPTION");
			optn.text = routearr[i];
			optn.value = idarr[i];
			optn.style.paddingLeft ="5px";
			document.getElementById("adsubcategory").options.add(optn);
		}
	
	}
	
}
function getcities(scid)
{
	xmlhttp.open('GET', weblink+"welcome/getcities/" + scid , false);
	xmlhttp.send(null); 
	str=xmlhttp.responseText;
	str=str.replace(/^\s*([\S\s]*)\b\s*$/, '$1');
	//alert(str);
	if(str=="0")
	{
		var slen=document.getElementById("city").options.length;
		for(j=slen;j>=0;j--)
		{
			document.getElementById("city").remove(j);
		}	
		var optn = document.createElement("OPTION");
		optn.text = "Select City";
		optn.value = "0";
		document.getElementById("city").options.add(optn);
	}
	
	else
	{
		var myarray=str.split("~");
		//alert(myarray);
		var idarr1=myarray[0];
		//alert(idarr1);
		var routearr1=myarray[1];
		//alert(routearr1);
		var idarr=idarr1.split(",");
		//alert(idarr);
		//alert(idarr.length)
		var routearr=routearr1.split(",");
		//alert(routearr)
		var slen=document.getElementById("city").options.length;
		for(j=slen;j>=0;j--)
		{
			document.getElementById("city").remove(j);
		}	
		var optn = document.createElement("OPTION");
		optn.text = "Select City";
		optn.value = "0";
		document.getElementById("city").options.add(optn);
		for (i=0;i<(idarr.length)-1;i++)
		{
			var optn = document.createElement("OPTION");
			optn.text = routearr[i];
			optn.value = idarr[i];
			optn.style.paddingLeft ="5px";
			document.getElementById("city").options.add(optn);
		}
	
	}
	
}

function deladimage(p_id)
{
	var n = confirm("Are you sure to remove this image ?");
	if(n==1)
	{
		xmlHttp.open('GET', weblink+"welcome/delete_ad_img/" + p_id, false);
		xmlHttp.send(null); 
		str=xmlHttp.responseText;
		str=str.replace(/^\s*([\S\s]*)\b\s*$/, '$1');
		if(str>0)
		{
			document.getElementById("update_info").value='1';
			document.forms["formular"].submit();
		}
	}
	
}
function returnmenusearch()
{
	//alert("hai");
	var id1=document.getElementById("city_info");
	var id2=document.getElementById("keyword");
	var id3=document.getElementById("category");
	if(id1.value=='' && id2.value=='' && id3.value=='')
	{
		alert("Please enter atleast one search term");
		return false;
	}
	else
	{
		return true;
	}
}
function listing_delete(p_id)
{
	var value = confirm("Are you sure to delete this listing ?");
	if(value==true)
	{	
		//alert(weblink+"delete-listing/" + p_id);
		window.location=weblink+"delete-listing/" + p_id;
	}
	else
	{
		window.location=weblink+'my-listings';
	}
}

/**
 *  Sowjanya code
 */
function regvalidate()
{
	var id1=document.getElementById("username1");
	var id2=document.getElementById("password1");
	var lbl=document.getElementById("valid");
	if(checkTextEmpty(id1,"Email address",lbl) && validateEmail(id1,"Email address",lbl) && checkTextEmpty(id2,"Password",lbl) &&
			pwdminimum_lengths(id2,'Password should be atleast 8 characters',8,lbl))
	{
		return true;
	}
	else return false;
}
function contactuspage()
{
	window.location = weblink+'welcome/contact_us';
}
function registervalidate()
{
	var id2=document.getElementById('emailid');
	var id3=document.getElementById('password');
	var id4=document.getElementById('cpassword');
	var id6=document.getElementById('captcha');
	var lbl=document.getElementById('errordisplay');
	if(checkTextEmpty(id2,'Email address',lbl) && 
			validateEmail(id2,'Email address',lbl) && checkemailexist() && checkTextEmpty(id3,'Password',lbl) && 
			pwdminimum_lengths(id3,'Password should be atleast 8 characters',8,lbl) && 
			checkTextEmpty(id4,'Confirm password',lbl) && comparepasswords(id3,id4,lbl) && 
			pwdminimum_lengths(id4,'Confirm password should be atleast 8 characters',8,lbl) &&
			checkTextEmpty(id6,'Captcha',lbl) && ValidNumber(id6,'Captcha',lbl))
	{
		document.forms["register"].submit(); 
		alert('hai');
		return true;
	}
		else return false;		
				
}
function checkemailexist()
{
	var lbl=document.getElementById("errordisplay")
	var email=document.getElementById("emailid").value;
	var emstr=email.split("@");//alert("emstr0===>"+emstr[0]);alert("emstr1===>"+emstr[1]);
	xmlHttp.open('GET',weblink+"welcome/emailcheck/"+emstr[0]+"/"+emstr[1]+"", false);
	xmlHttp.send(null); 
	var str=xmlHttp.responseText;
	var str=str.replace(/^\s*([\S\s]*)\b\s*$/, '$1');
	if(str=="Exist")
	{
		lbl.innerHTML="Provided email address already exist";
		document.getElementById("emailid").value="";
		document.getElementById("password").value="";
		document.getElementById("cpassword").value="";
		return false;
	}
	else 
	{
		lbl.innerHTML=""
		return true;
	}
	
}
function forgetpassword_validate()
{
	var id1=document.getElementById("emailid");
	var lbl=document.getElementById("errordisplay");
	if(newcheckTextEmpty(id1,'Email address',lbl) && newvalidateEmail(id1,'Email address',lbl) && checkuserexistemail())
	{
		
	}
	else
	{		
			return false;
	}
}
	function restpswd_validate()
	{
		var id1=document.getElementById("newpwd");
		var id2=document.getElementById("confirmpwd");
		var lbl=document.getElementById("errordisplay")
		if(checkTextEmpty(id1,"New password",lbl) && pwdminimum_lengths(id1,'New password should be atleast 8 characters',8,lbl) &&
				checkTextEmpty(id2,"Confirm password",lbl) && pwdminimum_lengths(id2,'Confirm password should be atleast 8 characters',8,lbl)  && comparepasswords(id1,id2,lbl))
		{
			return true;
		}
		else
		{
			return false;
		}
	}

/**
 * Hemachand
 * Delete Profile Photo function
*/
/********************** Delete Profile Photo Start *************************/
function delete_profile_photo(userid)
{
	var value=confirm("Are you sure you want to delete this photo?")
	if (value == true) 
	{
		//alert(weblink+'welcome/delete_profile_photo/' + userid);
		window.location = weblink+'welcome/delete_profile_photo/' + userid;
	}
	else 
	{
		window.location = weblink+'my-profile/';
	}
}
/********************** Delete Profile Photo End *************************/
/********************** Redirect To my-profile Page Code Start *************************/
function backto_my_profile()
{
		window.location = weblink+'my-profile/';
}
function backto_home()
{
		window.location = weblink;
}
function defaultextonclick()
{
	document.getElementById('autocomplete').value="";
}
function defaultextonclicks()
{
	document.getElementById('keyword').value="";
}
/********************** Redirect To my-profile Page Code End *************************/

