﻿//Widgets operation, all functionality will be placed or derived in same object.
function createwidget(objCSW)
{
    var serviceRoot ='../../Nearby_Places300x250';
    var widgeturl= serviceRoot;
    widgeturl += "?";
    if(typeof objCSW.what == "undefined" && typeof objCSW.tags == "undefined" )
    {
    throw 'undefined what/tags';
    return;
    }
    
    if(typeof objCSW.url == "undefined" && typeof objCSW.callback == "undefined" )
    {
    throw 'undefined url/callback';
    return;
    }
    if(typeof objCSW.what == "" && typeof objCSW.tags == "" )
    {
    throw 'empty what/tags';
    return;
    }
    if(typeof objCSW.url == "" && typeof objCSW.callback == "" )
    {
    throw 'empty url/callback';
    return;
    }

    if(typeof objCSW.publisher == "undefined" || objCSW.publisher == '')
    {
        throw 'undefiend publisher';
        return;
    }
    
    if(typeof objCSW.what == "undefined")
        objCSW.what = '';
    if(typeof objCSW.where == "undefined")
        objCSW.where = '';
    if(typeof objCSW.lat == "undefined")
        objCSW.lat = '';
    if(typeof objCSW.lon == "undefined")
        objCSW.lon = '';

    if(typeof objCSW.tags == "undefined")
        objCSW.tags = '';
    if(typeof objCSW.radius == "undefined")
        objCSW.radius = '';
    if(typeof objCSW.url == "undefined")
        objCSW.url = '';
    if(typeof objCSW.callback == "undefined")
        objCSW.callback = '';

    widgeturl+='what='+objCSW.what;
    widgeturl+='&where='+objCSW.where;
    widgeturl+='&publishercode='+objCSW.publisher;
    widgeturl+='&lat='+objCSW.lat;
    widgeturl+='&lon='+objCSW.lon;
    widgeturl+='&tags='+objCSW.tags;
    widgeturl+='&radius='+objCSW.radius;
    widgeturl+='&placement=&apikey=test';
    widgeturl+='&callbackfunction=' + objCSW.callback;
    widgeturl+='&callbackURL=' + objCSW.url;
    //document.write(widgeturl);
    
    var XMLHTTP=null;
    try {
        XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (oc) {
            XMLHTTP = null;
        }
    }
    //Creating object in Mozilla and Safari
    if (!XMLHTTP && typeof XMLHttpRequest != "undefined") {
        XMLHTTP = new XMLHttpRequest();
    }
    XMLHTTP.open("GET", widgeturl , true);
    XMLHTTP.onreadystatechange = function() {//Call a function when the state changes.
        if (XMLHTTP.readyState == 4 && (XMLHTTP.status == 200||XMLHTTP.status == 0) ) {

            try {
                if (XMLHTTP.readyState == 1)
                    return;
                if (XMLHTTP.readyState == 4) {
                    //Valid Response is received
                    if ((XMLHTTP.status == 200||XMLHTTP.status == 0)) {
                        var sScript = "";
                        sScript = XMLHTTP.responseText;
                       
                        document.getElementById(objCSW.target).innerHTML = sScript;
                        XMLHTTP = null;
                    }
                }
            }
            catch (e) {
            }
            return;
        }

    }
    XMLHTTP.send(null);
}
function QSObject(querystring){ 
    //Create regular expression object to retrieve the qs part 
    var qsReg = new RegExp("[?][^#]*","i"); 
    hRef = unescape(querystring); 
    var qsMatch = hRef.match(qsReg); 
    //removes the question mark from the url 
    qsMatch = new String(qsMatch); 
    qsMatch = qsMatch.substr(1, qsMatch.length -1); 
    //split it up 
    var rootArr = qsMatch.split("&"); 
    for(i=0;i<rootArr.length;i++){ 
        var tempArr = rootArr[i].split("="); 
        if(tempArr.length ==2){ 
            tempArr[0] = unescape(tempArr[0]); 
            tempArr[1] = unescape(tempArr[1]); 
            if(tempArr[0]=='var')
            {
                document.write('<script type=\"text/javascript\">createwidget('+tempArr[1]+');<\/script>');
            }
        } 
    } 
} 
var scriptSrc = document.getElementById("CSWScript").src.toLowerCase();
qs = new QSObject(scriptSrc); 

@@ -132,14 +132,88 @@
 ot =
-'../..
+ document.location.hostname + '/' + document.location.pathname.split('/')%5B1%5D + '
 /Nea
@@ -415,37 +415,33 @@
   return;%0A    %7D%0A
-    
 %0A
+
     if(typeof ob
@@ -942,21 +942,17 @@
 ;%0A    %7D%0A
-    
 %0A
+
     if(t
@@ -1946,21 +1946,17 @@
 eturl);%0A
-    
 %0A
+
     var 
@@ -2937,32 +2937,9 @@
 xt;%0A
-                       
 %0A
+
     
@@ -3244,17 +3244,16 @@
 string)%7B
- 
 %0A    //C
@@ -3307,17 +3307,16 @@
  qs part
- 
 %0A    var
@@ -3351,17 +3351,16 @@
 *%22,%22i%22);
- 
 %0A    hRe
@@ -3385,17 +3385,16 @@
 string);
- 
 %0A    var
@@ -3422,17 +3422,16 @@
 (qsReg);
- 
 %0A    //r
@@ -3467,17 +3467,16 @@
  the url
- 
 %0A    qsM
@@ -3502,17 +3502,16 @@
 sMatch);
- 
 %0A    qsM
@@ -3554,17 +3554,16 @@
 gth -1);
- 
 %0A    //s
@@ -3572,17 +3572,16 @@
 it it up
- 
 %0A    var
@@ -3610,17 +3610,16 @@
 it(%22&%22);
- 
 %0A    for
@@ -3645,17 +3645,16 @@
 th;i++)%7B
- 
 %0A       
@@ -3690,17 +3690,16 @@
 it(%22=%22);
- 
 %0A       
@@ -3722,17 +3722,16 @@
 th ==2)%7B
- 
 %0A       
@@ -3769,17 +3769,16 @@
 Arr%5B0%5D);
- 
 %0A       
@@ -3816,17 +3816,16 @@
 Arr%5B1%5D);
- 
 %0A       
@@ -4000,19 +4000,16 @@
    %7D
- 
 %0A    %7D
- 
 %0A%7D
- 
 %0Avar
@@ -4077,16 +4077,16 @@
 Case();%0A
+
 qs = new
@@ -4106,10 +4106,9 @@
 iptSrc);
- 
 %0A

change nearby url to hit for cswidget js