// HTTP Request
HTTPRequest = function () {
var xmlhttp=null;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (_e) {
    try {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (_E) { }
 }
 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
   try {
    xmlhttp = new XMLHttpRequest();
    } catch (e) {
    xmlhttp = false;
   }
  }
 return xmlhttp;
};
function askNull(url) {
var http = new HTTPRequest();
 http.open("GET", url, true);
 http.send(null);
 http.onreadystatechange = function (){ handleHttpResponseNull(http)};
}
function handleHttpResponseNull(http)
{ 
	if(http.readyState == 4)
	{ 
		if(http.status == 200)
		{ 
			eval(http.responseText);

		} 
	} 
}
function askPost(url,questStr,div) {
var http = new HTTPRequest();
 http.open("POST", url, true);
 http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
 http.send(questStr);
 http.onreadystatechange = function (){ handleHttpResponsePost(http,div)};
}

function ajax(url,data, func) {
	var http = new HTTPRequest();
	http.open("POST", url, true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send(data);
	http.onreadystatechange = function() {
		if (http.readyState == 4) {
			var data = http.responseText;
			func(data);
		}
	};
	return true;
}

function handleHttpResponsePost(http,div) {
 if (http.readyState == 4) {
  result = http.responseText;
  document.getElementById(div).innerHTML = result;
}
}

// show password
function askPwd(url,questStr,div,hid,val) {
var http = new HTTPRequest();
  http.open("POST", url, true);
  http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
  http.send(questStr);
  http.onreadystatechange = function (){ handleHttpResponsePwd(http,div,hid,val)};
}

function handleHttpResponsePwd(http,div,hid,val) {
 if (http.readyState == 4) {
 result = http.responseText;
  if (result == "ok") {
		resetMSG(div); 
		document.getElementById("cpassword").readOnly=false;
		document.getElementById("password").readOnly=false;
		document.getElementById(hid).value=1; 
		val.style.backgroundColor = '#FFFFFF'; }
	else {
		ShowMSG(div,result); 
		document.getElementById("c_password").value=-1; 
		document.getElementById("c_cpassword").value=-1; 
		document.getElementById("password").value=""; 
		document.getElementById("cpassword").value=""; 
		document.getElementById("cpassword").readOnly=true;
		document.getElementById("password").readOnly=true;
		document.getElementById(hid).value=-1; 
		val.style.backgroundColor = '#FFFF99';	
	}

}
}


function askReg(url,questStr,div,hid,val) {
var http = new HTTPRequest();
  http.open("POST", url, true);
  http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
  http.send(questStr);
  http.onreadystatechange = function (){ handleHttpResponseReg(http,div,hid,val)};
}

function handleHttpResponseReg(http,div,hid,val) {
 if (http.readyState == 4) {
result = http.responseText;
	if (result == "ok") {
		resetMSG(div); 
		document.getElementById(hid).value=1; 
		val.style.backgroundColor = '#FFFFFF'; }
	else {
		ShowMSG(div,result); 
		document.getElementById(hid).value=-1; 
		val.style.backgroundColor = '#FFFF99';	
	}

}
}

// Login Module
function Login(url,questStr,div,cdiv) {
var http = new HTTPRequest();
 http.open("POST", url, true);
  http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
  http.send(questStr);
  http.onreadystatechange = function (){ handleHttpResponseLogin(http,div,cdiv)};
}
//Check Login
function ClickEnter(cc,e,flag) {
	if (cc==13) { check_login(e);} 
	}
function ClickEnter_(cc,e,flag) {
	if (cc==13) { check_login(document.forms['customer_loginform'],'customer_login','member_login');} 
	}
function handleHttpResponseLogin(http,div,cdiv) {
	 if (http.readyState == 4) {
    var result = http.responseText;
	var results = result.split("|");
	 if(results[0]=="error") {
	   if (cdiv!="") {
		 document.getElementById("customer_login").innerHTML = cdiv;
			document.getElementById("login").innerHTML = div;
	   		ShowMSG("customer_login_msg",results[1]);
			}
		else  {   
		    alert(results[1]);
	   }
	   }
	   else if (results[0]=="common") {
        if (cdiv!="") {
			document.getElementById("u_login").innerHTML = results[2];
			document.getElementById("customer_login").innerHTML = results[1];
			window.location.reload();
		} else { 
			document.getElementById("u_login").innerHTML = results[2];
			window.location.reload();
        }
    }else
	{document.getElementById("u_login").innerHTML = results[1];
	 	window.location.reload();
	}
	   
}
}

function check_login(e,flag,source)
{
	var msg;
	var textAll = "Please enter your Username and Password.";
	var textName = "";
	var textPassw = "";
    var questStr = "";
	var  loginsource;
	if (e.username.value == "E-mail") { 
	   textName = "Please enter your Username."; 
	  }

	if (e.pwd.value == "************") { 
 textPassw = "Please enter your Password."; 
	}
	
	if (textName=="") { 
	  if (!CheckEmail(e.username.value))  {
		alert('Invalid E-mail Address.');
		return false;
		  } } 
	
	if (e.username.style) e.username.style.backgroundColor = textName != "" ? '#FFFF99':'#FFFFFF';
	if (e.pwd.style) e.pwd.style.backgroundColor = textPassw != "" ? '#FFFF99':'#FFFFFF';

	if ((textPassw == "") && (textName == "")) { 
	  var username = escape(e.username.value);
	  var password = escape(e.pwd.value);
	  var loginDIV = document.getElementById("login").innerHTML;
	  var CloginDIV = "";
	  if (document.getElementById("customer_login")) { CloginDIV = document.getElementById("customer_login").innerHTML;}
	  resetMSG("login_msg");
	  if (document.getElementById("customer_login_msg")) { resetMSG("customer_login_msg"); }
	  if (document.getElementById("customer_login")) { document.getElementById("customer_login").innerHTML=procbar;}
	  if(source=="member_login")
	  {loginsource="login";}
	  else if(source=="common_login")
	  {loginsource="login";}
	  else if(source=="check_out_login")
	  {loginsource="checklogin";}
	  else
	  {loginsource="login";}
	  questStr = "ajaxtype="+loginsource+"&username="+username+"&password="+password;
	 Login("/inc/memberlogin.proc.php",questStr,loginDIV,CloginDIV);
	  return false; }

	if (flag=="login") {
		if (textName && textPassw) {
			msg = textAll;
		} else {
			msg = textName + textPassw;
		}
		ShowMSG("login_msg",msg);
	}
	else if (flag=="customer_login") { 
		if (textName != "") { ShowMSG("username_msg",textName); }
		if (textPassw != "") { ShowMSG("password_msg",textPassw); }
	}
	return false;
}
//Logout 
function Logout() {
	url="/inc/memberlogin.proc.php?ajaxtype=logout";
	ajax(
		url,
		'&ajax=1',
		function() {
			window.location.reload();
		}
	); 
}
		
//Track Order
function trackorder()
{ 
	var ordertype = document.getElementById('ordertype').value;
	var order = document.getElementById('order').value;
	var ordername = document.getElementById('ordername').value;
	var questStr = "ordertype="+ordertype+"&order="+order+"&ordername="+ordername;
	document.getElementById('show').innerHTML="processing";
	askPost("ordercheck.php",questStr,"show");	
	//askNull(qurl);
}		
function askCode(url,questStr) {
var http = new HTTPRequest();
  http.open("POST", url, true);
  http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
  http.send(questStr);
  http.onreadystatechange = function (){ handleCode(http)};
}

function handleCode(http) {
 if (http.readyState == 4) {
 var result = http.responseText;
	var results = result.split("||");
    
if (results[0] == "error") { ShowMSG("code_msg",results[1]); } 
   else { 
    var discount = results[1];
	var total = results[2];
	document.getElementById("checkout_code").style.display = "none";
	document.getElementById("mc_discount").innerHTML = "- "+discount;
	document.getElementById("mc_total").innerHTML = total;
	document.getElementById("new_ccode").style.display = "";
	 
	refreshcart();
	 
   }
}
}

// Define Processing Bar
var txt,ctxt;
var procbar,checkbar;
txt="Processing ..."; ctxt="Validating ...";
procbar = "<table width=100% border=0><tr><td align=center valign=middle height=100><img src=/images/loading.gif width=16 height=16 align=absmiddle /> "+ txt +" </td></tr></table>";
checkbar = "<img src=/images/loading.gif width=16 height=16 align=absmiddle /> "+ ctxt;
validbar = "<table width=100% border=0 cellspacing=0 cellpadding=5 class=table_2><tr><td align=center><img src=/images/loading.gif width=16 height=16 align=absmiddle /> "+ ctxt+" </td></tr></table>";

//Gold Add to Cart 
function cdkey_addtocart(obj) {
	var gd_q = "gd_quantity_"+obj;
	var gd_p = "gd_price_"+obj;
	var gd_ep = "gd_eprice_"+obj;
	var gd_prod = "gd_productid_"+obj;
	var gd_productid = escape(document.getElementById(gd_prod).value);
	var gd_gameid = escape(document.getElementById("gd_gameid").value);
	var gd_quantity = escape(document.getElementById(gd_q).value);
	var gd_currency = escape(document.getElementById("gd_currency").value);
	var gd_price = escape(document.getElementById(gd_p).value);
	var gd_eprice = escape(document.getElementById(gd_ep).value);
	var cart_status_old = document.getElementById("cart_status").value;
	document.getElementById("cart").innerHTML = procbar;
	questStr = "gd_gameid="+gd_gameid+"&gd_quantity="+gd_quantity+"&gd_price="+gd_price+"&gd_eprice="+gd_eprice+"&cart_action=add"+"&gd_productid="+gd_productid+"&gd_currency="+gd_currency;
	if (document.getElementById('qty') != undefined && $("qty").value != '') {
		questStr += '&qty=' + $('qty').value;
	}
	alert("Item Added");
	askPost("cdkey_action.php",questStr,"cart");	
	//setTimeout("location.href='gold_checkout.php'",2000);
	if (cart_status_old =="empty") { setTimeout("location.href='/cdkey-checkout.php'",2000); }
}

//Delete Cdkey Cart
function delcdkeycart(e) {
	document.getElementById("cart_main").innerHTML = procbar;
	document.getElementById("cart").innerHTML = procbar;
	questStr = "cart_action=del&id="+e;
	askPost("cdkey_action.php",questStr,"cart");	
	askPost("del_cdkey_cart.php",questStr,"cart_main");
}	
//Update Cdkey Cart
function upcdkeycart(e,f) {
	var newcount="count"+e;
	var count=escape(document.getElementById(newcount).value);
	document.getElementById("cart_main").innerHTML = procbar;
	document.getElementById("cart").innerHTML = procbar;
	questStr = "cart_action=update&count="+count+"&id="+e;
	askPost("cdkey_action.php",questStr,"cart");	
	askPost("update_cdkey_cart.php",questStr,"cart_main");
}

//Clean CDkey Cart
function cleancdkeycart() {
	document.getElementById("cart_main").innerHTML = procbar;
	document.getElementById("cart").innerHTML = procbar;
	questStr = "cart_action=clean";
	askPost("cdkey_action.php",questStr,"cart");	
	askPost("del_cart.php",questStr,"cart_main");
    }


//Post Payment
function checkpayment(e,div) {
	document.getElementById("payment").innerHTML = procbar;
	var questStr = "id="+e;
	askPost("/paymentinfo.php",questStr,div);
}
//Check Coupon code 
function _DoCheckCode(e) {
	if (e.coupon_code.value=="" || isblank(e.coupon_code.value)) { 
	 document.getElementById("code_msg").style.display="";
	 return false;
	}

	document.getElementById("code_msg").innerHTML= checkbar;
	document.getElementById("code_msg").style.display="";
	
	var code = escape(e.coupon_code.value);
	var questStr = "action=checkcode&code="+code;
	askCode("url",questStr);
}
//Check Account
function check_useremail(val,name) {
	var e=val.value;
	var msg="";
	var div = name.toString()+"_msg";
	var hid = "c_"+name.toString();

	if (!CheckEmail(e)) { 
	 msg = "The email address must be in example@eing.com format. Special characters such as ( ) < > [ ] , ; : \ etc. are generally not allowed. Similarly, non-ASCII characters such as + - etc. are prohibited."; 
		val.style.backgroundColor = '#FFFF99';
	 ShowMSG(div,msg); 
	 document.getElementById(hid).value=-1; 
	 return false;
	}else { resetMSG(div);document.getElementById(hid).value=1; 
																																																																																																											val.style.backgroundColor = '#FFFFFF'; return true;}
}
// Check register
function check_reguser(val,name) {
	var e=val.value;
	var msg="";
	var div = name.toString()+"_msg";
	var hid = "c_"+name.toString();

	if (!CheckEmail(e)) { 
	 msg = "The email address must be in example@eing.com format. Special characters such as ( ) < > [ ] , ; : \ etc. are generally not allowed. Similarly, non-ASCII characters such as ????etc. are prohibited."; 
		val.style.backgroundColor = '#FFFF99';
	 ShowMSG(div,msg); 
	 document.getElementById(hid).value=-1; 
	 return false;
	}
	if ($(div) == undefined) {
		arr = div.split('_msg');
		var divMsg = document.createElement("div");
		divMsg.id = div;
		$(arr[0]).parentNode.appendChild(divMsg)
	}
	document.getElementById(div).innerHTML = checkbar;
	document.getElementById(hid).value=0; 
	
	questStr = "email="+escape(e);
	askReg("check-reg.php",questStr,div,hid,val);
}

function _DoLostPassword (e) {
	var msg_email = "Please specify a valid e-mail address.";
	var email;
	var flag=0;
	var questStr;
	if (isblank(e.email.value) || e.email.value=="") {
		ShowMSG("email_msg",msg_email);
		_DoSetBG(e.username,0);
		return false;
	} else {
		resetMSG("email_msg");
		_DoSetBG(e.email,1);
		email=escape(e.email.value);
	}
	if (flag == 0) {
		document.getElementById("editwin").innerHTML = procbar;
		questStr = "action=email&email="+email;
		askPost("/forget_password.inc.php",questStr,"editwin");	
	}
	return false;	
}

function _DoAnswer(e) {
	var msg_answer;
	var answer;
	var email;
	var flag=0;
	var questStr;
	msg_answer = "Please type your Answer.";
	if (e.c_answer.value == -1) { flag=flag+1; ShowMSG("answer_msg",msg_answer); _DoSetBG(e.answer,0); }
	else if (e.c_answer.value == 1) { 
		if (isblank(e.answer.value) || e.answer.value=="") { flag=flag+1; ShowMSG("answer_msg",msg_answer); _DoSetBG(e.answer,0); }
		else { resetMSG("msg_error"); resetMSG("answer_msg"); _DoSetBG(e.answer,1); answer=escape(e.answer.value); } }
	
	email = e.email.value;
	if (flag == 0) { 
		document.getElementById("lost_password").innerHTML = procbar;
		questStr = "action=question&email="+email+"&answer="+answer;
	askPost("/forget_password.inc.php",questStr,"lost_password");	
	}
	return false;	
}

// Check oldpassword
function check_oldpassword(val,name) {
	var e=val.value;
	var msg="";
	var div = name.toString()+"_msg";
	var hid = "c_"+name.toString();
    if (isblank(e) || e=="")
	{   
	    resetMSG("oldpassword_msg"); 
		resetMSG("password_msg"); 
		resetMSG("cpassword_msg"); 
		document.getElementById(hid).value=-1; 
		document.getElementById("c_password").value=-1; 
		document.getElementById("c_cpassword").value=-1; 
		document.getElementById("password").value=""; 
		document.getElementById("cpassword").value=""; 
		document.getElementById("cpassword").readOnly=true;
		document.getElementById("password").readOnly=true;
		return false;
		}
	//document.getElementById(div).innerHTML = checkbar;
	document.getElementById(hid).value=0; 
	questStr = "oldpassword="+escape(e);
    askPwd("check-pwd.php",questStr,div,hid,val);
}
//edit Profile
function _DoChangeProfile(e) {
    var msg_fname, msg_lname, msg_phone,msg_address,msg_city,msg_state,msg_country,msg_zip;
	var fname,lname,phone,address,city,state,country,zip;
	var msg_pwd, msg_conpwd, msg_cpwd,msg_oldpwd,msg_proc;
	var password;
	var pwd=0;
	var flag=0;
	var msg_enews;
	var enews;
	var gameinfo="";
	var count = Number(e.enews_count.value);
	var enews_id;
	var cur_count=0;
	var questStr;
	         msg_oldpwd = "Please specify a valid password address.";
		     msg_proc = "Our system is verifying your password, please wait a second.";
	 	     msg_pwd = "Please specify your Password.";
			 msg_conpwd = "Please Re-type your Password.";
			 msg_cpwd = "Your password entries did not match.";
			 msg_fname = "Please specify a First Name.";
			 msg_lname = "Please specify a Last Name.";
			 msg_phone = "Please specify your Contact Phone.";
			 msg_address = "Please specify your Address.";
			 msg_city = "Please specify your City.";
			 msg_state = "Please specify your State or Province.";
			 msg_country = "Please specify your Country.";
			 msg_zip = "Please specify a Zip or Postal Code.";
			 msg_enews = "Please check the boxes to indicate which newsletters you’d like to receive from us.";
 if (e.c_oldpassword.value == 0) { flag=flag+1; ShowMSG("oldpassword_msg",msg_proc); _DoSetBG(e.c_oldpassword,0); }
	else if (e.c_oldpassword.value == 1) {
		if (isblank(e.c_oldpassword.value) || e.c_oldpassword.value=="") { flag=flag+1; ShowMSG("oldpassword_msg",msg_oldpwd); _DoSetBG(e.c_oldpassword,0); }
		else { resetMSG("oldpassword_msg"); _DoSetBG(e.c_oldpassword,1); pwd=1; } }
	if(pwd==1){
		   if (e.c_password.value == -1) { flag=flag+1; ShowMSG("password_msg",msg_pwd); _DoSetBG(e.password,0); }
	else if (e.c_password.value == 1) {
		if (isblank(e.password.value) || e.password.value=="") { flag=flag+1; ShowMSG("password_msg",msg_pwd); _DoSetBG(e.password,0); }
		else { resetMSG("password_msg"); _DoSetBG(e.password,1);  } }

	if (e.c_cpassword.value == -1) { flag=flag+1; ShowMSG("cpassword_msg",msg_conpwd); _DoSetBG(e.cpassword,0); }
	else if (e.c_cpassword.value == 0) { flag=flag+1; ShowMSG("cpassword_msg",msg_cpwd); _DoSetBG(e.password,0); _DoSetBG(e.cpassword,0); }
	else if (e.c_cpassword.value == 1) {
		if (isblank(e.cpassword.value) || e.cpassword.value=="") { flag=flag+1; ShowMSG("cpassword_msg",msg_conpwd); _DoSetBG(e.cpassword,0); }
		else { resetMSG("cpassword_msg"); _DoSetBG(e.cpassword,1); password=escape(e.cpassword.value); } }

		}

	if (e.c_fname.value == -1) { flag=flag+1; ShowMSG("fname_msg",msg_fname); _DoSetBG(e.fname,0); }
	else if (e.c_fname.value == 1) {
		if (isblank(e.fname.value) || e.fname.value=="") { flag=flag+1; ShowMSG("fname_msg",msg_fname); _DoSetBG(e.fname,0); }
		else { resetMSG("fname_msg"); _DoSetBG(e.fname,1); fname=escape(e.fname.value); } }

	if (e.c_lname.value == -1) { flag=flag+1; ShowMSG("lname_msg",msg_lname); _DoSetBG(e.lname,0); }
	else if (e.c_lname.value == 1) {
		if (isblank(e.lname.value) || e.lname.value=="") { flag=flag+1; ShowMSG("lname_msg",msg_lname); _DoSetBG(e.lname,0); }
		else { resetMSG("lname_msg"); _DoSetBG(e.lname,1); lname=escape(e.lname.value); } }

	if (e.c_phone.value == -1) { flag=flag+1; ShowMSG("phone_msg",msg_phone); _DoSetBG(e.phone,0); }
	else if (e.c_phone.value == 1) {
		if (isblank(e.phone.value) || e.phone.value=="") { flag=flag+1; ShowMSG("phone_msg",msg_phone); _DoSetBG(e.phone,0); }
		else { resetMSG("phone_msg"); _DoSetBG(e.phone,1); phone=escape(e.phone.value); } }

	if (e.c_address.value == -1) { flag=flag+1; ShowMSG("address_msg",msg_address); _DoSetBG(e.address,0); }
	else if (e.c_address.value == 1) {
		if (isblank(e.address.value) || e.address.value=="") { flag=flag+1; ShowMSG("address_msg",msg_address); _DoSetBG(e.address,0); }
		else { resetMSG("address_msg"); _DoSetBG(e.address,1); address=escape(e.address.value); } }

	if (e.c_city.value == -1) { flag=flag+1; ShowMSG("city_msg",msg_city); _DoSetBG(e.city,0); }
	else if (e.c_city.value == 1) {
		if (isblank(e.city.value) || e.city.value=="") { flag=flag+1; ShowMSG("city_msg",msg_city); _DoSetBG(e.city,0); }
		else { resetMSG("city_msg"); _DoSetBG(e.city,1); city=escape(e.city.value);} }

	if (e.c_state.value == -1) { flag=flag+1; ShowMSG("state_msg",msg_state); _DoSetBG(e.state,0); }
	else if (e.c_state.value == 1) {
		if (isblank(e.state.value) || e.state.value=="") { flag=flag+1; ShowMSG("state_msg",msg_state); _DoSetBG(e.state,0); }
		else { resetMSG("state_msg"); _DoSetBG(e.state,1); state=escape(e.state.value); } }
		if (e.c_zip.value == -1) { flag=flag+1; ShowMSG("zip_msg",msg_zip); _DoSetBG(e.zip,0); }
	else if (e.c_zip.value == 1) {
		if (isblank(e.zip.value) || e.zip.value=="") { flag=flag+1; ShowMSG("zip_msg",msg_zip); _DoSetBG(e.zip,0); }
		else { resetMSG("zip_msg"); _DoSetBG(e.zip,1); zip=escape(e.zip.value); } }
	if (e.enews.checked) {
	enews = 1;
	} else { enews = 0; }
	 var aphone=escape(e.aphone.value);
     var aaddress=escape(e.aaddress.value);
	for (var i=0;i<count;i++) {
		 enews_id = "enews_"+i;
		if (document.getElementById(enews_id).checked) {
			cur_count=cur_count+1;
			gameinfo= (gameinfo=="")?document.getElementById(enews_id).value:(gameinfo+","+document.getElementById(enews_id).value);
			}
		}
	if (cur_count==0) { flag=flag+1; ShowMSG("enews_msg",msg_enews); }
	else { resetMSG("enews_msg"); }
	if (flag == 0) {
		//document.getElementById("reg").innerHTML = procbar;
		 if(pwd==1){
			//questStr = "action=mpwd&fname="+fname+"&lname="+lname+"&phone="+phone+"&address="+address+"&city="+city+"&states="+state+"&country="+country+"&zip="+zip+"&enews="+enews+"&gameinfo="+gameinfo+"&password="+password;
			questStr = "action=mpwd&fname="+fname+"&lname="+lname+"&phone="+phone+"&address="+address+"&city="+city+"&states="+state+"&country="+country+"&zip="+zip+"&aphone="+aphone+"&aaddress="+aaddress+"&password="+password+"&enews="+enews+"&gameinfo="+gameinfo;
			}
		else
		{
		questStr = "action=minfo&fname="+fname+"&lname="+lname+"&phone="+phone+"&address="+address+"&city="+city+"&states="+state+"&country="+country+"&zip="+zip+"&aphone="+aphone+"&aaddress="+aaddress+"&enews="+enews+"&gameinfo="+gameinfo;
			}
		//alert(questStr);
	   	askPost("/inc/user_edit.inc.php",questStr,"editwin");

	}
	return false;
}

function _DoChangePassword(e) {
	var msg_pwd, msg_conpwd, msg_cpwd;
	var password;
	var flag=0;
	var questStr;
	         msg_pwd = "Please specify your Password.";
			 msg_conpwd = "Please Re-type your Password.";
			 msg_cpwd = "Your password entries did not match.";
	
	if (e.c_password.value == -1) { flag=flag+1; ShowMSG("password_msg",msg_pwd); _DoSetBG(e.password,0); }
	else if (e.c_password.value == 1) { 
		if (isblank(e.password.value) || e.password.value=="") { flag=flag+1; ShowMSG("password_msg",msg_pwd); _DoSetBG(e.password,0); }
		else { resetMSG("password_msg"); _DoSetBG(e.password,1);  } }
	
	if (e.c_cpassword.value == -1) { flag=flag+1; ShowMSG("cpassword_msg",msg_conpwd); _DoSetBG(e.cpassword,0); }
	else if (e.c_cpassword.value == 0) { flag=flag+1; ShowMSG("cpassword_msg",msg_cpwd); _DoSetBG(e.password,0); _DoSetBG(e.cpassword,0); }
	else if (e.c_cpassword.value == 1) { 
		if (isblank(e.cpassword.value) || e.cpassword.value=="") { flag=flag+1; ShowMSG("cpassword_msg",msg_conpwd); _DoSetBG(e.cpassword,0); }
		else { resetMSG("cpassword_msg"); _DoSetBG(e.cpassword,1); password=escape(MD5(e.cpassword.value)); } }
		
	if (flag == 0) { 
		document.getElementById("reg").innerHTML = procbar;
		questStr = "action=modify&password="+password;
	   	askPost("url",questStr,"reg");	
	
	}
	return false;
}

function _DoChangeNewsletter(e) {
	var msg_enews;
	var enews="";
	var questStr;
	
	var count = Number(e.enews_count.value);
	var enews_id;
	var cur_count=0;

	for (var i=0;i<count;i++) {
		 	enews_id = "enews_"+i;
			if (document.getElementById(enews_id).checked) { 
				cur_count=cur_count+1; 
				enews = (enews=="")?document.getElementById(enews_id).value:(enews+","+document.getElementById(enews_id).value);
			}			
		}
		
	if (cur_count == 0) { enews =0;}
	
	document.getElementById("reg").innerHTML = procbar;
	questStr = "action=modify&enews="+enews;
	askPost("url",questStr,"reg");	
	
	return false;	
}
function _DoUnsubscribe (e) {
	var msg_email;
	var email;
	var flag=0;
	var questStr;
	msg_email = "Please specify a valid e-mail address.";

	if (e.c_username.value == -1) { 
	flag=flag+1; ShowMSG("username_msg",msg_email); _DoSetBG(e.username,0); }
	else if (e.c_username.value == 1) {
		if (isblank(e.username.value) || e.username.value=="") { flag=flag+1; ShowMSG("username_msg",msg_email); _DoSetBG(e.username,0); }
		else { resetMSG("msg_error"); resetMSG("username_msg"); _DoSetBG(e.username,1); email=escape(e.username.value); }}
	if (flag == 0) {
		document.getElementById("user_unsubscribe").innerHTML = procbar;
		questStr = "action=email&email="+email;
		
		askPost("/newsletter.php",questStr,"user_unsubscribe");
	}
	return false;
}
