// Script Fro Yasik
var itemName = "";
function getLocYasik(item) {
    itemName = item;
    navigator.geolocation.getCurrentPosition(getLocYasikSuccess, errorHandler, {timeout:10000});
}

function getLocYasikSuccess(position) {
    location.href = "getData.php?latitude=" + position.coords.latitude + "&longitude=" + position.coords.longitude + "&item=" + itemName;
}

function search() {
    getLocYasik(document.getElementById('stext').value);
}

function call(id, telno){
    var req;
    var url = "call.php?id=" + id;

    if(window.XMLHttpRequest){
        req = new XMLHttpRequest();
    } else if(window.ActiveXObject){
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.open("Get",url,true);
    req.send("");
    location.href="tel:" + telno;
}

// Script For OPI
var option = 0;
function getLoc(opt) {
    option = opt;
    navigator.geolocation.getCurrentPosition(getLocationSuccess, errorHandler, {timeout:10000});
}

function getLocationSuccess(pos) {
    location.href = "getData.php?lat=" + pos.coords.latitude + "&lng=" + pos.coords.longitude + "&opt=" + option;
}

function updateData() {
    var req;
    var url = "update.php";

    if(window.XMLHttpRequest){
        req = new XMLHttpRequest();
    } else if(window.ActiveXObject){
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.open("Get",url,true);
    req.send("");
}

function getMap(lat, lng, opt, name) {
    location.href = "getMap.php?latitude=" + lat + "&longitude=" + lng + "&name=" + name + "&clat=" + clat + "&clng=" + clng + "&opt=" + opt;
}

// Script For Common
function errorHandler(error) {
    if (error.code == 0)
        alert("Unknown Error Occured");
    else if (error.code == 1)
        alert("Permission Denied");
    else if (error.code == 2)
        alert("Position Unavailable");
    else if (error.code == 3)
        alert("Time Out");
    else
        alert("Error");
}

