// JavaScript Document

function cat_search_validation()
{
		catsearch = document.getElementById('catquery');
		
		
	if(catsearch.value == "Search Category" ||  catsearch.value == "" )
	{		
		alert("Oops! What I have to find?");
		catsearch.focus();
		return false;
	}
	
      if(catsearch.value != "" )
	{		
	  field=catsearch.value;
	  var temp = field;

var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
var obj = / +/g;
temp = temp.replace(obj, " ");
if (temp == " ") { temp = ""; }
catsearch.value=temp;
catsearch.focus();


  	var len=field.length;
  	var a=field.substring(len-1,len)
       if(a=="\\" || a=="'" || a=="\"" )
	   {
	   catsearch.value=field.slice(0,len-1);
	   catsearch.focus();
	   }


	   var len1=field.length;
  	   var a1=field.substring(0,1)
       if(a1=="\\" || a1=="'"  || a1=="\"" )
	   {
	   catsearch.value=field.slice(1,len);
	   catsearch.focus();
	   }





if(catsearch.value == "" )
	{		
		alert("Oops! What I have to find?");
		topsearch.focus();
		return false;
	}

	}

  
return true;

		
}




function top_validation()
{
	topsearch = document.getElementById('top');
     if(topsearch.value == "what are you looking for?" ||  topsearch.value == "" ||  topsearch.value == "What are you looking for in Business Directory?" ||  topsearch.value == "What are you looking for in Jobs?" ||  topsearch.value == "What are you looking for in For Sale?" ||  topsearch.value == "What are you looking for in For Rent?" ||  topsearch.value == "What are you looking for in Movies?")
    {		
       alert("Oops! What I have to find?");	topsearch.focus();return false;

	}


  if(topsearch.value != "" ){		

		field=topsearch.value;
        var temp = field;
        var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
          if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
             var obj = / +/g;
             temp = temp.replace(obj, " ");

   if (temp == " ") { temp = ""; }

  topsearch.value=temp;

  topsearch.focus();

  

  

  	var len=field.length;

  		 var a=field.substring(len-1,len)

       if(a=="\\" || a=="'" || a=="\"" )

	   {

	   topsearch.value=field.slice(0,len-1);

	    topsearch.focus();

	   }

	   

	   var len1=field.length;

  		 var a1=field.substring(0,1)

		

       if(a1=="\\" || a1=="'"  || a1=="\"" )

	   {

	   topsearch.value=field.slice(1,len);

	    topsearch.focus();

	   }
             var last_char = topsearch.value.charAt(topsearch.value.length-1);
			 if(last_char=="\\" || last_char=="'" || last_char=="\"" ){topsearch.value= topsearch.value.slice(0,topsearch.value.length-1) }




if(topsearch.value == "" )

	{		

		alert("Oops! What I have to find?");

		topsearch.focus();

		return false;

	}

	}

  

  

  

return true;

}







function validation()

{

    

		topsearch = document.getElementById('home-what');

	what = document.getElementById('home-what');

	area = document.getElementById('area_middle');

  

 

  if(what.value == "" && area.value == ""  )

	{		

		alert("Oops! What I have to find?");

		what.focus();

		return false;

	}

	

	    if(what.value == "" && area.value != ""  )

	{		

		alert("Oops! What I have to find?");

		what.focus();

		return false;

	}

 

	

	  if(topsearch.value != "" )

	{		

		field=topsearch.value;

	  var temp = field;



   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;

   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }

   var obj = / +/g;

   temp = temp.replace(obj, " ");

   if (temp == " ") { temp = ""; }

  topsearch.value=temp;

  topsearch.focus();

  



		var len=field.length;

  		 var a=field.substring(len-1,len)

       if(a=="\\" || a=="'"  || a=="\"" )

	   {

	   topsearch.value=field.slice(0,len-1);

	    topsearch.focus();



	   }

	   

	    var len1=field.length;

  		 var a1=field.substring(0,1)

		

       if(a1=="\\" || a1=="'"  || a1=="\"" )

	   {

	   topsearch.value=field.slice(1,len);

	    topsearch.focus();

	

	   }



   if(what.value == "" && area.value == ""  )

	{		

		alert("Oops! What I have to find?");

		what.focus();

		return false;

	}

	

	    if(what.value == "" && area.value != ""  )

	{		

		alert("Oops! What I have to find?");

		what.focus();

		return false;

	}





	}	

	return true;

}



function contact()

{



	yourname = document.getElementById('name');

	youremail = document.getElementById('email');

	yourphone = document.getElementById('phone_no');

	yourdescription = document.getElementById('description');

	yourquestion = document.getElementById('question');

	

	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

	var numExp = /^[0-9]+$/;

	

  if( yourname.value == "")

	{

	 alert("Name is Required");

     yourname.focus();

     return false;  

  }

   if( youremail.value == "" && yourphone.value == "")

	{

	 alert("Email / Phone No is Required");

     youremail.focus();

     return false;  

  }

  else

  {

	  if(youremail.value != "")

	  {

	    if(!youremail.value.match(emailExp))

		{		

			alert("Invalid Email Format");

			youremail.focus();

			return false;

		}

	  }

	  else  if( yourphone.value == "")

			{

			 alert("Phone No is Required");

			 yourphone.focus();

			 return false;  

			}

			else if(!yourphone.value.match(numExp))

				 {		

					alert("Invalid Phone Number");

					yourphone.focus();

					return false;

				 }

  }

  

  //if( yourphone.value.length != 10 )

//	{

//	 alert("Invalid Phone Number");

//     yourphone.focus();

//     return false;  

//  }



 if( yourquestion.value == "0")

 {

	 alert("You must select an appropriate subject");

     yourquestion.focus();

     return false;  

  }

  



  if( yourdescription.value != "")

  {

	  var temp = yourdescription.value;

      var obj = /^(\s*)([\W\w]*)(\b\s*$)/;

      if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }

      var obj = / +/g;

      temp = temp.replace(obj, " ");

      if (temp == " ") { temp = ""; }

      yourdescription.value=temp;

   } 

   

   

     if( yourdescription.value == "")

  {

	 alert("Message is Required");

     yourdescription.focus();

     return false;  

  } 

   

      return true;

}



function review()

{



	username = document.getElementById('user_name');

	useremail = document.getElementById('email');

	userdescription = document.getElementById('description');

	

	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

	//var numExp = /^[0-9]+$/;

	

  if( username.value == "")

	{

	 alert("Name is Required");

     username.focus();

     return false;  

  }

    

	if( useremail.value == "")

	{

	 alert("Email is Required");

     useremail.focus();

     return false;  

  }

  if(!useremail.value.match(emailExp))

	{		

		alert("Invalid Email Format");

		useremail.focus();

		return false;

	}

	

	 if( userdescription.value == "")

	{

	 alert("Description is Required");

     userdescription.focus();

     return false;  

  }

  

	

	

  return true;



}

function post_add()

{

	area = document.getElementById('area_id');

	if( area.value == "")

	{

	 alert("Location is Required");

     area.focus();

     return false;  

  }

  return false;

	

}

