// JavaScript Document
//登录与注册的切换
/**
showObj 显示对象
hideObj 隐藏的对象
isShow 是否显示
*/
function switchLoginRegPanel(showObj,hideObj,isShow){
	if(isShow){
		showObj.show();
		hideObj.hide();
	}else{
		showObj.hide();
		hideObj.show();
	}
	
}

//销售团队展开与收缩
function openSale(showObj,hideObj){
		showObj.hide();
		hideObj.slideDown('slow');

}
function closeSale(showObj,hideObj){
		hideObj.slideUp('slow',function(){
			showObj.show();
			});

}

//文档加载完毕要执行的
$(document).ready(function(){
	//注意99999999999999最后页面全部做完的时候，分别在每个页面里面放置对应的启动函数，不需要每个页面都启动
   //setCNTVINDEWidth();
   CNMediaPOP();
   //取消IE下面的链接虚线框
   $("a").attr("hideFocus","true");
});

//收视中国封面页面宽度设置
function setCNTVINDEWidth(){
	//680为左栏的宽度
	$(".tvvnRight").css({"width":680-$(".tvvnLeft").width()});
}


//传媒系列报告的菜单
function CNMediaPOP(){
	$('.CNMediaItem').hover(function(e) {
		//  jQuery获得页面元素的绝对/相对位置 收藏
/*获取页面某一元素的绝对X,Y坐标，可以用offset()方法：

view plaincopy to clipboardprint?
var X = $('#DivID').offset().top;  
var Y = $('#DivID').offset().left;  

获取相对(父元素)位置:父级要设置position

view plaincopy to clipboardprint?
var X = $('#DivID').position().top;  
var Y = $('#DivID').position().left;  

view plaincopy to clipboardprint?
var pleft = $("selector").scrollLeft();//元素相对于滚动条左边的偏移量  
var pTop = $("selector").scrollTop();//元素相对于滚动条顶部的偏移量 */ 
        //alert($(document).width());		
		//alert($(e.target).position().left);
		var id = $(this).attr('id');
		$.ajax({
			url:'/index.php/Home/Ajax/getReport/id/'+id,
			type:'POST',
			success:function(html){
				$("#CNMediaReportPOP").html(html);
			}			
			
		});
		if((($(document).width()-940)/2+525)<$(this).position().left){
			//alert("right");
			$("#CNMediaReportPOP").removeClass("CNMediaReportPOP_left");
			$("#CNMediaReportPOP").addClass("CNMediaReportPOP_right");
			$("#CNMediaReportPOP").css({"left":$(this).position().left-408,"top":$(this).position().top});
		}else{
			//alert("left");
			$("#CNMediaReportPOP").addClass("CNMediaReportPOP_left");
			$("#CNMediaReportPOP").removeClass("CNMediaReportPOP_right");
			$("#CNMediaReportPOP").css({"left":$(this).position().left+150,"top":$(this).position().top});
		}
		
		$("#CNMediaReportPOP").show();
		
		$("#CNMediaReportPOP").hover(function(){
			
				if(t!=null){
				  clearTimeout(t);
				}
			
			},function(){
				$("#CNMediaReportPOP").hide();
			
			});
		if(t!=null){
		 clearTimeout(t);
		}
    },
	
	function(e) {
		t = setTimeout("popHide()",400);
		
    }
	);
}



function popHide(){
	$("#CNMediaReportPOP").hide();
}

//Tab 切换
/**
showObj 显示对象
hideObj 隐藏的对象
isShow 是否显示
*/
function switchTabContent(showObj,hideObj,thisObj){
	    thisObj.siblings("li").removeClass("currentTab");
		thisObj.addClass("currentTab");
		hideObj.hide();
		showObj.show();		
}
function switchJobContent(showObj,hideObj){
	    //thisObj.siblings("li").removeClass("currentTab");
		//thisObj.addClass("currentTab");
		hideObj.hide();
		showObj.show();		
}

function gotoPage(pageUrl){
	window.location.href=pageUrl; 
}

//6.25--------------------------
//清空输入表单
function removeValue(inputObj,value){
	if(inputObj.attr("value")==value){
		inputObj.attr("value","");
	}
}
//如果输入不为空，重新返回原来的状态
function resetValue(inputObj,value){
	if(inputObj.attr("value")==value||inputObj.attr("value")==""){
		inputObj.attr("value",value);
	}
}

//鼠标切换样式
function switchMouseCss(obj,addClassName,removeClassName){
	obj.removeClass(removeClassName);
	obj.addClass(addClassName);
}

function switchMouseShowHide(showObj,hideObj){
	showObj.show();
	hideObj.hide();
}


//6.25---------------------------

//6.23
function switchClientContent(showObj,hideObj,obj,clickObj){
	    obj.removeClass("currentTab");
		clickObj.addClass("currentTab");
		hideObj.hide();
		showObj.show();		
}
//6.23

//6.21
function switchCustomerContent(showObj,cssName,clickObj){
		$("#customerTab li").removeClass("currentTab");
		$("#customerTab li").removeClass("midCurrentTab");
		clickObj.addClass(cssName);
		$(".customPadding").hide();
		showObj.show();		
}
//6.21

//7.13开始
//增加与减少数量
//总本数
var totalNum=0;
//总价
var totalPrice=0;
function addAndReduce(obj,isAdd,flag){
	
	var num=obj.attr("value");
	var flag = "#reportid_"+flag;
	var reportid = $(flag).attr('value');
	if(isAdd){
		num++;
		$.ajax({url:'/index.php/Home/Ajax/addOrder/id/'+reportid});
	}else{
		if(num<=1){
			return false;
		}
		$.ajax({url:'/index.php/Home/Ajax/subReportOrder/id/'+reportid});
		num--;
	}
	
	obj.attr("value",num);
	
	sumOneListPrice(obj.attr("id").substr(4));
	
	sumTotalNum();
	sumTotalPrice();
	
}

//计算总数
function sumTotalNum(){
	//查找这个表格里面所有的输入框的值，相加
	totalNum=0;
	$("#buyListTable input:text").each(function(i){
		totalNum+=parseInt($(this).val());
 });
 //alert(totalNum);
 $("#totalNumArea").text(totalNum);
}

//计算总价
function sumTotalPrice(){
	//查找这个表格里面所有的输入框的值，相加
	totalPrice=0;
	$("#buyListTable .totalPriceShow").each(function(i){
		var t=Number(parseFloat($(this).text()).toFixed(2));
		totalPrice+=t;
 });
 //alert(totalPrice);
 $("#totalPricesArea").text(parseInt(totalPrice).toFixed(2));
}

//计算每条的单价和总价
function sumOneListPrice(currentID){
	//读取单价，然后相乘，这个需要在生成的时候声明不同的条ID
	var idString="#num_"+String(currentID);
	var obj=$(idString);
	var objPriceShow=$("#dangjiaShow_"+currentID);
	var objShuliangShow=$("#shuliangShow_"+currentID);
	var objTotalPriceShow=$("#totalPriceShow_"+currentID);
	var t=parseInt(obj.val());
	var s=Number(parseFloat(objPriceShow.text()).toFixed(2));
	objShuliangShow.text(t);
	objTotalPriceShow.text(parseFloat(t*s).toFixed(2));

}

//一打开页面的时候执行所有的单条计算
function initSumOneList(){
	$("#buyListTable .totalPriceShow").each(function(i){
		sumOneListPrice(parseInt(i+1));
 	});
	
	sumTotalNum();
	sumTotalPrice();
}

//7.13结束

//7.14开始

function buyNow(id)
{
	$.ajax({
		url:'/index.php/Home/Ajax/addOrder/id/'+id,
		dataType:'json',
		success:function(data){
			if(data.status == 1)
			{
				location.href='/index.php/Home/Research/reportOrder';
			}
			else
			{
				//
			}
		}
	});
}

function openVideoPop(_videoTitle,_videoURL,_coverImage){
				$.colorbox({
				href:"/Public/csmFlvPlayer/flash.html",
				innerWidth:513,
				innerHeight:444,
				scrolling:false,
				overlayClose:false,
				close:"",
				onComplete:function(){
					setValue(_videoTitle,_videoURL,_coverImage);
					}
			});
			}

function closePopLayer(){
	$.colorbox.close();
}


//7.28TAB感应效果
function tabMJOver(obj){

		obj.addClass('currentMJOverTab');

}
function tabMJOut(obj){

		obj.removeClass('currentMJOverTab');

}

//8.4报告模块加入订购列表

function clickOrder(id)
{
	var url = '/index.php/Home/Research/addOrder/id/'+id;
	$.ajax({
		
		type:'get',
		dataType:'json',
		url:url,
		success:addOrderSuccess
	});
}
function addOrderSuccess(data)
{
	if(data.status == 1)
	{
		alert(data.info);
		location.reload();
	}
	else
	{
		alert(data.info);
		location.reload();
	}
}	
