var defScriptName = 'js_data.php';
var JDLoader = '/'+defScriptName;

function setJDLoader(url,sName) {
 sName = sName || defScriptName;
 JDLoader = url+"/"+sName;
}



//fillSelect(id, url, callName, varName, preLoad, postLoad, successLoad, lockMsg)



function GetOnlyCountries(id, wpo, blockFunc, postLoad) {

 gc = 'GetOnlyCountries';
 blockFunc = blockFunc || '';
 postLoad = postLoad || '';

 if (wpo && wpo>0) {gc= gc + '&wpo='+wpo;}
 
 gc = gc;

// alert(JDLoader);

 fillSelect(id, JDLoader, gc, 'OnlyCountriesArr', blockFunc, postLoad, '');

}






function GetOnlyStates(id, countryId, wpo, blockFunc, postLoad) {

 cVal = getValue(countryId);

 gc = 'GetOnlyStates';
 blockFunc = blockFunc || '';
 postLoad = postLoad || '';

 if (wpo && wpo>0) {gc= gc + '&wpo='+wpo;}
 
 gc = gc + '&cval='+cVal;

// alert(gc);

 fillSelect(id, JDLoader, gc, 'OnlyStatesArr', blockFunc, postLoad, '', '-- Select Country first --');

}



function GetOnlyCities(id, countryId, stateId, wpo, blockFunc, postLoad) {

 cVal = getValue(countryId) || "-1";
 sVal = getValue(stateId) || "-1";

 gc = 'GetOnlyCities';
 blockFunc = blockFunc || '';
 postLoad = postLoad || '';

 if (wpo && wpo>0) {gc= gc + '&wpo='+wpo;}
 
 gc = gc + '&cval='+cVal+'&sval='+sVal;

// alert(gc);

 fillSelect(id, JDLoader, gc, 'OnlyCitiesArr', blockFunc, postLoad, '', '-- Select Country and State first --');

}



function GetOnlyResorts(id, countryId, stateId, cityId, wpo, blockFunc, postLoad) {

 cVal = getValue(countryId) || "-1";
 sVal = getValue(stateId) || "-1";
 ciVal = getValue(cityId) || "-1";

 if (cVal == -1 || cVal == "-1") {

  var selItems = new Array('n_resort');
  selBlock(selItems,'-- Select Country first --');

 } else {

  gc = 'GetOnlyResorts';
  blockFunc = blockFunc || '';
  postLoad = postLoad || '';
 
  if (wpo && wpo>0) {gc= gc + '&wpo='+wpo;}
  
  gc = gc + '&cval='+cVal+'&sval='+sVal+'&cival='+ciVal;
 
 // alert(gc);
 
  fillSelect(id, JDLoader, gc, 'OnlyResortsArr', blockFunc, postLoad, '', '-- Select Country first --');
 }

}




 function insEl(selID, selErrMsg, pMsg, insCmd, insFld, insFlds, callBack) {

  selID = selID || '';
  selErrMsg = selErrMsg || '';
  pMsg = pMsg || '';
  insCmd = insCmd || '';
  insFld = insFld || '';
  insFlds = insFlds || '';
  callBack = callBack || '';

  if (selID!='' && selErrMsg!='' && pMsg!='' && insCmd!='' && insFlds!='' && insFlds!='') {
   if (getValue(selID)=="-1") {
    alert(selErrMsg);
   } else {
    vl = prompt(pMsg+" \""+getLabel(selID)+"\":\n(Attention! You will be unable to undo this operation.)","");
    if (vl!==null && vl!=="" && confirm("Sure to add "+insFld+" \""+vl+"\" within \""+getLabel(selID)+"\"?")) {
     var flds = {};
     eval("var flds = "+insFlds);
     flds[insFld] = vl;
     flds["var"] = "tmpVar";
     insertElement(JDLoader, insCmd, flds, callBack);
    }
   }
  } else {
   return false;
  }
 }















//---------------------------------------------------------------------------



var htmlBody = '';
var Timer = null;
var Cache = [];
var AcceptMessage=true;
var userKey = "012345678901234567890123456789";
var globalSelectAjaxedClass = 'ajaxed_default';

var selectCoverOpen = '&nbsp;<small>';
var selectCoverClose = '</small>';
var h2DCoverOpen = "<small>";
var h2DCoverClose = "</small>";

var uniFName = "";
var uniFVal = "";

var ajaxLIMG = "";

function setAjaxLIMG(imga) {
 ajaxLIMG = "<img src='"+imga+"'>&nbsp;"; 
}

function setSelectCover(st,ed) {
 selectCoverOpen=st;
 selectCoverClose=ed;
}


function setHTML2DIVCover(st,ed) {
 h2DCoverOpen=st;
 h2DCoverClose=ed;
}


function setUniFltr(name, uvl) {
 uniFName = name;
 uniFVal = uvl;
}

   function eID(id) { return document.getElementById(id); }

   function getGSAC() {

    if (globalSelectAjaxedClass != null) {
     gSAClass = globalSelectAjaxedClass;
    } else {
     gSAClass = "ajaxed_default";
    }

    return gSAClass;

   }



   function TimeRandFunction() {
    var now;
    now=new Date();
    strng=now.getTime()+"_"+(Math.random()*999999);
    return strng;
   }



   function Milliseconds() {
    var now;
    now=new Date();
    return now.getTime();
   }



   function runJS(divID) {

      var scripts = eID(divID).getElementsByTagName("script");

      for(i=0; i<scripts.length; i++) {
       var curScript = scripts[i]; 
       if ( !curScript.executed ) {
        curScript.executed = true;
        var sc = curScript.innerHTML;
        if ( sc ) {
         var a = eval(sc);
        }
       }
      }

   }


   function LoadHTML2Div(divID, url) {

    htmlBody = h2DCoverOpen+"Error loading requested page..."+h2DCoverClose;

    var call2 = domain+'/controller.php?call=loadhtmlfromurl'+
                      '&url='+encodeURIComponent(url.replace(/\//g,"#"))+
                      '&timer='+TimeRandFunction();

    jQuery.getScript(call2, 
     function(){
      if (htmlBody == "") {
       LoadHTML2Div(divID, url);
      } else {
       eID(divID).innerHTML = htmlBody;
      }
     }
    );

   }




   function LoadQuery2Div(divID,query){

    htmlBody = selectCoverOpen+"Error loading requested page..."+selectCoverClose;

    var call2 = domain+'/controller.php?call=loadhtmlfromquery'+
                      '&query='+encodeURIComponent(query.replace(/\//g,"#"))+
                      '&timer='+TimeRandFunction();

    jQuery.getScript(call2, 
     function(){
      eID(divID).innerHTML = htmlBody;
      runJS(divID);
     }
    );

   }

