﻿

function correctPNG()
{
   for(var i=0; i<document.images.length; i++)
   {
   var img = document.images[i]
   var imgName = img.src.toUpperCase()
   if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
   {
   var imgID = (img.id) ? "id='" + img.id + "' " : ""
   var imgClass = (img.className) ? "class='" + img.className + "' " : ""
   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
   var imgStyle = "display:inline-block;" + img.style.cssText
   if (img.align == "left") imgStyle = "float:left;" + imgStyle
   if (img.align == "right") imgStyle = "float:right;" + imgStyle
   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle 
   var strNewHTML = "<span " + imgID + imgClass + imgTitle
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
   + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
   img.outerHTML = strNewHTML
   i = i-1
   };
   };
};

if(navigator.userAgent.indexOf("MSIE")>-1)
{
window.attachEvent("onload", correctPNG);
};

function change_img(imgsrc,linkid)
{
	document.getElementById("smallpic").src=imgsrc;
	document.getElementById("bigpic").src=imgsrc;
	for(var i=1;i<7;i++)
	{
		if(document.getElementById("alink_"+i)!=null)
		 {
			document.getElementById("alink_"+i).className=""; 
			document.getElementById("aspan_"+i).className="";
		 }
	}
	document.getElementById("alink_"+linkid).className="noLinkIcon"; 
	document.getElementById("aspan_"+linkid).className="noLink";
}

function change_imglist_sp(colorid,pid)
{
	for(var i=1;i<7;i++)
	{
		if(document.getElementById("tlink_"+i)!=null)
		 {
			document.getElementById("tlink_"+i).className=""; 
			document.getElementById("tspan_"+i).className="";
		 }
	}
	document.getElementById("tlink_"+colorid).className="noLinkIcon"; 
	document.getElementById("tspan_"+colorid).className="noLink";
	ajax("spanish/getlist.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"jiaodulist");
	ajax_img("spanish/getlist_img.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"smallpic");
	ajax_img("spanish/getlist_img.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"bigpic");
	document.getElementById("color").value=colorid;
}

function change_imglist(colorid,pid)
{
	for(var i=1;i<7;i++)
	{
		if(document.getElementById("tlink_"+i)!=null)
		 {
			document.getElementById("tlink_"+i).className=""; 
			document.getElementById("tspan_"+i).className="";
		 }
	}
	document.getElementById("tlink_"+colorid).className="noLinkIcon"; 
	document.getElementById("tspan_"+colorid).className="noLink";
	ajax("getlist.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"jiaodulist");
	ajax_img("getlist_img.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"smallpic");
	ajax_img("getlist_img.asp?id="+pid+"&color="+colorid+"&r="+Math.random(),"bigpic");
	document.getElementById("color").value=colorid;
}

function createXMLHttps()
{
    var ret = null;
    try {
        ret = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e) {
        try {
            ret = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (ee) {
            ret = null;
        }
    }
    if (!ret && typeof XMLHttpRequest != 'undefined')
        ret = new XMLHttpRequest();
    return ret;
}

function ajax(URL,DIVID)
{
var obj_div=document.getElementById(DIVID);
var script="";
if(obj_div)
{
	var xmlhttp = createXMLHttps();
	xmlhttp.open("GET",URL,true);
	xmlhttp.onreadystatechange = function(){
 	if   (xmlhttp.readyState   ==   4)   {  
 	if   (xmlhttp.status   ==   200)   {   
 	document.getElementById(DIVID).innerHTML = xmlhttp.responseText;
	}  
 else   
 {   
alert( "您所请求的页面有异常。 "); 
} 
} 
}
	xmlhttp.send(null);
}
}

function ajax_img(URL,DIVID)
{
var obj_div=document.getElementById(DIVID);
var script="";
if(obj_div)
{
	var xmlhttp = createXMLHttps();
	xmlhttp.open("GET",URL,true);
	xmlhttp.onreadystatechange = function(){
 	if   (xmlhttp.readyState   ==   4)   {  
 	if   (xmlhttp.status   ==   200)   {   
 	document.getElementById(DIVID).src = xmlhttp.responseText;
	}  
 else   
 {   
alert( "您所请求的页面有异常。 "); 
} 
} 
}
	xmlhttp.send(null);
}
}


function gettotal()
{
   var t1=document.getElementById("num1").value;
   var t2=document.getElementById("num2").value;
   var t3=document.getElementById("num3").value;
   var t4=document.getElementById("num4").value;
   var t5=document.getElementById("num5").value;
   var total=0;
   if (isNaN(t1)==true||isNaN(t2)==true||isNaN(t3)==true||isNaN(t4)==true||isNaN(t5)==true)
   {
	   alert("Please enter a figure!");
   }
   else
   {
	  if(t1<0||t1<0||t1<0||t1<0||t1<0) 
	  {
		  alert("Please enter a positive number!");
	  }
	  else
	  {
		  total=parseInt(t1)+parseInt(t2)+parseInt(t3)+parseInt(t4)+parseInt(t5);
		  total=ForDight(total*parseFloat(document.getElementById("selfprice").value),2);
		  document.getElementById("total_num").innerHTML="Total:$"+total;
	  }
   }
}

function ForDight(Dight,How)

 { 

var Dight = Math.round (Dight*Math.pow(10,How))/Math.pow(10,How); 

return Dight; 

} 
function gettotal2()
{
   var t1=document.getElementById("num").value;
   var total=0;
   if (isNaN(t1)==true)
   {
	   alert("Please enter a figure!");
   }
   else
   {
	  if(t1<0||t1<0||t1<0||t1<0||t1<0) 
	  {
		  alert("Please enter a positive number!");
	  }
	  else
	  {
		  total=parseInt(t1);
		  total=ForDight(total*parseFloat(document.getElementById("selfprice").value),2);
		  document.getElementById("total_num").innerHTML="Total:$"+total;
	  }
   }
}


function subformlist()
{
   var t1=document.getElementById("num1").value;
   var t2=document.getElementById("num2").value;
   var t3=document.getElementById("num3").value;
   var t4=document.getElementById("num4").value;
   var t5=document.getElementById("num5").value;
   var total=0;
   if (isNaN(t1)==true||isNaN(t2)==true||isNaN(t3)==true||isNaN(t4)==true||isNaN(t5)==true)
   {
	   alert("Please enter a figure!");
   }
   else
   {
	  if(t1<0||t1<0||t1<0||t1<0||t1<0) 
	  {
		  alert("Please enter a positive number!");
	  }
	  else
	  {
		  total=parseInt(t1)+parseInt(t2)+parseInt(t3)+parseInt(t4)+parseInt(t5);
		  if(total>0)
		  {
			  document.getElementById("num").value=total;
			  var id=document.getElementById("pid").value;
			  var color=document.getElementById("color").value;
			  var url="save_cart.asp?pid="+id+"&color="+color+"&num1="+t1+"&num2="+t2+"&num3="+t3+"&num4="+t4+"&num5="+t5+"&num="+total;
			  location.href=url;
		  }
		  else
		  {
			  alert("Product quantity must be greater than 0!");
		  }
	  }
   }
}


function subform()
{
	var t1=document.getElementById("num").value;
   var total=0;
   if (isNaN(t1)==true)
   {
	   alert("Please enter a figure!");
   }
   else
   {
	  if(t1<0) 
	  {
		  alert("Please enter a positive number!");
	  }
	  else
	  {
		  total=parseInt(t1);
		  if(total>0)
		  {
			  var id=document.getElementById("pid").value;
			  var color=document.getElementById("color").value;
			  var url="save_cart.asp?pid="+id+"&color="+color+"&num="+total;
			  location.href=url;
		  }
		  else
		  {
			  alert("Product quantity must be greater than 0!");
		  }
	  }
   }
}

function adduser()
{
	var username=document.getElementById("username").value;
	if(checkspace_self(username) || username.length < 0)
	{
	   document.getElementById("username").focus();
       alert("Personnel Name should not be empty, please re-enter!");
	}
	else
	{
	  ajax("getuserc.asp?username="+username+"&r="+Math.random(),"userlist");
	}
}

function adduser_list(id)
{
	var username=escape(document.getElementById("username").value);
	if(checkspace_self(username) || username.length < 0)
	{
	   document.getElementById("username").focus();
       alert("Personnel Name should not be empty, please re-enter!");
	}
	else
	{
	  ajax("getuserlist.asp?id="+id+"&username="+username+"&r="+Math.random(),"userlist");
	  document.getElementById("circlelist").src="design_circle_mamage_content.asp?id="+id+"&r="+Math.random();
	}
}

function checkspace_self(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}


function go_next()
{
	if((this_page+1)*page_size<total_c)
	{
		for(i=0;i<page_size;i++)
		{
			document.getElementById("div_list_"+(i+(this_page)*page_size)).style.display="none";
		}
		for(i=0;i<page_size;i++)
		{
		    if(i+(this_page+1)*page_size<total_c)
			{
			//document.getElementById("div_list_"+(i+(this_page+1)*page_size)).style.display="";
			$("#div_list_"+(i+(this_page+1)*page_size)).css("list-style","none");
			$("#div_list_"+(i+(this_page+1)*page_size)).css("display","block");
			$("#div_list_"+(i+(this_page+1)*page_size)).css("width","74.9px");
			
			}
		}
		
		this_page=this_page+1;
	}
}
function go_pre()
{
	if((this_page-1)>=0)
	{
		for(i=0;i<page_size;i++)
		{
		    if(i+(this_page)*page_size<total_c)
			document.getElementById("div_list_"+(i+(this_page)*page_size)).style.display="none";
		}
		
		for(i=0;i<page_size;i++)
		{
		    if(i+(this_page-1)*page_size<total_c)
			document.getElementById("div_list_"+(i+(this_page-1)*page_size)).style.display="block";
		}
		this_page=this_page-1;
	}
}
jQuery.fn.loadthumb = function(options) {
	options = $.extend({
		 src : ""
	},options);
	var _self = this;
	_self.hide();
	var img = new Image();
	$(img).load(function(){
		_self.attr("src", options.src);
		_self.fadeIn("slow");
	}).attr("src", options.src);  
	return _self;
}

function change_img(pic_url,img_height)
{
  $(".imageViewBig").css("height",img_height +"px");
  $(".imageViewBig").css("padding","20px");
  $(".imageViewBig img").loadthumb({src:  pic_url });
}

function change_prd_img(pic_url,img_height)
{
  $(".productsViewBig").css("height",img_height +"px");
  $(".productsViewBig img").loadthumb({src:  pic_url });
}


function save_feedback()
{
	var check_D=true;
	var u_name=$("#name").val();
	var u_sex=$('input[name="sex"]:checked').val();
	var u_province=$("#province").val();
	var u_city=$("#city").val();
	var u_phone=$("#phone").val();
	var u_email=$("#email").val();
	var u_address=$("#address").val();
	var u_content=$("#content").val();
	if(u_name=="")
	{
		check_D=false;
		alert("请输入姓名");
		$("#name").focus(); 
	}
	else if(isNaN(u_sex))
	{
		check_D=false;
		alert("必须选择性别");
	}
	else if(u_province==""||u_city=="")
	{
		check_D=false;
		alert("请填写所在地区");
		if(u_province=="")
		$("#province").focus(); 
		else
		$("#city").focus(); 
	}
	else if(u_phone=="")
	{
		check_D=false;
		alert("请填写电话或手机号码");
		$("#phone").focus(); 
	}
	else if(u_email=="")
	{
		check_D=false;
	  	alert("邮箱地址不能为空");
		$("#email").focus(); 
	}
	else if(isMail(u_email)==false)
	{
		check_D=false;
	  	alert("邮箱地址格式错误");
		$("#email").focus(); 
	}
	else if(u_address=="")
	{
		check_D=false;
	  	alert("请填写邮寄地址");
		$("#address").focus(); 
	}
	else if(u_content=="")
	{
		check_D=false;
	  	alert("请填写客户留言");
		$("#content").focus(); 
	}
	else
	{
		//发送留言信息
		var url="save_feedback.php?name="+u_name+"&sex="+u_sex+"&province="+u_province+"&city="+u_city+"&phone="+u_phone+"&email="+u_email+"&address="+u_address+"&content="+u_content;
		TB_show(url);
	}
	return false;
}



function save_apply()
{
	var u_name=$("#name").val();
	var u_sex=$('#sex').val();
	var u_age=$("#age").val();
	var u_education=$("#education").val();
	var u_job=$("#job").val();
	var u_face=$("#face").val();
	var u_tel=$("#tel").val();
	var u_mobile=$("#mobile").val();
	var u_company=$("#company").val();
	var u_workTel=$("#workTel").val();
	var u_zipCode=$("#zipCode").val();
	var u_email=$("#email").val();
	var u_qq=$("#qq").val();
	var u_birthDay=$("#birthDay").val();
	var u_idCardNum=$("#idCardNum").val();
	var u_homeAddress=$("#homeAddress").val();
	var u_address=$("#address").val();
	var u_locationPerson=$('input[name="locationPerson"]:checked').val(); //radio
	var u_locationAverageIncome=$('input[name="locationAverageIncome"]:checked').val(); //radio
	var u_joinGrade=$('#joinGrade').val();
	var u_fund=$('#fund').val();
	var u_province=$('#province').val();
	var u_city=$('#city').val();
	var u_district=$('#district').val();
	var u_businessType=$('input[name="businessType"]:checked').val(); //radio
	var u_businessOrgan = "";//checkbox
    $("input[name='businessOrgan']").each(function(){
        if($(this).attr("checked") == true){
        	if(u_businessOrgan!="")
				u_businessOrgan+=",";
			u_businessOrgan += $(this).val();
        }
    })
	var u_businessPerson=$('input[name="businessPerson"]:checked').val();//radio
	var u_businessTraffic=$('input[name="businessTraffic"]:checked').val();//radio
	var u_businessPersonNum=$('input[name="businessPersonNum"]:checked').val();//radio
	var u_businessOther=$("#businessOther").val();
	var u_marketManager=$('input[name="marketManager"]:checked').val();//radio
	var u_advice=$("#advice").val();
	var u_remark=$("#remark").val();
	if(u_name=="")
	{
		check_D=false;
		alert("请输入姓名");
		$("#name").focus(); 
	}
	else if(u_job=="")
	{
		check_D=false;
		alert("请输入职业");
		$("#job").focus(); 
	}
	else if(u_tel=="")
	{
		check_D=false;
		alert("请填写联系电话");
		$("#tel").focus(); 
	}
	else if(u_mobile=="")
	{
		check_D=false;
		alert("请填写手机号码");
		$("#mobile").focus(); 
	}
	else if(u_homeAddress=="")
	{
		check_D=false;
	  	alert("请填写家庭住址");
		$("#homeAddress").focus(); 
	}
	else if(u_locationPerson=="")
	{
		check_D=false;
		alert('请选择当地常住人口');
	}
	else if(u_locationAverageIncome=="")
	{
		check_D=false;
	  	alert("请选择当地人均收入");
	}
	else if(u_fund=="")
	{
		check_D=false;
	  	alert("请填写投资金额");
		$("#fund").focus(); 
	}
	else if(u_province==""||u_city=="")
	{
		check_D=false;
	  	alert("请填写投资商圈区域");
		if(u_province=="")
		$("#province").focus(); 
		else
		$("#city").focus(); 
	}
	else if(u_businessType==undefined)
	{
		check_D=false;
	  	alert("请选择商圈类型");
	}
	else if(u_businessOrgan=="")
	{
		check_D=false;
	  	alert("请选择主要机构");
	}
	else if(u_businessPerson==undefined)
	{
		check_D=false;
	  	alert("请选择人群结构");
	}
	else if(u_businessTraffic==undefined)
	{
		check_D=false;
	  	alert("请选择交通情况");
	}
	else if(u_businessPersonNum==undefined)
	{
		check_D=false;
	  	alert("请选择人口情况");
	}
	else if(u_marketManager==undefined)
	{
		check_D=false;
	  	alert("请选择市场经理");
	}
	else
	{
		
		//发送留言信息
		var url="save_apply.php?name="+u_name;
        url+="&sex="+u_sex;
		url+="&age="+u_age;
		url+="&education="+u_education;
		url+="&job="+u_job;
		url+="&face="+u_face;
		url+="&tel="+u_tel;
		url+="&mobile="+u_mobile;
		url+="&company="+u_company;
		url+="&workTel="+u_workTel;
		url+="&zipCode="+u_zipCode;
		url+="&email="+u_email;
		url+="&qq="+u_qq;
		url+="&birthDay="+u_birthDay;
		url+="&idCardNum="+u_idCardNum;
		url+="&homeAddress="+u_homeAddress;
		url+="&address="+u_address;
		url+="&locationPerson="+u_locationPerson;
		url+="&locationAverageIncome="+u_locationAverageIncome;
		url+="&joinGrade="+u_joinGrade;
		url+="&fund="+u_fund;
		url+="&province="+u_province;
		url+="&city="+u_city;
		url+="&district="+u_district;
		url+="&businessType="+u_businessType;
		url+="&businessOrgan="+u_businessOrgan;
		url+="&businessPerson="+u_businessPerson;
		url+="&businessTraffic="+u_businessTraffic;
		url+="&businessPersonNum="+u_businessPersonNum;
		url+="&businessOther="+u_businessOther;
		url+="&marketManager="+u_marketManager;
		url+="&advice="+u_advice;
		url+="&remark="+u_remark;
		TB_show(url);
	}
	return false;
}















function TB_show(url) { //function called when the user clicks on a thickbox link
	try {
		$("body")
		.append("<div id='TB_overlay'></div><div id='TB_window'></div>");
		$("#TB_overlay").css("opacity","0.6");
		$("#TB_overlay").css("filter","alpha(opacity=60)");
		$("#TB_overlay").css("-moz-opacity","0.6");
		$(window).resize(TB_position);
		$("body").append("<div id='TB_load'><div id='TB_loadContent'>信息提交中.....</div></div>");
		TB_position();
		$(window).scroll(function(){TB_position();});
		$("#TB_overlay").show();
		$.get(url+"&rnd_num="+Math.random(),function(data){
		TB_remove();
		var status_S=$(data).find('status').text();
		var message_S=$(data).find('message').text();
		if(status_S=="1")
		{
			reset_feedback();
		}
		alert(message_S);
		});
		
	} catch(e) {
		alert(e);
	}
}

function TB_remove() {
	$('#TB_window,#TB_overlay,#TB_load').remove();
	return false;
}



function TB_position() {
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
  
  	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
  	}
	$("#TB_overlay").css("height",yScroll +"px");
	var loadContent_top=(h-100)/2+$(document).scrollTop();
	//alert(loadContent_top);
	$("#TB_load").css("top",loadContent_top+"px");
}


function isMail(mail) {
    var patrn = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    if (!patrn.test(mail))
        return false;
    else
        return true;
}


function reset_feedback()
{
	document.getElementById("feedback").reset();
	//$("#feedback").reset();
}
