//var baseurl="http://www.bctoad.com/;


function trim(s)
{
	return rtrim(ltrim(s));
}

function ltrim(s)
{
	var l=0;
	while(l < s.length && s[l] == ' ')
	{l++;}
	return s.substring(l, s.length);
}

function rtrim(s)
{
	var r=s.length -1;
	while(r > 0 && s[r] == ' ')
	{r-=1;}
	return s.substring(0, r+1);
}


function trimEnter(s)
{
	return ltrimEnter(rtrimEnter(rtrim(ltrim(s))));
}

function ltrimEnter(s)
{
	var l=0;
	while(l < s.length && s.charCodeAt(l) == 10)
	{l++;}
	return s.substring(l, s.length);
}

function rtrimEnter(s)
{
	var r=s.length -1;
	while(r > 0 && s.charCodeAt(r) == 10)
	{r-=1;}
	return s.substring(0, r+1);
}



function changemenucss(divId,keyword,location)
{
      var menuids= new Array("uads","sforum","ucomments","uarticles","upress","ublog","upage");
      for (menuitem in menuids)
      {     
            
            if(menuids[menuitem]==divId)
                  {
                  document.getElementById(menuids[menuitem]).setAttribute('style', 'color: #1157A4;background-color:  #EAEAEA;border-right:#EAEAEA solid 12px;border-left:#EAEAEA solid 12px; ');
                  getadOfferdata(divId,keyword,location);
                  }
            else
                  document.getElementById(menuids[menuitem]).setAttribute('style', 'color: #676767;background-color: #FEFEFE;border-right:#FEFEFE solid 12px;border-left:#FEFEFE solid 12px;');                   
            
      }
}

function getadOfferdata(obj,keyword,location)
{
      //str = obj.value; 
      //alert(obj);
      
       if(obj=="sforum")
            qstring=baseurl+"ajax/adofferforum.php?keyword="+keyword+"&location="+location;
                
             else
       if(obj=="uarticles")
             qstring=baseurl+"ajax/adofferarticle.php?keyword="+keyword+"&location="+location;
                 
             else
       if(obj=="ucomments")
             
    
     qstring=baseurl+"ajax/addcomment.php?keyword="+keyword+"&location="+location;
   else
     if(obj=="ublog")
             
             qstring=baseurl+"ajax/addofferblog.php?keyword="+keyword+"&location="+location;
     else
     if(obj=="uads")
             
             {
                 var url          =document.URL;
             
             qstring=baseurl+"ajax/addads.php?keyword="+keyword+"&location="+location+"&url="+url;
             }
     else if(obj=="upress")
             
             qstring=baseurl+"ajax/addpress.php?keyword="+keyword+"&location="+location;
             
       else{
             document.getElementById("addofferOuterdiv").innerHTML='<div id="addurofferads" style="display: none;"><iframe scrolling="no" height="100%" width="100%" src="'+baseurl+'/add2.php"></iframe></div>';
             document.getElementById("addurofferads").style.display="block";
             return;
             }
      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttpMC=new XMLHttpRequest();
      }
      else
      {// code for IE6, IE5
            xmlhttpMC=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttpMC.onreadystatechange=function()
      {
           
                  
            if (xmlhttpMC.readyState==4 && xmlhttpMC.status==200)
            {
             //document.getElementById("addofferOuterdiv").innerHTML='<div id="addurofferads" style="display: none;"><iframe scrolling="no" height="100%" width="100%" src="'+baseurl+'/add2.php"></iframe></div>'+xmlhttpMC.responseText;
             document.getElementById("addofferOuterdiv").innerHTML=xmlhttpMC.responseText;
             //document.getElementById("addurofferads").style.display="none";
            }
      }
      

      xmlhttpMC.open("GET",qstring,true);
      xmlhttpMC.send();
    }
    
    
    function adreply(aid)
            {
                var addids= new Array("1","2","3");
               
        
              for (additem in addids)
                 {
                     if(addids[additem]==aid)
                      {  
                          //alert(aid+"replytxt");
                      document.getElementById(addids[additem]).style.height="170px";     
                      document.getElementById(addids[additem]).style.display="block";
                      document.getElementById(addids[additem]+"replytxt").value="Enter your message...";
                      document.getElementById(addids[additem]+"replytxt").style.border="1px solid #83877a ";
                      document.getElementById(addids[additem]+"adreply_name").style.border="1px solid #83877a";
                      document.getElementById(addids[additem]+"adreply_email").style.border="1px solid #83877a";
                      document.getElementById(addids[additem]+"adreply_mobile").style.border="1px solid #83877a";
                      document.getElementById(addids[additem]+"adreply_name").value="";
                      document.getElementById(addids[additem]+"adreply_email").value="";
                      document.getElementById(addids[additem]+"adreply_mobile").value="+91";
//                      document.getElementById(addids[additem]+"adreply").style.display="none";
                      document.getElementById(addids[additem]+"errordiv").style.display="none";
                      }
                   else
                       {
                          document.getElementById(addids[additem]).style.display="none";
                          document.getElementById(addids[additem]+"adreply").style.display="block";
                       }
                 }
             }
            
                function closereply(aid)
                                    {
                                          var addids= new Array("1","2","3");
               
        
                              for (additem in addids)
                               {
                                 if(addids[additem]==aid)

                                  document.getElementById(addids[additem]).style.display="none";
                                  document.getElementById(addids[additem]+"adreply").style.display="block";
                                  document.getElementById(addids[additem]+"errordiv").style.display="none";
                                  
                                 
                                }
                                         
                                     }
                                    
            


function insert(aid)
{
   //alert(txtreply);
   
   {
                var addids= new Array("1","2","3");
               
        
              for (additem in addids)
                 {
                     if(addids[additem]==aid && document.getElementById(addids[additem]+"replytxt").value=="Enter your message...")
                      {  
                          //alert(aid+"replytxt");
                            
                      
                      document.getElementById(addids[additem]+"replytxt").value="";
                      }
                  
                 }
             }
   
}

function insertadreplydetails(mainid,addid,message1,name,email1,mobile)
{
  
   var addid =document.getElementById(addid).value;
   var message=trim(document.getElementById(message1).value);
   
   var name=document.getElementById(name).value;
   var email=validateEmail(trim(document.getElementById(email1).value));
  // alert(email)
  var email2=trim(document.getElementById(email1).value);
//  alert(email2);
  var mobile2=trim(document.getElementById(mobile).value);
   var mobile=validateadPhoneNumber(trim(document.getElementById(mobile).value));
  
   var url          =document.URL;
    
   var errorid= new Array("1","2","3");
     for (erroritem in errorid)
     {  
                
            if(errorid[erroritem]==mainid)
              {
                document.getElementById(errorid[erroritem]).style.height="200px";
                document.getElementById(errorid[erroritem]+"errordiv").style.display="block";
                document.getElementById(errorid[erroritem]+"errordiv").style.border="1px solid red";
                

                     if(message=="Enter your message..."||message==null || message=="")
                       {
                       document.getElementById(errorid[erroritem]+"errormessage").innerHTML="&nbsp;&nbsp;Please enter your message"; 
                       document.getElementById(errorid[erroritem]+"replytxt").style.border="1px solid red";
                       }
                      else if((!email)||(!mobile))
                      { 
                        
                        document.getElementById(errorid[erroritem]+"replytxt").style.border="1px solid #83877a";  
                        document.getElementById(errorid[erroritem]+"errormessage").innerHTML="&nbsp;&nbsp;Please enter valid contact details"; 
                        document.getElementById(errorid[erroritem]+"adreply_email").style.border="1px solid red";
                        document.getElementById(errorid[erroritem]+"adreply_mobile").style.border="1px solid red";
                        return false;
                      }
                     else
  
                    {
                   //alert("email");
        
                 qstring=baseurl+"ajax/addadreplydetails.php?message="+message+"&name="+name+"&email="+email2+"&mobile="+mobile2+"&addid="+addid+"&url="+url;  
                 document.getElementById(errorid[erroritem]).style.display="none";
                 /*document.getElementById("1").style.display="none";"&addid="+addid
                 document.getElementById("2").style.display="none";
                 document.getElementById("3").style.display="none";
                 document.getElementById("4").style.display="none";*/

                  if (window.XMLHttpRequest)
                  {// code for IE7+, Firefox, Chrome, Opera, Safari
                        xmlhttpad=new XMLHttpRequest();
                  }
                  else
                  {// code for IE6, IE5
                        xmlhttpad=new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  xmlhttpad.onreadystatechange=function()
                  {


                        if (xmlhttpad.readyState==4 && xmlhttpad.status==200)
                        {
                            //alert(xmlhttpad.responseText);
                         //document.getElementById("addofferOuterdiv").innerHTML='<div id="addurofferads" style="display: none;"><iframe scrolling="no" height="100%" width="100%" src="'+baseurl+'/add2.php"></iframe></div>'+xmlhttpMC.responseText;
                         document.getElementById("adreplyconfirm").innerHTML=xmlhttpad.responseText;
                         //document.getElementById("addurofferads").style.display="none";
                        }
                  }


                  xmlhttpad.open("GET",qstring,true);
                  //alert(qstring);
                  xmlhttpad.send();

                }

        
            
              }
         else
           {
                 document.getElementById(errorid[erroritem]).style.height="170px";
                 document.getElementById(errorid[erroritem]+"errordiv").style.display="none";  
            }
       }
    
}


function closeadreplypopup()
{
//       document.getElementById("adreplypopup").style.display="none";
        $("#adreplypopup").fadeOut("slow",function() {
                                          greyout(false);});
       document.getElementById("1adreply").style.display="block";
       document.getElementById("2adreply").style.display="block";
       document.getElementById("3adreply").style.display="block";
       //document.getElementById("4adreply").style.display="block";
     
    
}

function deletereplyad()
{
  document.getElementById("adreplypopup").style.height="100px"   
  document.getElementById("viewad").style.display="none"  
  document.getElementById("againpostadddetails").style.display="none" 
  document.getElementById("againpostadd").style.display="none";
 document.getElementById("deletemsg").style.display="none";
 document.getElementById("msgsent").style.border="1px solid green ";
 document.getElementById("msgsent2").innerHTML="&nbsp;Your ad has been deleted successfully.";
}

