﻿// JScript File
function SendRequestToGoogle()
{   
    localSearch.setSearchCompleteCallback(null, 
                                                function() {                                                     
                                                    document.getElementById("sbmt").disabled = false;
                                                    if (localSearch.results[0])
                                                    {		
                                                        document.getElementById("googleX").value = localSearch.results[0].lat;
                                                        document.getElementById("googleY").value = localSearch.results[0].lng;                                                                                                                                                                                                                                                
                                                        document.getElementById("edtrSearchControl:btnSave").value = 1;
                                                        document.forms[0].submit();
                                                        
                                                    }else{
                                                        alert("Postcode not found!");                                                                                
                                                    }
                                                }
                                          );	 
    document.getElementById("sbmt").disabled = true;                                                                           		
    localSearch.execute(document.getElementById("fldLocationWithin").value + ", UK");
}



function drawMarkersOnTheMap()
{   
    for(var i=0; i<info.length;i++)
    {           
        if(coord[i][0] != "0"  &&  coord[i][1] != "0")
        {
            tmp[tpmIndex] = new Array();
            src[tpmIndex] = new Array();
            
            tmp[tpmIndex][0] = coord[i][0];
            tmp[tpmIndex][1] = coord[i][1];
            tmp[tpmIndex][2] = info[i];            
            src[tpmIndex][0] = ids[i];
            
            var qwe = 0;    
            for(var j=i+1; j<info.length; j++)
            {
                if(coord[j][0] != "0"  &&  coord[j][1] != "0")
                {
                    if(coord[j][0] == coord[i][0]  &&  coord[j][1] == coord[i][1])
                    {
                        tmp[tpmIndex][(3+qwe)] = info[j];
                        coord[j][0]=0;
                        coord[j][1]=0;
                        src[tpmIndex][qwe+1] = ids[j];
                                                
                        qwe++;
                    }
                }
            }
            tpmIndex++;
        }                                
    }    
    
    //RENDERING    
    for(var i=0; i<tmp.length; i++)
    {   
        var point = new GLatLng(tmp[i][0],tmp[i][1]);                                     
        var txt = "";        
        
        if(tmp[i].length == 3)
        {
            //normal
            txt = tmp[i][2];
        }
        else
        {
            //multi
            for(var r=2; r < tmp[i].length; r++)
            {
                if(r == 2)                                
                    txt += "<div style='position:relative;heigth:250px;' id='" + i + "" + r + "'>";
                else
                    txt += "<div style='position:relative; display:none;heigth:250px;' id='" + i + "" + r + "'>";
                    
                txt += "<br/>";                    
                txt += "<div style='position:relative; text-align:center; margin-bottom:10px;'>";                
                if(r != 2)
                    txt += "<a href='javascript:changeDiv(" + i + "" + r + ", " + i + "" + (r-1) + ")'>Previous</a>&nbsp;&nbsp;&nbsp;";
                    
                txt += "<b>" + (r - 1) + " of " + (tmp[i].length - 2) + " Vacancies</b>";
                    
                if(r != (tmp[i].length - 1))                    
                    txt += " &nbsp;&nbsp;&nbsp; <a href='javascript:changeDiv(" + i + "" + r + ", " + i + "" + (r+1) + ")'>Next</a>";
                    
                
                txt += "</div>";
                
                txt += tmp[i][r];
                txt += "</div>";
            }
        }
        
        var marker = createMarker(point,"<div style='margin-bottom:-90px;position:relative;width:250px;heigth:250px;'>" + txt + "</div>")
        
        var functionName = "fnc" + i;
        var resStr = "function " + functionName + "() { simpleRedirect(" + i + ");}";
        eval(resStr);
        
        GEvent.addListener(marker, "click", eval(functionName));
        map.addOverlay(marker);
    }    
}
//-----------------------------------------------------------------------------------
function simpleRedirect(i)
{      
    var str = "";
    for(var k=0; k< src[i].length; k++)
    {
        str += src[i][k] + ",";
    }                                                                                                
    
    if(str.length > 0)                                                                   
    {
        str = str.substring(0, str.length-1);
        window.location.href = "job_details.aspx?ID=" + src[i][0] + "&other=" + str + "&back=1";
    }
}
//-----------------------------------------------------------------------------------
function createMarker(point,html) {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "mouseover", function() {
                                            marker.openInfoWindowHtml(html);
                              }
                       );                                   
    return marker;
}                 
//-----------------------------------------------------------------------------------
