﻿// JavaScript Document

//banner展示效果
var bannerHeight = 0;
$(document).ready( function() {
	var img = new Image();
	img.src = $("#probanner #show").attr("rel");
	img.onload = function () {
		bannerHeight = img.height;
		$("#probanner #show").css( { "background" : "url(" + img.src + ") no-repeat center" } ).show().stop().animate( { "height" : bannerHeight + "px" } , { queue: false, duration: 500 } );
		//$("#probanner #show").css( { "background" : "url(" + img.src + ") no-repeat center" , "height" : bannerHeight + "px" } ).show();
	};
} );

var projectbanner = true;
function showprojectbanner() {
	if ( projectbanner ) {
		if ( $("#probannertop a:first").attr("class") == "rd" ) {
			projectbanner = false;
			$("#probanner #show").stop().animate( { "height" : "0px" } , { queue: false, duration: 500, complete: function() {
				$(this).hide();
				$("#probannertop a:first").attr("class","ad");
				projectbanner = true;
			} } );
		}
		else if ( $("#probannertop a:first").attr("class") == "ad" ) {
			projectbanner = false;
			$("#probanner #show").stop().show().animate( { "height" : bannerHeight + "px" } , { queue: false, duration: 500, complete: function() {
				$("#probannertop a:first").attr("class","rd");
				projectbanner = true;
			} } );
		}
	}
}



//打分部分
$(document).ready( function() {
	//ajax读取分数信息
	function getTotalDefault() {
		$.ajax( {
			type: "post",
			url: "/ajax/total.asp",
			cache: false,
			data: "id=" + $("#pointsp").attr("rel"),
			dataType: ($.browser.msie) ? "text" : "xml",
			error: function() { alert("Error loading XML document"); },
			success: function(result) {
				if ( typeof result == "string" ) {
					var xml = new ActiveXObject("Microsoft.XMLDOM");
					xml.async = false;
					xml.loadXML(result);
				}
				else {
					var xml = result;
				}
				var total = xml.getElementsByTagName("root")[0].getElementsByTagName("total")[0] , xmldate;
				$("#pointsp").empty();
				xmldate = "<span>";
				if ( total.getAttribute("Counting") == 0 ) {
					xmldate += "0";
				}
				else {
					xmldate += ( total.getAttribute("Totals") / total.getAttribute("Counting") ).toFixed(2);
				}
				xmldate += "分</span> 共有";
				xmldate += total.getAttribute("Counting");
				xmldate += "人打分 总分";
				xmldate += total.getAttribute("Totals");
				xmldate += "分（请拖动黄色滑块打分）";
				$("#pointsp").append(xmldate);
			}
		} );
	}
	getTotalDefault();
	
	var totaling = false , startleft = 0 , maxfar = 430 , firstfar = 8 , stepfar = 42 , totalover = false;
	if ( $("#pointsarrow").attr("rel") != "" ) {
		var defaultfar = $("#pointsarrow").attr("rel") * stepfar - firstfar;
		if ( defaultfar < 0 ) { defaultfar = 0; }
		$("#pointsarrow img").css("margin-left" , defaultfar + "px");
		totalover = true;
	}
	if ( !$.browser.mozilla ) {
		//非FF
		$("#pointsarrow img").bind( "dragstart", function() { return false; } );
		
		$("#pointsarrow img").mousedown( function() {
			if ( !totalover ) {
				locate();
				startleft = cx;
				totaling = true;
			}
		} );
		$(document.body).mousemove( function() {
			if ( totaling && !totalover ) {
				locate();
				if ( ( cx - startleft ) >= 0 && ( cx - startleft ) <= maxfar ) {
					$("#pointsarrow img").css("margin-left" , ( cx - startleft ) + "px");
				}
				else if ( ( cx - startleft ) < 0 ) {
					$("#pointsarrow img").css("margin-left" , "0");
				}
				else if ( ( cx - startleft ) > maxfar ) {
					$("#pointsarrow img").css("margin-left" , maxfar + "px");
				}
			}
		} ).mouseup( function() {
			if ( totaling && !totalover ) {
				locate();
				var scolls = ( ( cx - startleft + firstfar ) / stepfar ).toFixed(0);
				if ( scolls > 10 ) { scolls = 10; } else if ( scolls < 0 ) { scolls = 0; }
				var setfar = scolls * stepfar - firstfar;
				if ( setfar < 0 ) { setfar = 0; }
				$("#pointsarrow img").css("margin-left" , ( setfar ) + "px");
				givethescoll(scolls);
			}
		} );
	}
	else {
		//FF
		$("#points").click( function() {
			if ( !totalover ) {
				locate();
				var scolls = ( ( cx - $(this).offset().left + firstfar ) / stepfar ).toFixed(0);
				if ( scolls > 10 ) { scolls = 10; } else if ( scolls < 0 ) { scolls = 0; }
				var setfar = scolls * stepfar - firstfar;
				if ( setfar < 0 ) { setfar = 0; }
				$("#pointsarrow img").css("margin-left" , ( setfar ) + "px");
				givethescoll(scolls);
			}
		} );
	}
	
	function givethescoll(num) {
		totaling = false;
		if ( $.browser.msie || $.browser.mozilla ) {
			if ( confirm("是否确定给此盘古建站打 " + num + " 分？") ) {
				totalover = true;
				sendmyscoll(num);
			}
			else {
				$("#pointsarrow img").css("margin-left" , "0");
			}
		}
		else {
			totalover = true;
			sendmyscoll(num);
		}
	}
	function sendmyscoll(num) {
		$.ajax( {
			type: "post",
			url: "/ajax/set_scolls.asp",
			cache: false,
			data: "id=" + $("#points").attr("rel") + "&scolls=" + num,
			error: function() { alert("Error"); },
			success: function(result) {
				if ( typeof result == "string" ) {
					if ( result == "add_ok" ) {
						$("#pointsarrow").attr("rel",num);
						getTotalDefault();
					}
				}
			}
		} );
	}
} );



//分辨率
$(document).ready( function() {
	var mywidth = window.screen.width;
	var myheight = window.screen.height;
	var screentxt;
	switch ( mywidth ) {
		case 800:
			screentxt = "　（适合15寸方屏）"; break;
		case 1024:
			screentxt = "　（适合17寸方屏）"; break;
		case 1280:
			if ( myheight == 1024 ) {
				screentxt = "　（适合19寸方屏）"; break;
			}
			else {
				screentxt = "　（适合17寸宽屏）"; break;
			}
		case 1440:
			screentxt = "　（适合19寸宽屏）"; break;
		case 1600:
			screentxt = "　（适合20寸宽屏）"; break;
		case 1680:
			screentxt = "　（适合22寸宽屏）"; break;
		default:
			screentxt = "　（未知尺寸）"; break;
	}
	$("#fbl p:eq(1)").html("<span style='color:green;'>您当前正在使用的分辨率：</span>" + mywidth + "px × " + myheight + "px" + screentxt);
	$("#fbl ul li a").each( function() {
		if ( $(this).attr("rel").split(",")[0] == mywidth ) {
			checkResolution(mywidth,myheight,$("#fbl").attr("rel"),$(this));
		}
	} ); 
	
	$("#fbl ul li a").click( function() {
		checkResolution($(this).attr("rel").split(",")[0],$(this).attr("rel").split(",")[1],$("#fbl").attr("rel"),$(this));
	} );
	function checkResolution(width,height,resolutions,obj) {
		$("#fbl ul li a").removeClass("oncheck");
		obj.addClass("oncheck");
		var makeheight;
		if ( width == 800 || width == 1024 || width == 1280 ) {
			makeheight = 255;
			$("#screen #main div:first").animate( { "height" : makeheight + "px" } , { queue: false, duration: 500, complete: function() {
				$("#screen #main").css( "background" , "url(../images/screen_bg.jpg) no-repeat" );
			} } );
		}
		else {
			makeheight = 225;
			$("#screen #main div:first").animate( { "height" : makeheight + "px" } , { queue: false, duration: 500, complete: function() {
				$("#screen #main").css( "background" , "url(../images/screen_bg_k.jpg) no-repeat" );
			} } );
		}
		$("#screen #main div:first img:first").animate( { "width" : ( resolutions / width * 419 ) + "px" } , { queue: false, duration: 500, complete: function() {
			if ( $(this).attr("height") <= makeheight ) {
				switch (makeheight) {
					case 255:
						$("#screen #main").css( "background" , "url(../images/screen_bg_none.jpg) no-repeat" ); break;
					case 225:
						$("#screen #main").css( "background" , "url(../images/screen_bg_k_none.jpg) no-repeat" ); break;
				}
			}
		} } );
	}
} );



//选择对比
function fastattech(id) {
	$.ajax( {
		type: "post",
		url: "/ajax/loadattech.asp",
		cache: false,
		data: "id=" + id + "&fast=ok&fastdel=" + false,
		dataType: ($.browser.msie) ? "text" : "xml",
		error: function() { alert("Error loading XML document"); },
		success: function(result) {
			if ( typeof result == "string" ) {
				var xml = new ActiveXObject("Microsoft.XMLDOM");
				xml.async = false;
				xml.loadXML(result);
			}
			else {
				var xml = result;
			}
			var attech = xml.getElementsByTagName("root")[0].getElementsByTagName("attech");
			var read = xml.getElementsByTagName("root")[0].getAttribute("read");
			var ids = "";
			if ( read == "have" ) {
				alert("您已经选择了这个盘古建站。");
			}
			else if ( read == "ok" ) {
				for ( var i = 0 ; i < attech.length ; i++ ) {
					if ( attech[i].getAttribute("see") == "true" ) {
						$(".compare a:eq(" + i + ")").attr("href","project.asp?id=" + attech[i].getAttribute("id")).attr("title",attech[i].getAttribute("W_id")).attr("class","oncheck");
						ids += attech[i].getAttribute("id") + ",";
					}
					else {
						$(".compare a:eq(" + i + ")").attr("title","暂无选择");
					}
				}
				if ( id != "" ) {
					alert("选择成功！");
				}
			}
			if ( ids != "" ) {
				if ( ids.split(",")[ids.split(",").length - 1] == "" ) {
					ids = ids.substring(0,ids.length - 1);
				}
				$("#btn a.text").attr("href","index.asp?list=attech&ids=" + ids).css("display","block");
			}
			else {
				$("#btn a.text").attr("href","index.asp").css("display","none");
			}
		}
	} );
}
$(document).ready( function() {
	fastattech("");
} );

//购物车
$(document).ready( function() {
	var shop_map = "";
	shop_map += "<div id='float_shop_box' style='width:100%;height:100%;position:absolute;z-index:100;top:0;left:0;display:none;'><div id='float_shop' style='width:645px;height:auto;margin:200px auto;border:2px #D3E3EA solid;background:#FFF url(/images/industry_bg.jpg) repeat-x;padding-bottom:10px;'>";
		shop_map += "<div style='margin:0 15px 10px 15px;text-align:right;height:35px;border-bottom:1px #000 solid;'>";
			shop_map += "<img id='checkall' src='/images/checkall.gif' style='margin:5px;cursor:pointer;' />";
			shop_map += "<img id='checkop' src='/images/checkallleave.gif' style='margin:5px;cursor:pointer;' />";
			shop_map += "<img id='checknull' src='/images/checknull.gif' style='margin:5px;cursor:pointer;' />";
			shop_map += "<img id='buy' src='/images/buy.gif' style='margin:5px;cursor:pointer;' />";
			shop_map += "<img id='close' src='/images/close.gif' style='margin:5px;cursor:pointer;' />";
		shop_map += "</div>";
		shop_map += "<ul style='margin:0;padding:0 15px;list-style-type:none;'></ul>";
	shop_map += "</div></div>";
	
	shop_map += "<div id='float_buy_box' style='width:100%;height:100%;position:absolute;z-index:100;top:0;left:0;display:none;'><div id='float_buy' style='width:350px;height:auto;margin:200px auto;border:2px #D3E3EA solid;background:#FFF url(/images/industry_bg.jpg) repeat-x;padding-bottom:10px;'>";
		shop_map += "<div style='margin:0 15px 10px 15px;text-align:right;height:35px;border-bottom:1px #000 solid;'>";
			shop_map += "<img id='buyit' src='/images/buy.gif' style='margin:5px;cursor:pointer;' />";
			shop_map += "<img id='returnshop' src='/images/returnshop.gif' style='margin:5px;cursor:pointer;' />";
			shop_map += "<img id='closebuy' src='/images/close.gif' style='margin:5px;cursor:pointer;' />";
		shop_map += "</div>";
		shop_map += "<ul style='margin:0;padding:0 15px;list-style-type:none;'>";
			shop_map += "<li style='text-align:center;font-size:14px;color:#800;font-weight:bold;border-bottom:2px #000 groove;'>请填写您的联系方式</li>";
			shop_map += "<li style='text-align:center;padding:5px 0;'>公　　　　司：<input type='text' id='S_Com' style='width:200px;border:1px #a8c5ff solid;' /></li>";
			shop_map += "<li style='text-align:center;padding:5px 0;'>姓　　　　名：<input type='text' id='S_Name' style='width:200px;border:1px #a8c5ff solid;' /></li>";
			shop_map += "<li style='text-align:center;padding:5px 0;'>电　　　　话：<input type='text' id='S_Tel' style='width:200px;border:1px #a8c5ff solid;' /></li>";
			shop_map += "<li style='text-align:center;padding:5px 0;'>邮　　　　箱：<input type='text' id='S_Mail' style='width:200px;border:1px #a8c5ff solid;' /></li>";
			shop_map += "<li style='text-align:center;padding:5px 0;'>其他联系方式：<textarea id='S_Other' style='width:200px;height:80px;border:1px #a8c5ff solid;'></textarea></li>";
			shop_map += "<li style='text-align:center;padding:5px 0;'>备　　　　注：<textarea id='S_Contents' style='width:200px;height:80px;border:1px #a8c5ff solid;'></textarea></li>";
		shop_map += "</ul>";
	shop_map += "</div></div>";
	$(document.body).append(shop_map);

	//全选
	$("#checkall").click( function() {
		$("#float_shop ul:first :checkbox").attr("checked",true);
	} );
	//反选
	$("#checkop").click( function() {
		$("#float_shop ul:first :checkbox").each( function() {
			if ( $(this).attr("checked") ) {
				$(this).attr("checked",false);
			}
			else {
				$(this).attr("checked",true);
			}
		} );
	} );
	//清除所选
	$("#buy").click( function() {
		showbuy();
	} );
	//购买
	$("#checknull").click( function() {
		clearoncheck();
	} );
	//关闭
	$("#close").click( function() {
		if ( shop_click ) {
			$("#float_shop_box").fadeOut("fast",function() { shop_click = false; });
		}
	} );
	
	//购买
	$("#buyit").click( function() {
		checkbuy();
	} );
	//返回购物车
	$("#returnshop").click( function() {
		if ( shop_click ) {
			$("#float_buy_box").fadeOut("fast",function() {
				shop_click = false;
				$("#float_shop_box").fadeIn("fast",function() {
					shop_click = true;
				} );
			});
		}
	} );
	//关闭购物
	$("#closebuy").click( function() {
		if ( shop_click ) {
			$("#float_buy_box").fadeOut("fast",function() { shop_click = false; });
		}
	} );
	$(window).scroll( function() {
		if ( shop_click ) {
			$("#float_shop").stop().animate( { "marginTop" : 200 + document.documentElement.scrollTop + document.body.scrollTop + "px" } , { queue: false, duration: 500 } );
			$("#float_buy").stop().animate( { "marginTop" : 200 + document.documentElement.scrollTop + document.body.scrollTop + "px" } , { queue: false, duration: 500 } );
		}
	} );
} );
//加入购物车
function buytoshop(id) {
	$.ajax( {
		type: "post",
		url: "/ajax/buytoshop.asp",
		cache: false,
		data: "id=" + id,
		dataType: "",
		error: function() { alert("Error loading XML document"); },
		success: function(result) {
			if ( typeof result == "string" ) {
				if ( result == "ok" ) {
					if ( $.browser.safari ) {
						alert("加入成功！");
					}
					else {
						if ( confirm("加入成功，是否现在查看购物车？") ) {
							showshop();
						}
					}
				}
				else if ( result == "has" ) {
					if ( $.browser.safari ) {
						alert("我已经在您的购物车里了。");
					}
					else {
						if ( confirm("我已经在您的购物车里了，是否现在查看购物车？") ) {
							showshop();
						}
					}
				}
				else {
					alert("加入失败！");
				}
			}
		}
	} );
}

var shop_click = false;
//显示
function showshop() {
	$.ajax( {
		type: "post",
		url: "/ajax/shop.asp",
		cache: false,
		data: "",
		dataType: ($.browser.msie) ? "text" : "xml",
		success: function(result) {
			if ( typeof result == "string" ) {
				var xml = new ActiveXObject("Microsoft.XMLDOM");
				xml.async = false;
				xml.loadXML(result);
			}
			else {
				var xml = result;
			}
			var shop , xmldate;
			if ( xml.getElementsByTagName("root")[0].getElementsByTagName("shop").length > 0 ) {
				shop = xml.getElementsByTagName("root")[0].getElementsByTagName("shop");
				var ulheight = 0;
				if ( shop.length % 5 == 0 ) {
					ulheight = parseInt(shop.length / 5) * 133;
				}
				else {
					ulheight = (parseInt(shop.length / 5) + 1) * 133;
				}
				$("#float_shop ul:first").empty().css("height",ulheight + "px");
				for ( var x = 0 ; x < shop.length ; x++ ) {
					xmldate = "<li style='width:113px;height:123px;padding:5px;float:left;text-align:center;font-size:14px;color:#222;overflow:hidden;'>";
						xmldate += "<a href='project.asp?id=" + shop[x].getAttribute("id") + "' style='display:block;width:100px;height:100px;'><img src='" + shop[x].getAttribute("pic") + "' width='100' style='border:1px #CCC solid;' /></a>";
						xmldate += "<div style='width:100px;height:23px;line-height:23px;text-align:left;clear:left;padding:3px 0;'>"
							xmldate += "<input type='checkbox' value='" + shop[x].getAttribute("id") + "' style='cursor:default;' onfocus='this.blur();' />";
							xmldate += "　<span style='cursor:pointer;'>" + shop[x].getAttribute("W_id") + "</span>";
						xmldate += "</div>";
					xmldate += "</li>";
					$("#float_shop ul:first").append(xmldate);
				}
				$("#float_shop_box ul input:checkbox").attr("checked",true);
				$("#float_shop ul:first").find("span").click( function() {
					setcheckshop($(this).parent());
				} );
			}
			else {
				$("#float_shop ul:first").empty().css("height","0");
			}
		}
	} );
	$("#float_shop").css( { "marginTop" : 200 + document.documentElement.scrollTop + document.body.scrollTop + "px" } );
	$("#float_shop_box").fadeIn("fast",function() {
		shop_click = true;
	} );
}
//点击文字，复选框选中
function setcheckshop(obj) {
	if ( obj.find("input").attr("checked") ) {
		obj.find("input").attr("checked",false);
	}
	else {
		obj.find("input").attr("checked",true);
	}
}

//清除所选
function clearoncheck() {
	var oncheck = $("#float_shop ul:first :checkbox:checked") , shop_ids = "" , i = 0;
	oncheck.each( function() {
		shop_ids += $(this).attr("value");
		if ( i < oncheck.length - 1 ) {
			shop_ids += ",";
		}
		i++;
	} );
	if ( shop_ids != "" ) {
		$.ajax( {
			type: "post",
			url: "/ajax/clearoncheck.asp",
			cache: false,
			data: "ids=" + shop_ids,
			dataType: "",
			success: function(result) {
				if ( typeof result == "string" ) {
					if ( result == "ok" ) {
						showshop();
					}
					else {
						alert("清除失败");
					}
				}
			}
		} );
	}
	else {
		alert("您还没有选择任何项目");
	}
}

//购买
function showbuy() {
	var oncheck = $("#float_shop ul:first :checkbox:checked") , shop_ids = "" , i = 0;
	oncheck.each( function() {
		shop_ids += $(this).attr("value");
		if ( i < oncheck.length - 1 ) {
			shop_ids += ",";
		}
		i++;
	} );
	if ( shop_ids != "" ) {
		$("#float_shop_box").fadeOut("fast",function() {
			shop_click = false;
			$("#float_buy").css( { "marginTop" : 200 + document.documentElement.scrollTop + document.body.scrollTop + "px" } );
			$("#float_buy_box").fadeIn("fast",function() {
				shop_click = true;
			} );
		});
	}
	else {
		alert("您还没有选择任何项目");
	}
}
function checkbuy() {
	var oncheck = $("#float_shop ul:first :checkbox:checked") , ids = "" , i = 0;
	oncheck.each( function() {
		ids += $(this).attr("value");
		if ( i < oncheck.length - 1 ) {
			ids += ",";
		}
		i++;
	} );
	if ( $("#S_Com").attr("value") == "" ) {
		alert("您还没有填写公司名称");
	}
	else if ( $("#S_Name").attr("value") == "" ) {
		alert("您还没有填写姓名");
	}
	else if ( $("#S_Tel").attr("value") == "" ) {
		alert("您还没有填写电话");
	}
	else if ( $("#S_Mail").attr("value") == "" ) {
		alert("您还没有填写邮箱");
	}
	else if ( !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test( $("#S_Mail").attr("value") ) ) {
		alert("您填写的邮箱格式不正确");
	}
	else {
		$.ajax( {
			type: "post",
			url: "/ajax/buy.asp",
			cache: false,
			data: "ids=" + ids + "&S_Name=" + escape($("#S_Name").attr("value")) + "&S_Com=" + escape($("#S_Com").attr("value")) + "&S_Tel=" + escape($("#S_Tel").attr("value")) + "&S_Mail=" + escape($("#S_Mail").attr("value")) + "&S_Other=" + escape($("#S_Other").attr("value")) + "&S_Contents=" + escape($("#S_Contents").attr("value")),
			dataType: "",
			success: function(result) {
				if ( typeof result == "string" ) {
					if ( result == "ok" ) {
						alert("谢谢惠顾，我们会及时与您联系。");
						$("#float_buy_box").fadeOut("fast",function() {
							shop_click = false;
							showshop();
						});
					}
					else {
						alert("购买失败");
					}
				}
			}
		} );
	}
}
