
/*
//
//+-----------------------------------------------------------------+
//|                 RadCLASSIFIEDS GOLD v2 ADMIN                    |
//|                        (February 2008)                          |
//|                Copyright © 2008 RadScripts.com                  |
//|                                                                 |
//| File Name:       script.js                                      |
//| Project Manager:  Ed Pakstas                                    |
//| Email:            support@radscripts.com                        |
//| Website:          http://www.RadScripts.com                     |
//|                                                                 |
//| Note: Any alteration of PHP code in this file will void any     |
//|	     support services which RadScripts.com may provide.     |
//| Note: This script is NOT Freeware and IS NOT Open Source Code!  |
//|       All terms, conditions and copyrights as defined in the    |
//|	RadScripts License Agreement WHICH YOU AGREED TO COMPLY WITH|
//|	when you purchased this software must be adhered to and will|
//|	be strictly enforced.                                       |
//+-----------------------------------------------------------------+
//
*/

function gotocluster(s){
	var d = s.options[s.selectedIndex].value
	if(d){
		top.location.href = d
	}
	s.selectedIndex=0
}

function my_submit_form() {
	obj = eval("document.form1.expbox");
	ki = 0;
	if (obj){
		var iNumItems = obj.length;
		// create product order
		for (i = 0; i < iNumItems; i++ ){
			if( obj.options[i].selected ){
				if (ki == 1){
					document.form1.myExp.value += ':' + obj.options[i].value;
				}else{
					document.form1.myExp.value = obj.options[i].value;
					ki = 1;
				}
			}
		}
	}
}



function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function populate(selected,mychoice) {
	document.form1.elements['state'].selectedIndex = 0;
	var nochoice = 1;
	if ( eval(selected+"_array") ){
		var selectedArray = eval(selected+"_array");
		while (selectedArray.length < document.form1.elements['state'].options.length) {
			document.form1.elements['state'].options[(document.form1.elements['state'].options.length - 1)] = null;
		}
		eval("document.form1.elements['state'].options[0]=" + "new Option('--')");
		document.form1.elements['state'].options[0].value="0";
		for (var i=1; i < selectedArray.length; i++) {
			var id = selectedArray[i].substring(0,selectedArray[i].indexOf(":"));
			var val = selectedArray[i].substring(selectedArray[i].indexOf(":")+1, selectedArray[i].length);
			document.form1.elements['state'].options[i]=new Option(val);
			document.form1.elements['state'].options[i].value=id;
			if (id == mychoice){
				document.form1.elements['state'].selectedIndex = i;
				nochoice = 0;
			}
		}
	}else{
		document.form1.elements['state'].options[(document.form1.elements['state'].options.length - 1)] = null;
		eval("document.form1.elements['state'].options[0]=" + "new Option('--')");
		document.form1.elements['state'].options[0].value="0";
	}
	if (nochoice){
		document.form1.elements['state'].selectedIndex = 0;
	}
}



var map;
var directionsPanel;
var directions;

function initialize(address, dispmapinfowin) {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));

        var geocoder = new GClientGeocoder();

        geocoder.getLatLng(
            address,
            function(point) {
                if (!point) {
                    alert(address + " not found");
                } else {
		map.setCenter(point, 15);
		map.addControl(new GMapTypeControl());
		map.addControl(new GLargeMapControl());
                      var marker = new GMarker(point);
		map.addOverlay(marker);

                     if(dispmapinfowin){
		  marker.openInfoWindowHtml("<div style=\'background:white;\'><b>Address:</b><br/> "+address+"</div>");
                    }

            	  GEvent.addListener(marker, "click", function() {
            		    marker.openInfoWindowHtml("<b>Address:</b> "+address);
            	  });

               }
            }
        );
    }
}

function showdirection(from,address) {
      if (GBrowserIsCompatible()) {

        if(!map) return false;

        if(directions) directions.clear();

        directionsPanel = document.getElementById("route");
        directionsPanel.innerHTML="";
        directions = new GDirections(map, directionsPanel);
        directions.load(from+" to "+address);

    }
}


function ajax_get_calendar(cid,listingid,time,forupdate,can_change_month){

    $.get(
        'ajax.php',
        { action: "DispMonth",
           listingid: listingid,
           time: time,
           forupdate: forupdate,
           calid: cid,
           chgmon: can_change_month
        },
        function(data){
            $('div#'+cid).html(data);
        }
    );

    return false;
}

function ajax_update_calendar(cid,listingid,starttime,endtime,status,can_change_month,display_time){

    $.get(
        'ajax.php',
        { action: "ChgDateStatus",
           listingid: listingid,
           starttime: starttime,
           endtime: endtime,
           status: status,
           calid: cid,
           chgmon:can_change_month,
           display_time: display_time
        },
        function(data){
            $('div#'+cid).html(data);
        }
    );

    return false;
}

function load_ads(){
   var ads=$('div.ad');
   for(var i=0; i<ads.length; i++){
       load_ad(ads[i].id);
   }
}


function load_ad(adid){
    //alert(adid);
    $.get(
        'ajax.php',
        { action: "LoadAdContent",
           id:adid
        },
        function(data){
            var result = data.split("|");
            var bnid=result[0];
            var content=result[1];
            $('div#'+adid).html(content);
            //$('div#'+adid).css('width','100%');
            //$('div#'+adid).css('height','100%');
            $("div#"+adid).bind("click", function(e){
                click_ad(bnid);
                // add click event
                //$("div#"+adid).text("Click "+data+" happened! ");
            });

        }
    );
}

function click_ad(bnid){

    //alert(adid);
    $.get(
        'ajax.php',
        { action: "ClickAd",
           id:bnid
        },
        function(data){
            window.open(data,"new");
            //window.location.href=data;
        }
    );

}

function getAdPlanDetail(){
    var bpid=$('select#newpriceplan').val();
    $.get(
        'ajax.php',
        { action: "GetAdPlanDetail",
           bpid:bpid
        },
        function(data){
            $('span#plandetail').html(data);
        }
    );

}

function addBannerPlan(bnid,bpid){
    //var bpid=$('span#planlist'+bnid).html();
    $.get(
        'ajax.php',
        { action: "AddBannerPlan",
           bpid:bpid,
           bnid:bnid
        },
        function(data){
            //var result=data.substr(0,1);
            //var str=data.substring(2);
            var result = data.split("|");
            if(result[0]=='1'){
                $('div#addplanresult'+bnid).html('new deposit added');
                $('span#ad_balance'+bnid).html(result[1]);
            }else if(result[1]){
                $('div#addplanresult'+bnid).html(data);
            }else{
                $('div#addplanresult'+bnid).html('process failed, please try again');
            }
            $('div#addplanresult'+bnid).fadeIn(1000);
            $('div#addplanresult'+bnid).fadeOut(6000);
        }
    );
}


function charCounter(idText,idCounter){
	var limit=$(idCounter).html();
	$(idText).bind("keyup mousedown change", function(){
	    if($(idText).val().length>limit){
	        $(idText).val($(idText).val().substring(0,limit));
	    }
	    $(idCounter).html( limit - $(idText).val().length   );
	});
	$(idText).trigger('change');
}
