// JavaScript Document

//ajax 获得远程数据
function ajax_post(fun,arr){
	var data = '';
	if(is_array(arr)){
		for(v in arr){
			data += "&d[]="+arr[v];
		}
	}else{
		data = "&d="+arr;
	}
  
	var html = $.ajax({
		type: "POST",
		url: "./ajax.php",
		data: "f="+fun+data,
		async: false
	}).responseText; 
	return html;
}

function is_array (mixed_var) {
    var key = '';
    var getFuncName = function (fn) {
        var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn);
        if (!name) {
            return '(Anonymous)';
        }
        return name[1];
    };
 
    if (!mixed_var) {
        return false;
    }
 
    // BEGIN REDUNDANT
    this.php_js = this.php_js || {};
    this.php_js.ini = this.php_js.ini || {};
    // END REDUNDANT
 
    if (typeof mixed_var === 'object') {
 
        if (this.php_js.ini['phpjs.objectsAsArrays'] &&  // Strict checking for being a JavaScript array (only check this way if call ini_set('phpjs.objectsAsArrays', 0) to disallow objects as arrays)
            (
            (this.php_js.ini['phpjs.objectsAsArrays'].local_value.toLowerCase &&
                    this.php_js.ini['phpjs.objectsAsArrays'].local_value.toLowerCase() === 'off') ||
                parseInt(this.php_js.ini['phpjs.objectsAsArrays'].local_value, 10) === 0)
            ) {
            return mixed_var.hasOwnProperty('length') && // Not non-enumerable because of being on parent class
                            !mixed_var.propertyIsEnumerable('length') && // Since is own property, if not enumerable, it must be a built-in function
                                getFuncName(mixed_var.constructor) !== 'String'; // exclude String()
        }
 
        if (mixed_var.hasOwnProperty) {
            for (key in mixed_var) {
                // Checks whether the object has the specified property
                // if not, we figure it's not an object in the sense of a php-associative-array.
                if (false === mixed_var.hasOwnProperty(key)) {
                    return false;
                }
            }
        }
 
        // Read discussion at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_is_array/
        return true;
    }
 
    return false;
}
function collect(albumid){
	s = ajax_post('collect', albumid);
	if(s == 1){
		alert('成功收藏该专辑!');
	}else if(s == 2){
		alert('该专辑不存在!');
	}else if(s == 3){
		alert('该专辑你已经收藏过.');
	}
}
function collect_post(postid){
	s = ajax_post('collect_post', postid);
	if(s == 1){
		alert('成功收藏该帖子!');
	}else if(s == 2){
		alert('该帖子不存在!');
	}else if(s == 3){
		alert('该帖子你已经收藏过.');
	}
}
function set_album_cover(albumid,picid){

	$('#albumcover').attr('src',ajax_post('set_album_coverpic',  [albumid, picid]));
}
function set_article_cover(albumid,picid){

	$('#albumcover').attr('src',ajax_post('set_article_cover',  [albumid, picid]));
}
function set_post_cover(albumid,picid){
	ajax_post('set_post_cover',  [albumid, picid]);
}
function delete_pm(pmid, type){
	if(confirm('确定删除?')){
		ajax_post('delete_pm',  [pmid, type]);
		window.location.reload();
	}	
}
function del_private_collect(id){
	if(confirm('确定删除?')){
		ajax_post('del_private_collect',  id);
		window.location.reload();
	}
}




function click_album(type, albumid){
	
 
	var num = ajax_post('click_album', {'type':type, 'albumid':albumid});
 
	if(num == '0'){
		alert('您今天已经赞美（祝福）过他/她了');
	}else{
		$('#'+type+'_span').html(num);
	}

}

function checkbox_click(obj,classname){
	$('.'+classname).attr('checked', obj.checked);
}

 
function select_selected(obj, selected_value){
	for (var i = 0; i < obj.options.length; i++) {
		if (obj.options[i].value == selected_value) { 
			obj.options[i].selected = true;
		}
	}
	 
}

function get_article_sx(id){
	//article_click
	//article_pm_num
	var html = $.ajax({
		type: "POST",
		url: "./article.php?action=get_article_sx",
		data: "id="+id,
		async: false
	}).responseText; 
	
	val = html.split('||');
	$('#article_click').html(val[0]);
	$('#article_pm_num').html(val[1]);
}