﻿// JScript 文件

var pageNum_H;
var pageNum_F;
var pageNum_S;
var productFormatId_H;
var productFormatId_F;
var productFormatId_S;
var phookProductId_H;
var phookProductId_F;
var phookProductId_S;
var allPageNum = [12,16,24,32,36,40];
var photoFolderId = 0;
var numFlag=1;

function rdPageNumClick(pageNum,suffix)
{
	  var tb=document.getElementById('tbPageNum'+suffix);
	  var imgs=tb.getElementsByTagName('img');

	  for(var i=0;i<imgs.length;i++)
	  {

		  imgs[i].src=imgs[i].src.replace('hc01','hc02');
	    
	  }
	  var obj=document.getElementById('img'+pageNum+suffix);
	  obj.src=obj.src.replace('hc02','hc01');
	  eval('pageNum' + suffix+'=pageNum');
	  getPhookProductPrice(suffix);
}
function productFormatClick(phookProductId,productFormatId,suffix,index)
{    
      var tb=document.getElementById('tbProductFormatHC'+suffix);
	  var imgs=tb.getElementsByTagName('img');
	  var currentIndex=0;
	  numFlag=1;

	  for(var i=0;i<imgs.length;i++)
	  {   
	      currentIndex++;
	      if(currentIndex==index)
	      {
	         imgs[i].src=imgs[i].src.replace('hc01','hc02');
	      }else
	      {
	        imgs[i].src=imgs[i].src.replace('hc02','hc01');
	      }  
	  }
	 eval('phookProductId' + suffix+'=phookProductId');
	 eval('productFormatId' + suffix+'=productFormatId');
	 getCanUsedPageNum(suffix,productFormatId);
	 getPhookProductPrice(suffix);
}
function getCanUsedPageNum(suffix,productFormatId)
{  

  var tb=document.getElementById('tbPageNum'+suffix);
  var inputs=tb.getElementsByTagName('input');
  for(var i=0;i<inputs.length;i++)
  {
      inputs[i].style.display='none';   
  }
  var imgs=tb.getElementsByTagName('img');
  for(var i=0;i<imgs.length;i++)
  {
      imgs[i].style.display='none';     
  }

  var objRadio;
  var objImg;
  for(var i=0; i<priceList.length; i++)
	{
		if(priceList[i].productFormatId == productFormatId)
		{
			objRadio=document.getElementById('rdPageNum' + priceList[i].pageNum + suffix);
		
			
			check(suffix); //add 2009-4-28
			if(objRadio)
			{
				var price=priceList[i].price;
				objRadio.style.display = (priceList[i].price == 0)?'none':'block';
//				if((productFormatId ==123 || productFormatId ==124) && priceList[i].pageNum ==12)
//				{
//				  	objRadio.style.display = 'none';
//				}

				if(priceList[i].price!=0)//设有效页数单元格的宽度 add 2009-4-28
				{
					tdPage=document.getElementById('td_'+priceList[i].pageNum+suffix);
					var str=priceList[i].pageNum;
					if(tdPage)
					{
						tdPage.style.width="90px";
					}
				}

			}
			objImg=document.getElementById('img' + priceList[i].pageNum +suffix);
			if(objImg)
			{
				objImg.style.display = (priceList[i].price == 0)?'none':'block';
//				if((productFormatId ==123 || productFormatId ==124) && priceList[i].pageNum ==12)
//				{
//				  	objImg.style.display = 'none';
//				}
			}
		}	
	}
	for(var i=0;i<inputs.length;i++)
	{
		  if(inputs[i].currentStyle.display=='none' && inputs[i].checked)
		  {
				selectMinPageNum(suffix);
		  }
	}
}
//重置单元格的宽度
function check(suffix)
{
	
	if(suffix=="_F" && numFlag==1)
	{
		
		document.getElementById('td_12_F').style.width="0px";
		document.getElementById('td_16_F').style.width="0px";
		document.getElementById('td_24_F').style.width="0px";
		document.getElementById('td_32_F').style.width="0px";
		document.getElementById('td_36_F').style.width="0px";
		document.getElementById('td_40_F').style.width="0px";
		numFlag++;
	}
}
function selectMinPageNum(suffix)
{
	var isSet = false;
	for(var i=0; i<allPageNum.length; i++)
	{
		var rd = document.getElementById('rdPageNum' + allPageNum[i] + suffix);
		var img = document.getElementById('img' + allPageNum[i] + suffix);
		rd.checked = false;
		img.src=img.src.replace('hc01','hc02');
		if(!isSet && rd.style.display == 'block')
		{
			rd.checked = true;
			img.src=img.src.replace('hc02','hc01');
			isSet = true;
			eval('pageNum' + suffix + '=' + allPageNum[i]);
		}
	}
	getPhookProductPrice(suffix);
}

function getPhookProductPrice(suffix)
{   
   var currentFormatId;
   var currentPageNum;
   var currentDivPhookProductPrice;
   eval('currentFormatId=productFormatId' + suffix);
   eval('currentPageNum=pageNum' + suffix);
   currentDivPhookProductPrice=document.getElementById('divPhookProductPrice' + suffix);
   // 获取产品价格
	for(var i=0; i<priceList.length; i++)
	{
		if(priceList[i].productFormatId == currentFormatId && priceList[i].pageNum == currentPageNum)
		{
//			
//			currentDivPhookProductPrice.innerHTML='￥'+ formatMoney(priceList[i].price);
//			break;
			if(priceList[i].originalPrice-priceList[i].price<=0)
			{
				currentDivPhookProductPrice.innerHTML='￥'+ formatMoney(priceList[i].price);
			}
			else 
			{    
				var divObj = document.createElement('div');
				currentDivPhookProductPrice.innerHTML  = '';
				divObj.innerHTML = '<font style="font-size:8px">￥</font>';
				divObj.innerHTML += '<font style="font-family:Georgia; font-size:12px; color:#d20200;">'+formatMoney(priceList[i].price)+'</font>';
				divObj.innerHTML += '<font style="color:Gray;margin-left:8px;font-size:8px">￥</font>';
				divObj.innerHTML += '<font style="font-family:Georgia; font-size:12px; color:Gray;text-decoration:line-through;">'+formatMoney(priceList[i].originalPrice)+'</font>';
				currentDivPhookProductPrice.appendChild(divObj);
			}
			break;
		}
	}
}
// 开始定制按钮
function btnBeginDoPhookProduct(suffix)
{   

	var divPhookProductPrice = document.getElementById('divPhookProductPrice'+suffix);
	var str =divPhookProductPrice.innerText.split('￥');
//	if(isNaN(divPhookProductPrice.innerHTML.replace(/￥/g,'')))
//	{
//		alert('获取价格失败！');
//		return;
//	}
    if(str[1]=="")
    {
		alert('获取价格失败！');
		return;
    }
	if(currentPhookProduct == 0)
	{
		alert('未选择正确的主题产品');
		return;
	}
//	currentPrice = parseFloat(divPhookProductPrice.innerHTML.replace(/￥/g,''));
	currentPrice = parseFloat(str[1]);
	MessageBox_Close();
	eval('currentPageNum = pageNum' + suffix);
	eval('currentPhookProduct='+'phookProductId'+suffix);

	var url='/PhookProduct/HC/HcDetail.aspx?';
	url+='pageNum='+currentPageNum;
	url+='&price='+currentPrice;
	url+='&phookProductId='+currentPhookProduct;
	
//	if(window.location.href.toLowerCase().indexOf('hc_zzsj.aspx')<0)//自主设计 update 2009-12-05 
//	{
//		url+='&themeName='+phookProductThemeName;
//		url+='&tagName='+phookProductTagName; 
//	}
	
	urlEncode(url);
}
// 格式化金额[保留两位小数]
function formatMoney(money)
{
    var j = Math.round(money*100);
    j = j/100;
	var index = j.toString().indexOf('.');
	if (index == -1)
	{
	    return j = j+ '.00';
	}
	else if (index == (j.toString().length - 2))
	{
	    return j = j + '0';
	}
	else
    {
        return j;
    }
    return j;
}


var imgObjColor = new Image();
var imgObjGray = new Image();
var imgOk = new Image();
var imgBtn = new Image();
imgObjColor.src = '/Images/PhookProduct/phook_product_bg_3.jpg';
imgObjGray.src = '/Images/PhookProduct/Phook_product_bg_010602.jpg';
imgOk.src = '/images/PhookProduct/phook_product_bg4.gif';
imgBtn.src = '/Images/PhookProduct/phook_product_btn0107.jpg';


//行 鼠标移过事件
function trMouseOver(o){
	var parentObj = o.parentNode.parentNode;
	var trList = parentObj.getElementsByTagName('tr');
	var flag = false;
	
	for(var i = 0 ; i < trList.length; i++){
		if (!trList[i].id) continue;
		if (i == 0) continue;
		//不是选中状态
		if (trList[i].id != o.id && trList[i].id){
			if (trList[i].className != 'trClick'){
				if ( !flag ){
					trList[i].className = 'trCommonTop';
				}
				if ( flag ){
					trList[i].className = 'trCommonButton';
				}
				var imgList = trList[i].getElementsByTagName('img');
				for(var j = 0; j < imgList.length; j++){
					imgList[j].src = imgObjGray.src;
				}
			}
		}
		else{
			if (trList[i].id){
				flag = true;
				//修正两条边线问题
				if (trList[i-1] && trList[i-1].className == 'trClick'){
					o.className = 'trCurrentBottom';	
				}
				else if (trList[i+1] && trList[i+1].className == 'trClick'){
					o.className = 'trCurrentTop';
				}
				else {
					if (trList[i].className != 'trClick'){
						o.className = 'trCurrent';	
					}
				}
			}
		}
	}
	//修正两条边线问题
	for(var i = 0; i < trList.length; i++){
		if (i == 0) continue;
		if (trList[i].className == 'trClick'){
			//修正两条边线
			var currentTrPageCount = o.id.split('_')[1];
			var selectTrPageCount = trList[i].id.split('_')[1];
			if (currentTrPageCount > selectTrPageCount && trList[i+1] && trList[i+1].className.indexOf('trCommon') != -1 ){
				trList[i+1].className = 'trCommonMiddle';
			}
			if ( currentTrPageCount < selectTrPageCount && trList[i-1] && trList[i-1].className.indexOf('trCommon') != -1 && i!=1){
				trList[i-1].className = 'trCommonMiddle';
			}
		}
	}
}
eval("var productFormatInfo="+'[{"productFormatId":111,"formatInfo":[{"pageCount":16,"photoCount":"31-41/张","phookProductId":673},{"pageCount":24,"photoCount":"43-54/张","phookProductId":673},{"pageCount":32,"photoCount":"67-79/张","phookProductId":673},{"pageCount":40,"photoCount":"89-99/张","phookProductId":673}]},{"productFormatId":112,"formatInfo":[{"pageCount":16,"photoCount":"29-37/张","phookProductId":674},{"pageCount":24,"photoCount":"49-56/张","phookProductId":674},{"pageCount":32,"photoCount":"75-79/张","phookProductId":674},{"pageCount":40,"photoCount":"87-104/张","phookProductId":674}]},{"productFormatId":113,"formatInfo":[{"pageCount":16,"photoCount":"24-41/张","phookProductId":675},{"pageCount":24,"photoCount":"44-51/张","phookProductId":675},{"pageCount":32,"photoCount":"66-78/张","phookProductId":675},{"pageCount":40,"photoCount":"88-101/张","phookProductId":675}]},{"productFormatId":114,"formatInfo":[{"pageCount":16,"photoCount":"32-42/张","phookProductId":676},{"pageCount":24,"photoCount":"43-50/张","phookProductId":676},{"pageCount":32,"photoCount":"64-85/张","phookProductId":676},{"pageCount":40,"photoCount":"91-102/张","phookProductId":676}]},{"productFormatId":121,"formatInfo":[{"pageCount":16,"photoCount":"32-42/张","phookProductId":678},{"pageCount":24,"photoCount":"51-57/张","phookProductId":678},{"pageCount":32,"photoCount":"61-78/张","phookProductId":678},{"pageCount":40,"photoCount":"83-90/张","phookProductId":678}]},{"productFormatId":122,"formatInfo":[{"pageCount":16,"photoCount":"25-37/张","phookProductId":679},{"pageCount":24,"photoCount":"48-60/张","phookProductId":679},{"pageCount":32,"photoCount":"67-77/张","phookProductId":679},{"pageCount":40,"photoCount":"79-93/张","phookProductId":679}]},{"productFormatId":123,"formatInfo":[{"pageCount":12,"photoCount":"15-35/张","phookProductId":680},{"pageCount":24,"photoCount":"47-60/张","phookProductId":680},{"pageCount":36,"photoCount":"80-93/张","phookProductId":680}]},{"productFormatId":124,"formatInfo":[{"pageCount":12,"photoCount":"14-28/张","phookProductId":681},{"pageCount":24,"photoCount":"41-53/张","phookProductId":681},{"pageCount":36,"photoCount":"73-94/张","phookProductId":681}]},{"productFormatId":131,"formatInfo":[{"pageCount":16,"photoCount":"18-34/张","phookProductId":682},{"pageCount":24,"photoCount":"36-50/张","phookProductId":682},{"pageCount":32,"photoCount":"62-79/张","phookProductId":682},{"pageCount":40,"photoCount":"85-93/张","phookProductId":682}]},{"productFormatId":132,"formatInfo":[{"pageCount":16,"photoCount":"23-37/张","phookProductId":683},{"pageCount":24,"photoCount":"37-51/张","phookProductId":683},{"pageCount":32,"photoCount":"67-76/张","phookProductId":683},{"pageCount":40,"photoCount":"86-93/张","phookProductId":683}]},{"productFormatId":133,"formatInfo":[{"pageCount":16,"photoCount":"19-31/张","phookProductId":684},{"pageCount":24,"photoCount":"36-53/张","phookProductId":684},{"pageCount":32,"photoCount":"68-78/张","phookProductId":684},{"pageCount":40,"photoCount":"80-97/张","phookProductId":684}]},{"productFormatId":134,"formatInfo":[{"pageCount":16,"photoCount":"27-30/张","phookProductId":685},{"pageCount":24,"photoCount":"44-52/张","phookProductId":685},{"pageCount":32,"photoCount":"63-75/张","phookProductId":685},{"pageCount":40,"photoCount":"79-93/张","phookProductId":685}]},{"productFormatId":125,"formatInfo":[{"pageCount":16,"photoCount":"20-50/张","phookProductId":3759},{"pageCount":24,"photoCount":"20-50/张","PhookProductId":3757},{"pageCount":32,"photoCount":"20-50/张","PhookProductId":3758},{"pageCount":40,"photoCount":"20-50张","phookProductId":3759}]},{"productFormatId":135,"formatInfo":[{"pageCount":16,"photoCount":"20-50/张","phookProductId":3763},{"pageCount":24,"photoCount":"20-50/张","phookProductId":3761},{"pageCount":32,"photoCount":"20-50/张","phookProductId":3762},{"pageCount":40,"photoCount":"20-50/张","phookProductId":3763}]}]')

//行 单击事件 
function trClick(o){
var parentObj = o.parentNode.parentNode;
var flag = false;
var trList = parentObj.getElementsByTagName('tr');
var trIds = o.id.split('_'); 
var obj = getProductFromatInfo(trIds[0],trIds[1]);
var spanPriceObj = document.getElementById('spanPrice_'+trIds[0]);
var spanPhotoCountObj = document.getElementById('spanPhotoCount_'+trIds[0]);
for(var i = 0 ; i < trList.length; i++){
	if (!trList[i].id) continue;
	if (trList[i].id != o.id && trList[i].id ){
		if ( !flag ){
			trList[i].className = 'trCommonTop';
		}
		if ( flag ){
			trList[i].className = 'trCommonButton';
		}
		var imgList = trList[i].getElementsByTagName('img');
		for(var j = 0; j < imgList.length; j++){
					imgList[j].src = imgObjGray.src;
		}
	}
	else{
		if (trList[i].id){
			spanPriceObj.innerHTML = trList[i].cells[4].innerHTML
			flag = true;
			var imgList = trList[i].getElementsByTagName('img');
			for(var j = 0; j < imgList.length; j++){
						imgList[j].src = imgObjColor.src;
			}
		}
	}
}
//照片数
spanPhotoCountObj.innerHTML = obj.photoCountInfo;
o.className = 'trClick';
}

//行鼠标移开事件
function trMouseout(o){
var parentObj = o.parentNode.parentNode;
var trList = parentObj.getElementsByTagName('tr');
var flag = false;
for(var i = 0 ; i < trList.length; i++){
	//不是选中状态
		if (!trList[i].id) continue;
		if (trList[i].id != o.id ){
			if (trList[i].className != 'trClick'){
				if ( !flag ){
					trList[i].className = 'trCommonTop';
				}
				if ( flag ){
					trList[i].className = 'trCommonButton';
				}
			}
		}
		else{
			if (trList[i].className.indexOf( 'trCurrent') != -1){
				trList[i].className = 'trMouseOut';
				var imgList = trList[i].getElementsByTagName('img');
				for(var j = 0; j < imgList.length; j++){
					imgList[j].src = imgObjGray.src;
				}
				//修正两条边线问题
				if (trList[i-1] && trList[i-1].className == 'trClick'){
					o.className = 'trMouseOutButtom';	
				}
				else if (trList[i+1] && trList[i+1].className == 'trClick'){
					o.className = 'trMouseOutTop';
				}
				else {
					if (trList[i].className != 'trClick'){
						o.className = 'trMouseOut';	
					}
				}
			}
			if (trList[i].id){
				flag = true;
			}
		}
}
//修正两条边线问题
for(var i = 0; i < trList.length; i++){
	if (i == 0) continue;
		if (trList[i].className == 'trClick'){
			//修正两条边线
			var currentTrPageCount = o.id.split('_')[1];
			var selectTrPageCount = trList[i].id.split('_')[1];
			if (currentTrPageCount > selectTrPageCount && trList[i+1] && trList[i+1].className.indexOf('trCommon') != -1 ){
				trList[i+1].className = 'trCommonMiddle';
			}
			if ( currentTrPageCount < selectTrPageCount && trList[i-1] && trList[i-1].className.indexOf('trCommon') != -1 && i!=1){
				trList[i-1].className = 'trCommonMiddle';
			}
		}
	}
}
function getProductFromatInfo(productFormatId, pageCount){
	var obj = new Object();
	if (productFormatInfo){
		for(var i = 0 ; i < productFormatInfo.length; i++){
			if (productFormatInfo[i].productFormatId == productFormatId){
				var productInfo = productFormatInfo[i].formatInfo
				for(var j = 0; j < productInfo.length; j++){
					if (productInfo[j].pageCount == pageCount){
						obj.productProductId = productInfo[j].phookProductId;
						obj.photoCountInfo = productInfo[j].photoCount;
					}
				}
			}
		}
	}
	return obj;
}
//立即定制点击  (链接到/PhookProduct/HC/HcDetail.aspx)
//  /PhookProduct/HC/HC_Zzsj.aspx 使用
function imgBtnClick(productFromatId){
	var productProductId = null;
	var pageCount = null;
	var price = null;
	var tableObj = document.getElementById('table_'+productFromatId);
	var spanPriceObj = document.getElementById('spanPrice_'+productFromatId);

	if(tableObj){
		var trList = tableObj.rows;
		for(var i = 0; i < trList.length; i++){
			if (trList[i].className == 'trClick'){
				pageCount = trList[i].id.split('_')[1];
			}
		}
	}

	var formatInfo = getProductFromatInfo(productFromatId, pageCount);
	price = spanPriceObj.innerHTML.replace('￥','');

	if (formatInfo){
		productProductId = formatInfo.productProductId;
		var url='/PhookProduct/HC/HcDetail2.aspx?';
		url+='pageNum='+pageCount;
		url+='&price='+price;
		url+='&phookProductId='+productProductId;
		urlEncode(url);
	}
}

function imgBtnClick2(productFromatId,pageCount,price)
{
    var formatInfo = getProductFromatInfo(productFromatId, pageCount);
    if (formatInfo){
		var productProductId = formatInfo.productProductId;
		var url='/PhookProduct/HC/HcDetail2.aspx?';
		url+='pageNum='+pageCount;
		url+='&price='+price;
		url+='&phookProductId='+productProductId;
		urlEncode(url);
	}
}

//选择页数改变样式
function checkPage(obj)
{
	var aSizeList=document.getElementById('divPageList').getElementsByTagName('a');
	for(var i=0;i<aSizeList.length;i++)
	{
		aSizeList[i].className='aPageNum';
		if(aSizeList[i].id==obj)
		{
			aSizeList[i].className='aPageNumCurrent';

		}
	}
	
	
}

var pageNum = "";
var price = "";
var oldPrice = "";
var productFormatId = "";
//获取不同页数的价格
function pageNumBtnClick(productFormatId,pageNum)
{
    pageNum = pageNum;
    productFormatId = productFormatId;
    document.getElementById("spanPageNum").innerHTML = pageNum;
    var aSizeList=document.getElementById('divPageList').getElementsByTagName('a');
	for(var i=0;i<aSizeList.length;i++)
	{
		aSizeList[i].className='aPageNum';
		if(aSizeList[i].id=="a"+pageNum)
		{
			aSizeList[i].className='aPageNumCurrent';
		}
	}
	
    ajax({type:"get_phook_productbyid_price",productFormatId:productFormatId,pageNum:pageNum},pageNumBtnClickBack);
}

//回调
function pageNumBtnClickBack(o)
{
    if(o.data)
    {
        price = o.data[0].price;
        oldPrice = o.data[0].oldPrice;
        var spanPrice = document.getElementById('spanPrice');
        var strHtml = "";
        if(o.data[0].oldPrice - o.data[0].price <= 0 )
        {
            strHtml += "<label style='font-size:14px;'>￥</label>"+price
        }
        else
        {
            strHtml +=" <a style='font-size:12px;color:#d20200; '>￥</a>"
            strHtml +="<a style='font-size:20px; color:#d20200;'>"+price+"</a>"
            strHtml +="<a style='color:Gray;margin-left:8px;font-size:8px'>￥</a>"
            strHtml +="<a style='font-family:Georgia; font-size:12px; color:Gray;text-decoration:line-through;'>"+oldPrice+"</a>";
        }
        
        spanPrice.innerHTML = strHtml;
        
       
    }
}

function makeBtnClick(pId)
{
    var pageNum = document.getElementById("spanPageNum").innerHTML;
    var url = "/PhookProduct/HC/Hc_rt.aspx?";
    url +="pId="+pId;
    url +="&pNum="+pageNum;
    url += "&pPrice="+price;
    urlEncode(url); 


}

//画册分类样式
function ProductTypeBtnClick(obj)
{
    var divTypeList=document.getElementById('divProductType').getElementsByTagName('div');
    for(var i=0; i<divTypeList.length-1; i++)
    {
        divTypeList[i].className = 'divHcBtn';
        document.getElementById(divTypeList[i].id+"_1").style.display = 'none';
        if(divTypeList[i].id == obj)
        {
            divTypeList[i].className = 'divHcRedBtn';
            document.getElementById(obj+"_1").style.display="block";
        }
    }
}

function hrefLoad()
{
	var url = window.location.href;
		    
	var index = url.indexOf("#");
	if(index != -1)
	{
	    var type = url.substring(index+1,url.length);
	    ProductTypeBtnClick(type);
	}
		    
}





