﻿// JavaScript Document
// JavaScript Document

function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}



function SetCookie(name, value)
//设定Cookie值
{
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 10000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}



function DelCookie(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() - 10000);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}


function GetCookie(name)
//获得Cookie的原始值
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
		while (i < clen)
		{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
		}
	return null;
} 


function KeyPress(objTR)
{//只允许录入数据字符 0-9 和小数点
   //var objTR = element.document.activeElement;  
    var txtval=objTR.value;  
    var l=objTR.value.length;
    var key = event.keyCode;
    if((key < 48||key > 57)&&key != 46)
    {  
        event.keyCode = 0;
    }    
    else
    {
        if(key == 46)
        {
            if(txtval.indexOf(".") != -1||txtval.length == 0)
            {
                event.keyCode = 0;
            }
        }
    }
    if(txtval.indexOf(".") != -1)
    {
        var decimalPart=txtval.substring(txtval.indexOf(".")+1,l);  
        if(decimalPart.length>=2)
        {  
            event.keyCode = 0;
        }
    }
}

function createRequest()
{
    var xmlHttp;
    try{// Firefox, Opera 8.0+, Safari
            xmlHttp=new XMLHttpRequest();
    }catch (e){// Internet Explorer
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
            try{
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e){
                alert("您的操作系统版本过低，请下载升级文件");
            return false;
            }
        }
    }
    return xmlHttp;
}

function get_page(url,obj_id)
{
    //会不会是这边在创建的时候 缺少一些选项控制？
	
    var xmlHttp=createRequest();
    xmlHttp.open("POST",url,true);
    xmlHttp.onreadystatechange=function()
	{
	   //alert(xmlHttp.readyState);

		
		
	 if (xmlHttp.readyState == 4) 
	 {
      if (xmlHttp.status == 200) 
	  {
        var response = xmlHttp.responseText;
        document.getElementById(obj_id).innerHTML =  response;
	   
		
      }

     }
     else 
	 {
		
        document.getElementById(obj_id).innerHTML = "<div style='position:absolute;padding-top:60px;z-index:100;text-align:center'><img src=loading.gif></div>"+document.getElementById(obj_id).innerHTML;
		
     }
		
		
		
    }
    xmlHttp.send(null);
	
}


function get_code_value(url)
{
			if (window.ActiveXObject) 
			{
				   var  oBaos = new ActiveXObject('Microsoft.XMLHTTP');
				   oBaos.open("POST",url,false);
                   oBaos.send(null);
			}
			else if (window.XMLHttpRequest) 
			{
					var  oBaos = new XMLHttpRequest();
					oBaos.open("GET",url, false);
					oBaos.send(null);
			}
	        var strResultmails = unescape(oBaos.responseText);
		    return(strResultmails);
}

function add_card(id,types)
{
	
	var w = 300;
	var h = 150;
	var url = '/inc/active.php?act=addcp&cpid='+id+'&types='+types+"&code=1";
	//alert(url)

    openr(w,h);	
	//get_page(url,'login_box');
	var value = get_code_value(url);
	if(value)
	{
	    var value_arr = value.split("|");	
	  
	}
	  document.getElementById('login_box').innerHTML = '成功放入购物车<br><br>您的购物车中有（'+value_arr[0]+'）件商品,合计（'+value_arr[1]+'）元<br/><br/> [<a href=javascript: onclick="closer();" style=color:red>继续购物] [<a href=/buy.php style=color:red>立即结算</a>]<br>';
		document.getElementById('login_tit').innerHTML = '购物车';
		document.getElementById('c_number').innerHTML = '('+value_arr[0]+')';
	
}

function vip_add_card(id,types)
{

	var w = 300;
	var h = 150;
	var url = '/inc/active.php?act=addcp&cpid='+id+'&types='+types+"&code=1&codetimes=1";
    openr(w,h);	
	//get_page(url,'login_box');
	var value = get_code_value(url);
	 var value_arr2 = value.split("|");
	
	if(value_arr2[1]&&value_arr2[1]!=2)
	{   

	    var value_arr = value.split("|");

	    document.getElementById('login_box').innerHTML = '成功放入购物车<br><br>您的购物车中有（'+value_arr[0]+'）件商品,合计（'+value_arr[1]+'）元<br/><br/>[<a href=?lib=buy style=color:red>查看购物车</a>] [<a href=javascript: onclick="closer();" style=color:red>继续购物] [<a href=?lib=buy style=color:red>立即结算</a>]<br>';
		document.getElementById('login_tit').innerHTML = '购物车';
		document.getElementById('c_number').innerHTML = '('+value_arr[0]+')';
	}else{
  
    document.getElementById('login_box').innerHTML = '<span style=color:red>[该钻石已经在您的购物车里]<br>[请不要重复订购]<span>';
	document.getElementById('login_tit').innerHTML = '购物车';
	}
}
function vip_add_card2(id,types)
{

	
	var url = '/inc/active.php?act=addcp&cpid='+id+'&types='+types+"&code=1&codetimes=1";

	//get_page(url,'login_box');
	var value = get_code_value(url);
   return 'true';
}


function list_id()
{   	


	var temp="";    
	var url = '';
	var value_arr = '';
	var id = 0;
	var endid = 0;
	var lens = document.form_buy.id.length;
	var count=0;
	if(lens != undefined)
	{ 
		
	  for(var i=0;i<lens;i++)    
	  {    
		  
		   if(document.form_buy.id[i].checked)  
		   {   
			  count++;
			   id = document.form_buy.id[i].value;
			   
			   if(id)
			   {
				   url = '/inc/active.php?act=addcp&cpid='+id+'&types=2&code=1';
				   value_arr = get_code_value(url);
				   endid = id;
				  
			   }
			   
		   //temp+=form_buy.id[i].value+"|";    
		   } 
		}
	}
	else
	{   
		
		endid = document.form_buy.id.value;
		//;
	}
	if(count==0){
		$.weeboxs.open('对不起,您还没有选择钻石..', {title: '提示', type:'alert'});		
	}else{
	
	$.weeboxs.open('成功加入到购物车..[<a href=?lib=buy style=color:red>查看购物车</a>]', {title: '提示', type:'alert'});	
	}
	//vip_add_card(0,2);

}



function cplist_id()
{
	var temp="";    
	var url = '';
	var value_arr = '';
	var id = 0;
	var endid = 0;
	var lens = document.form_buy.id.length;
	//alert(lens);
	if(lens != undefined)
	{
	  for(var i=0;i<lens;i++)    
	  {    
		   if(document.form_buy.id[i].checked)  
		   {
			   id = document.form_buy.id[i].value;
			   if(id)
			   {
				   url = '/inc/active.php?act=addcp&cpid='+id+'&types=3&code=1';
				   value_arr = get_code_value(url);
				   endid = id;
				  
			   }
			   
		   //temp+=form_buy.id[i].value+"|";    
		   } 
		}
	}
	else
	{
		endid = document.form_buy.id.value;
		//alert(endid);
	}
	vip_add_card(0,3);

}

function add_sc(id)
{
	
	var w = 300;
	var h = 150;
	var url = '/inc/active.php?act=addsc&cpid='+id;
    openr(w,h);	
	get_page(url,'login_box');
	document.getElementById('login_tit').innerHTML = '成功提示';

}

function show(id)
{
	document.getElementById(id).style.display='';
}
function hide(id)
{
	document.getElementById(id).style.display='none';
}
