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

}

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 emoticon(text,toid) {
	text = ' ' + text + ' ' ;
	var obj=document.getElementById(toid);
	if (obj.createTextRange && obj.caretPos) {
		var caretPos = obj.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		obj.focus();
	} else {
		obj.value  += text;
		obj.focus();
	}
}


function taLimit() {
	var taObj=event.srcElement;
	if (taObj.value.length==taObj.maxLength*1) return false;
}

function taCount(visCnt) {
	var taObj=event.srcElement;
	if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
	if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}

function my_submit_form1(sellimit) {
	obj = eval("document.form1.expbox");
	ki = 0;
	selcount = 0;
	//sellimit = '<?//=$project_area_limit?>';
	if(!sellimit) sellimit = -1;
	if (obj){
		var iNumItems = obj.length;
		// create product order
		for (i = 0; i < iNumItems; i++ ){
			if( obj.options[i].selected ){
				if( selcount == sellimit ){
					alert("You may only select "+sellimit+" options");

					sel = document.form1.myExp.value.split(":");

					for(j=0; j< iNumItems; j++){
						obj.options[j].selected = false;
						for(k=0; k< sel.length; k++){
							if( sel[k] == obj.options[j].value){
								obj.options[j].selected = true;
							}
						}
					}
					return;
				}

				if (ki == 1){
					document.form1.myExp.value += ':' + obj.options[i].value;
				}else{
					document.form1.myExp.value = obj.options[i].value;
					ki = 1;
				}
				selcount = selcount + 1;
			}
		}
	}
}

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 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;
	}
}

function check_multi_select_limit(o,selimit) {
	obj=document.getElementById(o);
	ki = 0;
	selcount = 0;
	if(!selimit) return true;
	if (obj){
		var iNumItems = obj.length;
		// create product order
		for (i = 0; i < iNumItems; i++ ){
			if( obj.options[i].selected ){
				if( selcount == selimit ){
					alert("You may only select "+selimit+" options");
					obj.options[i].selected=false;
					return false;
				}
				selcount = selcount + 1;
			}
		}
	}
}


function get_sub_cats(pcat,target){

    $.get(
        'ajax.php',
        { action: "GetSubCatOptions",
           pcat:pcat
        },
        function(data){
            $('select#'+target).html(data);
            //$('select#'+target).option
        }
    );

    return false;
}

function get_auction_sub_cats(pcat,target){

    $.get(
        'ajax.php',
        { action: "GetAuctionSubCatOptions",
           pcat:pcat
        },
        function(data){
            $('select#'+target).html(data);
            //$('select#'+target).option
        }
    );

    return false;
}

/* ajax */
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);
    $.getJSON(
        'ajax.php',
        { action: "LoadAdContent",
           id:adid
        },
        function(data){
            //data=data.replace(/^\s+|\s+$/g,'');
            if(data){
                $('div#'+adid).html(data.img).show();
                $("div#"+adid).bind("click", function(e){
                    click_ad(data.bnid);
                    // add click event
                    //$("div#"+adid).text("Click "+data+" happened! ");
                });
            }
        }
    );
}

function click_ad(adid){

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

}

function getAdPlanDetail(bnid){
    var bpid=$('select#planlist'+bnid).val();
    $.get(
        'ajax.php',
        { action: "GetAdPlanDetail",
           bpid:bpid
        },
        function(data){
            $('div#plandetail'+bnid).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);
            if(result=='1'){
                $('div#addplanresult'+bnid).html('new plan added');
                $('span#showclickcount'+bnid).html(str);
            }else if(str){
                $('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 get_job_search_states(country,target){

    $.get(
        'ajax.php',
        { action: "GetJobSearchStates",
          country:country
        },
        function(data){
            $('select#'+target).html(data);
            //$('select#'+target).option
        }
    );

    return false;
}

function get_auction_search_states(country,target){

    $.get(
        'ajax.php',
        { action: "GetAuctionSearchStates",
          country:country
        },
        function(data){
            $('select#'+target).html(data);
            //$('select#'+target).option
        }
    );

    return false;
}

function get_states(country,target){

    $.get(
        'ajax.php',
        { action: "GetStates",
          country:country
        },
        function(data){
            $('select#'+target).html(data);
            //$('select#'+target).option
        }
    );

    return false;
}

function load_content(id){
    $.get(
        'ajax.php',
        { action: "LoadContent",
           id:id
        },
        function(data){
            $('div#'+id).html(data);
        }
    );
}

function load_all_content(){
    $('div.autoload_content').each(
        function(){ load_content(this.id); }
    );
}


function countdownclock(end, target){

    var endtime=Date.parse(end)
    var now=new Date();
    var intervaltime=parseInt((endtime-now.getTime())/1000);
    if(intervaltime<=0) return;

    var seconds=intervaltime%60;
    if(seconds<10) seconds='0'+seconds;

    var tmp=parseInt(intervaltime/60);       //minutes
    var minutes=tmp%60;
    if(minutes<10) minutes='0'+minutes;

    tmp=parseInt(tmp/60);       //hours
    var hours=tmp%24;
    if(hours<10) hours='0'+hours;

    days=parseInt(tmp/24);   //days

    if(days){
        $('#'+target+' span.days span').html(days);
        $('#'+target+' span.days').show();
    }else{
        $('#'+target+' span.days').hide();
    }
    if(hours){
        $('#'+target+' span.hours span').html(hours);
        $('#'+target+' span.hours').show();
    }else{
        $('#'+target+' span.hours').hide();
    }
    if(minutes){
        $('#'+target+' span.minutes span').html(minutes);
        $('#'+target+' span.minutes').show();
    }else{
        $('#'+target+' span.minutes').hide();
    }
    if(seconds){
        $('#'+target+' span.seconds span').html(seconds);
        $('#'+target+' span.seconds').show();
    }else{
        $('#'+target+' span.seconds').hide();
    }

    setTimeout("countdownclock('"+end+"','"+target+"')",1000);
}



function countdownclockforcreate(target){      // tempendtime is global variable in page

    var endtime=Date.parse(tempendtime)
    var now=new Date();
    var intervaltime=parseInt((endtime-now.getTime())/1000);

    if(intervaltime>0) {

        var seconds=intervaltime%60;
        if(seconds<10) seconds='0'+seconds;

        var tmp=parseInt(intervaltime/60);       //minutes
        var minutes=tmp%60;
        if(minutes<10) minutes='0'+minutes;

        tmp=parseInt(tmp/60);       //hours
        var hours=tmp%24;
        if(hours<10) hours='0'+hours;

        days=parseInt(tmp/24);   //days

        $('#'+target).show();

        if(days){
            $('#'+target+' span.days span').html(days);
            $('#'+target+' span.days').show();
        }else{
            $('#'+target+' span.days').hide();
        }
        if(hours){
            $('#'+target+' span.hours span').html(hours);
            $('#'+target+' span.hours').show();
        }else{
            $('#'+target+' span.hours').hide();
        }
        if(minutes){
            $('#'+target+' span.minutes span').html(minutes);
            $('#'+target+' span.minutes').show();
        }else{
            $('#'+target+' span.minutes').hide();
        }
        if(seconds){
            $('#'+target+' span.seconds span').html(seconds);
            $('#'+target+' span.seconds').show();
        }else{
            $('#'+target+' span.seconds').hide();
        }

    }else{
        $('#'+target).hide();
    }

    setTimeout("countdownclockforcreate('"+target+"')",1000);
}


function ajax_update_progress(v,pid){
    $.get(
        'ajax.php',
        { action: "UpdateProgress",
           pid:pid,
           v:v
        },
        function(data){
            //$(this).val(data);
            //alert(data);
            $('#update_progress_time_'+pid).html(data);
        }
    );

}
