function isArray(obj) {
	return obj.constructor == Array;
}

function showLoading(div) {
  if(div && $('#'+div)) {
    $('#'+div).html("<img src='_media/loading.gif' border='0'> Loading ...");
  }
}

function showLoadingById(id) {
	if(id && $('#'+id)) {
		$('#'+id).html("<img src='"+loading_img+"' border='0'> Loading ...");
	}
}
function showLoadingByObj(obj) {
	if(obj) {
		obj.html("<img src='"+loading_img+"' border='0'> Loading ...");
	}
}

function dosubmit(url,data) {
	if(!url) {
		return;
	}
	// do search here
	$.ajax({
		type: "POST",
		url: url,
		data: data,
		dataType: "script"
	})
}

function download(url,data,target,parent) {
	if(!url) {
		return;
	}
	// do search here
	$.ajax({
		type: "POST",
		url: url,
		data: data,
		dataType: "html",
		success: function(msg){
			if(target && $('#'+target)) {
				if(parent) {
					$('#'+target).parent().html(msg);
				} else {
					$('#'+target).html(msg);
				}
			}
		}
	})
}

function toggleClass(divid, id) {
	if(divid && id) {
		divid.removeClass('on');
		id.addClass('on');
	}
}

function toggleDisplay(divid, id) {
	if(divid && id) {
		divid.addClass('hide');
		id.removeClass('hide');
	}
}

function popup(url,data) {
	if(!url) {
		return;
	}
	var target = "popup"+Math.round(Math.random()*1000);
	$('#popuplist').append("<div class='popup'><div class='popup_bg' onclick='javascript:$(this).parent().remove();'>&nbsp;</div><div class='popup_content'><div class='popup_close'><a class='link' onclick=\"javascript:$(this).parent().parent().parent().remove();\"><img src='_media/close2.gif' alt='Close' title='Close'></a></div><div id='"+target+"' class='popup_data'></div><div class='clear'></div></div>");
	if($.browser.msie) {
		$('div.popup_bg').css('filter', 'alpha(opacity=50)')
		if( $.browser.version < 7 ) {
			$('div.popup_bg').css('position','absolute');
			$('div.popup_bg').css('height',$(document).height());
			$('div.popup_content').css('position','absolute');
		}
	}
	showLoading(target);
	download(url,data,target);
}
function newpopup(url,data,title,id,w,h) {
	if(!url) {
		return;
	}
	var target = "popup"+Math.round(Math.random()*1000);
	if(id) {
		target = "popup"+id;
		if(document.getElementById(target)) {
			$('#'+target).dialog("open");
			return false;
		}
	}
	var style = "";
	w = !w ? 150 : w ;
	h = !h ? 150 : h ;
	style = style+'width:'+w+'px;';
	style = style+'height:'+h+'px;';
	$('#popuplist').append("<div id='"+target+"' class='newpopup' style=\""+style+"\"></div>");
	$('#'+target).dialog({title:title,height:h,width:w,minHeight:h,minWidth:w});
	showLoading(target);
	download(url,data,target);
}
function closeNewPopup() {
	$(this).parent().parent().parent().remove();
}
function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	if(!expiredays) {
		expiredays = 365;
	}
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name) {
	if (document.cookie.length>0) {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1) { 
	    c_start=c_start + c_name.length+1; 
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	  }
	}
	return "";
}
