var name_array;
name_array="Overview,Description,Screenshots,Customer Reviews,Buy Notice" ;
new_array=name_array.split(",");


function show_info(id,id_null)
{
	
	var product_id=getParam('product_id');
	var u_id=getParam('u_id');
	
var the_name;
	
	view_pic.className="class_"+id;
	get_html(id,id_null)
	
	var obj;
	for (var i=0;i<5;i++)
	{
	
	obj=document.getElementById(new_array[i]+"_1");
	
	if (id==i) {obj.style.display='';
	
	

		
	the_name="product_view.php?product_id="+product_id;
	if (u_id!=null)
	{the_name=the_name+"&u_id="+u_id;}
	the_name=the_name+"#"+new_array[i];
	location.href=the_name;
		//alert(the_name);
	}
	else {obj.style.display='none';}
	}
	
	
	}

function   getParam(name){   
          var   reg   =   new   RegExp("(^|&)"+   name   +"=([^&]*)(&|$)");   
          var   r   =   window.location.search.substr(1).match(reg);   
          if   (r!=null)   return   unescape(r[2]);   return   null;   
      } 
	  
	  function get_html(id,product_id)
{
//alert(product_id)
var result="";
for (var i=0;i<5;i++)
{
if (id==i){
result=result+"<div class=this_menu_1 id=m_"+i+">"+new_array[i]+"</div>"
}

	

else
{result=result+"<div class=this_menu id=m_"+i+" onclick=' show_info("+i+",\""+product_id+"\");'>"+new_array[i]+"</div>"
}


}
view_pic.innerHTML=result;

}

//
function cart_to_phone(id)
{
	
	overLay();
	chkAndCreate("lightBox", "div");
	
	
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	
	
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	

	
	var s = "<div id=\"lightBox_box\">";
	s += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border:solid 2px #003399\"><tr><td id=\"lightBox_right\"><div id=\"lightBox_info\">";
	s += "Loading...";
	s += "</div><div id=\"lightBox_btn\">";
	s += "<span onclick='msg2_close()' style=\"color:#003399;cursor:pointer;font-weight:bold;text-decoration:underline\">Close Window</span>";
	s += "</div></td></tr></table></div>";
	
	$("lightBox").innerHTML = s;
	get_product_result("add_cart_phone.php?id="+id,id,"")
	
	
	return false;
}

function msg2_close()
{
	overLay_close();
	$("lightBox").style.display = "none";
	
	
}

function get_product_result(url,product_id,action)
{

var p="product_id="+product_id+"&action="+action+"r="+Math.random()
//alert(p)
var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: p,
onComplete: showResponseFav
});



}



function showResponseFav(originalRequest)
{

$('lightBox_info').innerHTML = originalRequest.responseText;
}


/////////////
function del_cart()
{

var del_all=""
var del_value=""
var checked_status=false

var del=document.getElementsByName("del_price")


for(i=0;i<del.length;i++)
{
var this_del=(del[i].checked?1:0);
if (i==del.length-1)
{del_all=del_all+this_del;}
else
{del_all=del_all+this_del+"_";
}
} 

for(i=0;i<del.length;i++)
{

if (i==del.length-1)
{del_value=del_value+del[i].value;}
else
{del_value=del_value+del[i].value+"_";
}
} 

for(i=0;i<del.length;i++)
{

if (del[i].checked==true) 
{
checked_status=true
break;
}

} 



if (del.length==0 && del[0].checked==true)
{   
	del_all=del[0].value;
}


query_del_cart(del_all)





}

function query_del_cart(d)
{
	
	
	var url;
	
	url = "del_cart.php";

	
	var p = "del_values=" + d ;
	

	var myAjax = new Ajax.Request(
		url,
		{
		method: 'get',
		parameters: p,
		onComplete: delcart2
		});
	
	return false;
}

function delcart2(originalRequest)
{
	var resp = originalRequest.responseText;
	
	var a = resp.split("\n");

	if(a[1] == "true")
	{
		
		setCookie("cilent_price", a[2]);
		
	location.href="cart.php";
		
	}
	
	
else if(a[1] == "false") //
	{   
		delCookie("cilent_price")
		
			location.href="cart.php";
		
		
	}
	
	else
	{
		msg2("<br />Error_info" + resp, "0");
	}
}

var g_deviceJustClicked;

function addDevice8Cookie(d)
{
	if (d=='' || d==null || d.length==0) {return false};
	setCookie("cphonetype", d);
	g_deviceJustClicked = d;
	var url;
	var cc;
	url = "/setCookies.php";
	
	cc = getCookie("phonetype");
	if(cc == null)
	{
		cc = "";
	}
	var p = "action=phonetype&phonetype=addtype&values=" + d + "&cc=" + cc + "&r=" + Math.random();
	
	var myAjax = new Ajax.Request(
		url,
		{
		method: 'get',
		parameters: p,
		onComplete: addDevice2Cookie8
		});
	
	return false;
}

function addDevice2Cookie8(originalRequest)
{
	var resp = originalRequest.responseText;

	//return false;
	var a = resp.split("\n");
//alert(a[1])
	if(a[0] == "true")
	{
		setCookie("phonetype", a[1]);
		
		
		
		//location.reload();
	}
	
	else if(a[0] == "false") //
	{
		
		
		
		location.replace("index.php")
	}
	
	else
	{
		msg2("<br />Error_info" + resp, "0");
	}
}

function setCookie(name, value)
{
	var Days = 30;
	var exp  = new Date();   
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString();

}
function getCookie(name)
{
  var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  if(arr != null) return unescape(arr[2]); return null;
}


function delCookie(name)
{
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  var cval=getCookie(name);
  if(cval!=null) document.cookie=name +"="+cval+";expires="+exp.toGMTString();
}


function msg2(product_id,num,action)
{
	var url;
	if (num==1)url="product_email.php"
	if (num==2)url="product_fav.php"
	if (num==3)url="product_dig.php"
	if (num==4)url="set_client_price.php"
	if (num==5)url="pay.php" //pay
	if (num==6)url="jifen.php" //pay
	
	
	overLay();
	chkAndCreate("lightBox", "div");
	
	//Ê¾
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	

	
	var s = "<div id=\"lightBox_box\">";
	s += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border:solid 2px #003399\"><tr><td id=\"lightBox_right\"><div id=\"lightBox_info\">";
	s += "Loading...";
	s += "</div><div id=\"lightBox_btn\">";
	s += "<span onclick='msg2_close()' style=\"color:#003399;cursor:pointer;font-weight:bold;text-decoration:underline\">Close Window</span>";
	s += "</div></td></tr></table></div>";
	$("lightBox").innerHTML = s;
	get_product_result(url,product_id,action)
	
	return false;
}

// getpass
function forget_pass()
{
	
	overLay();
	chkAndCreate("lightBox", "div");
	
	//Ê¾
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	
	//Ê¾
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	

	
	var s = "<div id=\"lightBox_box\">";
	s += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border:solid 2px #003399\"><tr><td id=\"lightBox_right\"><div id=\"lightBox_info\">";
	s += "Loading...";
	s += "</div><div id=\"lightBox_btn\">";
	s += "<span onclick='msg2_close()' style=\"color:#003399;cursor:pointer;font-weight:bold;text-decoration:underline\">Close Window</span>";
	s += "</div></td></tr></table></div>";
	
	$("lightBox").innerHTML = s;
	get_product_result('forget_pass.php')
	
	
	return false;
}
function get_pwd_step()
{
var forgot_id=$('forgot_id').value;
if (forgot_id=='')
{alert('Please input your  MMMOOO Member ID ');
return false;
}
get_product_result('forget_pass.php?forgot_id='+forgot_id)
	
}

//account

function m_c(num,p)  //Ëµ
{
var max_num=2
var color_1="#cce6ff"
var color_2="#FF9900"



for (var i=1;i<=max_num;i++)
{
var this_num="c"+i


if (i==num && num!=5)
{document.getElementById(this_num).style.background=color_2;
//document.getElementById(this_num).style="#ff9900 solid 1px";
account_result(num,p)
}
//else if(num==5)
//{window.open('/blog/?user='+getCookie('userid'));
//break;
//}
else
{document.getElementById(this_num).style.background=color_1;
account_result(num,p)
}

}





}



function account_result(num,p)
{
var url="";

if (num==1) url="account/view_1.php"
if (num==2) url="account/view_2.php"
if (num==3) url="account/view_3.php"


url=url+"?r="+Math.random()


var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: p,
onComplete: showResponseaccount
});

}


function showResponseaccount(originalRequest)
{

$('a_result').innerHTML = originalRequest.responseText;
}


//edit user
function check_pwd()
{
var nickname=$("nickname")
var password=$("password")
var password_1=$("password_1")
var password_2=$("password_2")



		
if (password_1.value!='' && password.value=='')
{alert("The Old Password field is required.");
  return false;}
		
if (password_1.value!='' &&  password_1.value.length<6)
{ alert("  Password Length is at least more than 6 Characters.");
  return false;}
  
		

if (password_2.value!=password_1.value)
{
	alert ("\nYou did not enter the same new password twice. Please re-enter your password.")
	return false
	}



var url="check_pwd.php"
var p="password="+password.value+"&password_1="+password_1.value+"&nickname="+nickname.value

var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: p,
onComplete: showResponsepwd
});



	}
	
	function showResponsepwd(originalRequest)
{
	
var resp = originalRequest.responseText;

var a = resp.split("\n");

	if(a[0] == "false")
{   
alert("Password is not correct. Please try again. ");


}

 if(a[0]=="true")
{
	

setCookie("firstname", a[1]);
alert("Successful!");

}



}

//pay hostory
function pay_history(page)
{
	
	overLay();
	chkAndCreate("lightBox", "div");
	
	//Ê¾
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	
	//Ê¾
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	

	
	var s = "<div id=\"lightBox_box\">";
	s += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border:solid 2px #003399\"><tr><td id=\"lightBox_right\"><div id=\"lightBox_info\">";
	s += "Loading...";
	s += "</div><div id=\"lightBox_btn\">";
	s += "<span onclick='msg2_close()' style=\"color:#003399;cursor:pointer;font-weight:bold;text-decoration:underline\">Close Window</span>";
	s += "</div></td></tr></table></div>";
	
	$("lightBox").innerHTML = s;
	get_product_result('pay_history.php?page='+page)
	
	
	return false;
}


function login_out(url)
{
delCookie("useremail")	
delCookie("password")
delCookie("userid")
delCookie("firstname")
delCookie("other_email")
delCookie("nickname")
delCookie("cphonetype")


if (url!=""){
location.href=url;	
}
else{
location.href='index.php';
}

}
function ajax_1(str)
{

var result;

var http_request = false; 


 if (window.XMLHttpRequest) { // Mozilla, Safari,... 
            http_request = new XMLHttpRequest(); 
            if (http_request.overrideMimeType) { 
                http_request.overrideMimeType('text/xml'); 
            } 
        } else if (window.ActiveXObject) { // IE 
            try { 
                http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
            } catch (e) { 
                try { 
                    http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
                } catch (e) {} 
            } 
        } 


http_request.open("POST",str,false); 
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
http_request.send(str); 

if (http_request.readyState == 4)
{

if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
result = http_request.responseText; 
http_request.close
return result
}

}
}
}

//review
function check_reviews_add(product_id)
{
var g_baseUrl="";
var star_num=document.getElementsByName("star")
var content=document.getElementById("content")

var useremail=document.getElementById("useremail")
var password=document.getElementById("password")

//var reviews_result=document.getElementById("content")
var star_value;
for (var i=0;i<star_num.length;i++)
{
	if (star_num[i].checked==true)
	
	{
	star_value=star_num[i].value;
	break;
	}
	
	}
	
	
	
	
	if (useremail.value=="")
	{alert("please in put your email address")
	useremail.focus();
	return false;
	}


if (password.value=="")
	{alert("please in put your password")
	password.focus();
	return false;
	}
	
	
	if (content.value=="")
	{alert("please in put your reviews")
	content.focus();
	return false;
	}
	
	
	//È¼Ã»Ç·
	
	var url_2;
	
	url_2 = g_baseUrl + "/check_login.php";

  
	
	var p_2 = "useremail=" + useremail.value+"&password="+password.value;
	
	
	
	
	var result=ajax_1("check_login.php?"+p_2)
	
	
var a = result.split("\n");
if(a[0] == "false")
{   
alert("User name or password is not correct. Please try again. ");
return false
}
		
if(a[0] == "true")
{
setCookie("useremail",a[1]);
setCookie("password", a[2]);

}


   


var url_1="review.php"

var p_1="product_id="+product_id+"&star_num="+star_value+"&content="+content.value+"&action=add&r="+Math.random()

var myAjax = new Ajax.Request(
url_1,
{
method: 'get',
parameters: p_1,
onComplete: showResponseReviews_review
});


}


function showResponseReviews_review(originalRequest)
{
//put returned XML in the textarea
$('reviews_result').innerHTML = originalRequest.responseText;
content.value='';
}

function get_review_result(product_id,page)
{
var url="review.php";
var p="product_id="+product_id+"&page="+page+"&r="+Math.random()

var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: p,
onComplete: showResponseReviews
});



}

function showResponseReviews(originalRequest)
{
//put returned XML in the textarea
$('reviews_result').innerHTML = originalRequest.responseText;
content.value='';
}

function cart_to_imei(id,phone_id)
{
	
	overLay();
	chkAndCreate("lightBox", "div");
	
	//Ê¾
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	
	//Ê¾
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	

	
	var s = "<div id=\"lightBox_box\">";
	s += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border:solid 2px #003399\"><tr><td id=\"lightBox_right\"><div id=\"lightBox_info\">";
	s += "Loading...";
	s += "</div><div id=\"lightBox_btn\">";
	s += "<span onclick='msg2_close()' style=\"color:#003399;cursor:pointer;font-weight:bold;text-decoration:underline\">Close Window</span>";
	s += "</div></td></tr></table></div>";
	
	$("lightBox").innerHTML = s;
	get_product_result("add_cart_phone.php?id="+id+"&phone_id="+phone_id+"&is_iemi=1&skip_dazhe=1",id,"")
	
	
	return false;
}

// 跳过打折码

function skip_dazhe(id)
{
	
	overLay();
	chkAndCreate("lightBox", "div");
	
	//Ê¾
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	
	//Ê¾
	$("lightBox").style.marginTop = -100 + document.documentElement.scrollTop + "px";
	$("lightBox").style.display = "block";
	

	
	var s = "<div id=\"lightBox_box\">";
	s += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border:solid 2px #003399\"><tr><td id=\"lightBox_right\"><div id=\"lightBox_info\">";
	s += "Loading...";
	s += "</div><div id=\"lightBox_btn\">";
	s += "<span onclick='msg2_close()' style=\"color:#003399;cursor:pointer;font-weight:bold;text-decoration:underline\">Close Window</span>";
	s += "</div></td></tr></table></div>";
	
	$("lightBox").innerHTML = s;
	get_product_result("add_cart_phone.php?id="+id+"&phone_id=&skip_dazhe=1",id,"")
	
	
	return false;
}





