
//---------------------------------------------------------------------SEARCH PAGE JAVASCRIPT

// Important Line---------------------------------------

  onload=function(){


// get all the chiild elements of GFilter and 
var gFilterArray = new Array();
gFilterArray = $("a[name=nik]");   //$("input[name=first_name]");
 //document.getElementsByTagName("nik");
    for (var i=0; i< gFilterArray.length; i++)
        {
            if(gFilterArray[i].id !=undefined)
            { //alert("id = ss" + gFilterArray[i].id + "ddd");
                     if (gFilterArray[i].id.indexOf("tag")!= -1)
                        { //alert(document.getElementById(gFilterArray[i].id).innerHTML + "  " +  '<%=searchString %>');
                           //alert("searchString = " + searchString);
                           var searchStrArr = searchString.toLowerCase().split(" ");   
                           for(var j=0; j<searchStrArr.length; j++)  
                           {  //alert("array[j] = " + searchStrArr[j] + "match it with = "+ (document.getElementById(gFilterArray[i].id).innerHTML).toLowerCase());  
                               if(searchStrArr[j]==(document.getElementById(gFilterArray[i].id).innerHTML).toLowerCase())
                                   {//alert("yo");
                                    $("#" + gFilterArray[i].id).addClass("tagselected");
                                    //alert("id = "+gFilterArray[i].parentNode.parentNode.childNodes[1].id);
                                    var lp= gFilterArray[i].parentNode.parentNode.firstChild;
                                    if(lp.id==undefined){lp=next(lp);}
                                    //alert(lp.id);
                                    $("#" + lp.id).removeClass("Gbuttonall");
                                    break;                                   
                                   }
                           }
                              
                                //else{alert(searchString.toLowerCase() + "  " + document.getElementById(gFilterArray[i].id).innerHTML.toLowerCase() + "  " + searchString.toLowerCase().indexOf(document.getElementById(gFilterArray[i].id).innerHTML.toLowerCase()) );}
                        }
            }
        }
       

//var selectTag =  '<% =selectTag.replace("A", "^A")%>';        

    }   
     
 
 // Important Line---------------------------------------

    var cityflag=0;
    var keyFag = 0;
    function clear(id)
    {
    //alert();
        if(cityFlag==0){ document.getElementById("cityInput").value="ALL"; cityFlag=1;}
        if(keyFlag==0){document.getElementById("keyInput").value=""; keyFlag=1;}
    }
   
   var hideFilter=0; 
    function showHideFil(id)
    { alert("shhbbh");
        if(hideFilter==0)
        {  hide(id);
            hideFilter=1;
        }
        else
        {
        show(id);
        hideFilter=0;
        }
    }
    
    function closepopup(id)
        {
            document.getElementById(id).style.display='none';     
        }
function sendInfo()
   {
   urlTest('divSendInfo');
   }
   
   function urlTest(divId){
var flag=1;
//alert("in urltest");
$('.hasValidator' , '#' + divId).each(function(){
$(this).removeClass("GformError");
        document.getElementById("lbl" + this.id).innerHTML="";
});


$('.regexp' , '#' + divId).each(function(){

   if(this.name=='myUrl')  
   {
        var url = document.getElementById(this.id).value;
        var regurl = /^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/;
        if (regurl.test(url) || url=="")
        {
        }
        else
        {
            $("#" + "lbl" + this.id).html("URL is not valid, Ex:http://www.school.com");
            $("#" + "lbl" + this.id).fadeIn("fast");
            $(this).addClass("GformError");
            flag=0;
        }
   }   
   
   if(this.name=='email')
   {
        var email = document.getElementById(this.id).value;
        var regEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/;
        if (regEmail.test(email) || email=="")
        {
        }
        else
        {
            $("#" + "lbl" + this.id).html(this.name + " is not valid");
            $("#" + "lbl" + this.id).fadeIn("fast");
            $(this).addClass("GformError");
            flag=0;
        }
   }
   if(this.name=='contact')
   {
        var contact = document.getElementById(this.id).value;
        var regcontact = /^\d{10}$/;
        if (regcontact.test(contact) || contact=="")
        {
        }
        else
        {
            $("#" + "lbl" + this.id).html(this.name + " is not valid");
            $("#" + "lbl" + this.id).fadeIn("fast");
            $(this).addClass("GformError");
            flag=0;
        }
   }
   if(this.name=='paswd')
   {
        if (document.getElementById(this.id).value.length<6)
        {
            $("#" + "lbl" + this.id).html("The login id and password do not match");
            $("#" + "lbl" + this.id).fadeIn("fast");
            $(this).addClass("GformError");
            flag=0;
        }
        //alert("thismypasswd");
   }

        
    });


$('.required' , '#' + divId).each(function(){

       if(this.value=="")
        {
        //alert(this.id);
        if(this.name=="paswd")
        $("#" + "lbl" + this.id).html("password cannot be empty");
        else
        $("#" + "lbl" + this.id).html(this.name + " cant be empty");
        $("#" + "lbl" + this.id).fadeIn("fast");
        //add some class to highlight error
        $(this).addClass("GformError");
        flag=0;
        }
       }); 
        
       // alert("divid=" + divId);
       // alert(divId.indexOf("GdsStp11"));
         if(flag==0){
         return false;}
         else if (divId=="divSendInfo")
        {
                 $("#iconSendInfo").removeClass("hide");
        if (document.getElementById("txtSMSEmail").value=="" && document.getElementById("txtSMSPhone").value=="")
        {
        document.getElementById("lbltxtSMSEmail").innerHTML="Enter email and/or mobile No.";
        $("#lbltxtSMSEmail").fadeIn("fast");
          $("#iconSendInfo").addClass("hide");
        }
        else
        {
        var loadUrl = "../genAjax.aspx/?fun=sendInfo&schoolid=" + document.getElementById("hidSchoolid").value + "&name=" + document.getElementById("txtSMSName").value.replace("&","!@$%^") + "&email=" + document.getElementById("txtSMSEmail").value + "&phone="+document.getElementById("txtSMSPhone").value.replace("&","!@$%^") + "&captchaTxt=" + document.getElementById("txtCaptchaSMS").value.replace("&","!@$%^") + "&dum="+ new Date();
	        var callback = 
	         {
            	 success: function(o) 
            	 {
            	 if (o.responseText=="01")
            	 {
            	 closepopup('GpopSMSEM');
            	  $('#ctl00_ContentPlaceHolder1_errorField').html("The information has been sent");
                    $('#ctl00_ContentPlaceHolder1_errorField').fadeIn("fast"); 
                    document.getElementById("txtCaptchaSMS").value="";
            	 }
            	 else
            	 {
            		 document.getElementById("captcha1").src = ".." + o.responseText.substring(1);
            	 }
            	 
            	 $("#iconSendInfo").addClass("hide");
            	 
            	 },
            	 
	            failure: function(o) 
	            {
	                $("#iconSendInfo").addClass("hide");
                    $('#ctl00_ContentPlaceHolder1_errorField').html("There was some technical problem");
                    $('#ctl00_ContentPlaceHolder1_errorField').fadeIn("fast"); 
	            }
	        
            }
            var transaction = YAHOO.util.Connect.asyncRequest('GET', loadUrl, callback, null);
            }
        }
   
}

function showpopup(id)
        {
            var winwidth=document.body.clientWidth;
            document.getElementById(id).style.display='block';
            document.getElementById(id).style.left=(winwidth -500)/2 + 'px';
            
             var pageY;
                if(typeof(window.pageYOffset)=='number') {
                   pageY=window.pageYOffset;
                }
                else {
                   pageY=document.documentElement.scrollTop;
                }
            document.getElementById(id).style.top=pageY + 100 + 'px';
        
        }
function setSchoolId(id)
{
document.getElementById("hidSchoolid").value=id;
}

    function ajaxFuncPage()
{
var url = "genAjax.aspx?captcha=1&dum="+ new Date();
//alert("url = " + url);
	var req = getXMLHTTP();
	if (req) 
	{
		req.onreadystatechange = function() 
		{
			 if (req.readyState == 4) 
			 {
			    // only if "OK"
			    if (req.status == 200) 
			    {
			    //alert("a = " + req.responseText);
			    var a = req.responseText;
			    
			        if(a!=0)
			          {
                        //document.getElementById("capImg").innerHTML = "<img src='" + a + "'/>";
                         document.getElementById("captcha1").src = ".." + a;
                      }
                    
                    else 
                      {
                        $("#ctl00_ContentPlaceHolder1_techErr").html("There is some technical problem");
			            $("#ctl00_ContentPlaceHolder1_errorField").html("There is some technical problem.");
                        $("#ctl00_ContentPlaceHolder1_errorField").fadeIn("fast"); 
                      } 
			    
			    } 
			    else 
			    {
			           
			           $("#ctl00_ContentPlaceHolder1_techErr").html("There was a problem while using XMLHTTP:\n" + req.statusText);
			           $("#ctl00_ContentPlaceHolder1_errorField").html("There is some technical problem.");
                       $("#ctl00_ContentPlaceHolder1_errorField").fadeIn("fast");    
			    }
		     }				
		}			
		req.open("GET", url, true);
		req.send(null);
	}	
}    

function selectFilter(domId)
{
//alert("select filter  " + domId);
var match = document.getElementById(domId).innerHTML.toLowerCase();
 
if($("#"+domId).attr('class').indexOf("tagselected") != -1)  // already selected, so deselect it 
    {//alert("frf  = "+(searchTag.innerHTML).toLowerCase().indexOf(document.getElementById(domId).innerHTML.toLowerCase()));
    $("#"+domId).removeClass("tagselected");
        if((searchTag.innerHTML).toLowerCase().indexOf(document.getElementById(domId).innerHTML.toLowerCase()) != -1)
        {//alert("yes");
        //searchTag.innerHTML = searchTag.innerHTML.replace(match,"");
        }
        var searchTagArr = (searchTag.innerHTML).toLowerCase().split(" ");
        searchTag.innerHTML="";
        //alert("length = " + searchTagArr.length);
        for (var i =0 ; i<searchTagArr.length-1;i++)
        {
            if(searchTagArr[i]==document.getElementById(domId).innerHTML.toLowerCase()){}
            else
            {
                searchTag.innerHTML = searchTag.innerHTML + " " + searchTagArr[i];
                document.getElementById(SearchTextId).value = searchTag.innerHTML;
            }
        }
        
        
    }
else // not selected, so select this filter
    {$("#"+domId).addClass("tagselected");
    
// if some filter gets selected then deselect ALL correspondig to that filter                                        
        var lp= document.getElementById(domId).parentNode.parentNode.firstChild;
        if(lp.id==undefined){lp=next(lp);}
        //alert(lp.id);
        if($("#"+lp.id).attr('class').indexOf("Gbuttonall") != -1)
        {$("#" + lp.id).removeClass("Gbuttonall");}
        
       // alert("in else");
         if((searchTag.innerHTML).toLowerCase().indexOf(document.getElementById(domId).innerHTML.toLowerCase()) != -1)
        {
        // do nothing
        }
        else
        {
            if (searchTag.innerHTML == "all") {
                searchTag.innerHTML = match;
                document.getElementById(SearchTextId).value = searchTag.innerHTML;
            }
            else {
                searchTag.innerHTML = searchTag.innerHTML + " " + match;
                document.getElementById(SearchTextId).value = searchTag.innerHTML;
            }
        
        }
    
    }
// IF ALL FILTERS GETS DESELECTED THEN SELECT ALL 

var tempArray = new Array();
var filTemp=0;
tempArray = document.getElementById(domId).parentNode.parentNode.childNodes;
    for (var i =0 ; i< tempArray.length; i++)
        {                        
             if(tempArray[i].id !=undefined)
             {   
                var chd = tempArray[i].firstChild;
                if (chd.id !=undefined)
                    {
                    
                     //alert("#"+chd.id);   
                        if($("#"+chd.id).attr('class').indexOf("tagselected") != -1)
                            {
                            filTemp=1;
                           //do nothing , get out from loop
                           break;
                            
                            }
                            else
                            {}
                    }
             }
             
             
        } // for loop ends here

        if(filTemp==0)// reselect ALL as all filters get deselected
             {
            // alert("reselect ALL as all filters get deselected ");
                    var lp= document.getElementById(domId).parentNode.parentNode.firstChild;
                    if(lp.id==undefined){lp=next(lp);}
                   // alert(lp.id);
                    if($("#"+lp.id).attr('class').indexOf("Gbuttonall") == -1)
                    {$("#" + lp.id).addClass("Gbuttonall");}
             
             }
}

function goFilter() {

    document.getElementsByName("ctl00$ContentPlaceHolder1$Uc_Search$keyInput").value = searchTag.innerHTML;
    //document.getElementsByName("ctl00$ContentPlaceHolder1$Uc_Search$btnSearch").click();
       
}   

function deSelect(elem)
{

//alert(elem.parentNode.parentNode.childNodes[0].id + "  " +elem.parentNode.parentNode.childNodes[1].id + "  "+ elem.parentNode.parentNode.childNodes[2].id + "  "+ elem.parentNode.parentNode.childNodes[3].id);
//alert("next = " + next(elem).nodeType);
var tempChild = elem.parentNode;  // li corresponding to All- li

  //alert("dekho  = " + "#"+tempChild.id);
                    if(tempChild.id!="")
                    {
                        if($("#"+tempChild.id).attr('class').indexOf("Gbuttonall") != -1)
                            {}
                        else
                             {//alert("in else");
                             $("#"+tempChild.id).addClass("Gbuttonall");}
                    }

var tempArray = new Array();
tempArray = elem.parentNode.parentNode.childNodes;
    for (var i =0 ; i< tempArray.length; i++)
        {                        
             if(tempArray[i].id !=undefined)
             {   
                var chd = tempArray[i].firstChild;
                if (chd.id !=undefined)
                    {
                    
                     //alert("#"+chd.id);   
                        if($("#"+chd.id).attr('class').indexOf("tagselected") != -1)
                            {
                            $("#"+chd.id).removeClass("tagselected");
                            var match = document.getElementById(chd.id).innerHTML.toLowerCase();
                             searchTag.innerHTML = searchTag.innerHTML.replace(match,"");
                            
                            }
                    }
             }
        }

}

        function replaceAll(str, a,b)
        {
            var indx;
             while (indx != -1){
             // Relace out the current instance.
             str = str.replace( a, b )
              
             // Get the index of any next matching substring.
             indx = str.indexOf( a );
             }
             return str;
         }

function getImage(pExistingImageID, pImageURL){alert("egtIMage");
    var img = document.createElement('img');  
    img.onload = function (evt) {  
        document.getElementById(pExistingImageID).src=pImageURL;
       // document.getElementById(pExistingImageID).width=this.width;
       // document.getElementById(pExistingImageID).height=this.height;
    }
    img.src = pImageURL;
    return false;
}         
 


function next(nod) {

    do {
        nod = nod.nextSibling;
        //alert("next sibling="+ nod.id);
    } while (nod && nod.nodeType != 1);
    return nod;                
}	

//function showMap()
//{
//var ci= document.getElementById("cityHidden").value;
////window.open("../searchMap.aspx?q=<%=searchString %>&page=<%=Request("page") %>&cityId="+ci)
//window.open("../addresses-maps-schools-in-india-search/<%=searchString %>-<%=Request("page") %>-<%=cityId %>");

//}


function loadMaps(lati, longi, cit)
{


var img  = new Image();
    img.onload=function(){
    
    alert("loaded");
    
    }
    //alert(img.complete+ "  "+ img.load);
img.src  ="http://maps.google.com/maps/api/staticmap?center=" + cit  + ",india&size=296x230&maptype=roadmap&markers=color:blue|label:S|" + lati + "," + longi+"&markers=color:green&sensor=false&key=ABQIAAAABn6jzVUgEYvHbnKgi4wSthRkXZSi1G3ctQC1ix-5vcP4z0GLzBRV-T8BF1lW2SnHzkP2_ECuWS058w";

img.setAttribute("id","mapImage");
document.getElementById("map").removeChild(document.getElementById("mapImage"));
document.getElementById("map").appendChild(img);
}


//---------------------------------------------------------------------SEARCH PAGE JAVASCRIPOT





//alert("fine2");
