﻿String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, '');
}

function winOpen(url, w, h, n) {
    return window.open(url, (typeof n == 'undefined' ? '' : n), 'height=' + h + ',width=' + w + ',left=' + (window.screen.width - w) / 2 + ',top=' + (window.screen.height - h) / 2 + ',resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,status=no');
}
function xmlhttpCreate() {
    if (window.XMLHttpRequest) return new XMLHttpRequest();
    try { return new ActiveXObject('MSXML2.XMLHTTP.4.0'); } catch (e) { try { return new ActiveXObject('MSXML2.XMLHTTP.3.0'); } catch (e) { try { return new ActiveXObject('MSXML2.XMLHTTP.2.6'); } catch (e) { try { return new ActiveXObject('MSXML2.XMLHTTP'); } catch (e) { try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) { return null; } } } } }
}

function xmlhttpPost(url, callback, content) {
    var xhp = xmlhttpCreate();
    if (xhp == null) return;
    xhp.onreadystatechange = function(e) { if (xhp.readyState != 4 || xhp.status != 200) return; if (typeof callback == 'function') callback(xhp.responseText); xhp.abort(); }
    xhp.open("POST", url, true);
    xhp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    if (content) xhp.send(content);
    else xhp.send('');
}
function xmlhttpPost1(url, callback, content) {
    var xhp = xmlhttpCreate();
    if (xhp == null) return;
    //判断是否是firefox，ff中onreadystatechange,readyState 不支持
    if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
        xhp.onload = function(e) { if (xhp.readyState != 4 || xhp.status != 200) return; if (typeof callback == 'function') callback(xhp.responseText); xhp.abort(); }
        xhp.open("POST", url, false);
        xhp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        if (content) xhp.send(content);
        else xhp.send('');
    } else {
        xhp.onreadystatechange = function(e) { if (xhp.readyState != 4 || xhp.status != 200) return; if (typeof callback == 'function') callback(xhp.responseText); xhp.abort(); }
        xhp.open("POST", url, false);
        xhp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        if (content) xhp.send(content);
        else xhp.send('');
    }


}
//***********************
var fgoldgamegandserver;



function getservers(f) {

	 f.server.options.length = 0;
    if (f.game.value != '') {
        f.server.options.add(new Option('Loading....'));
    } else {
        f.server.options.add(new Option('Choose'));
        return;
    }
    xmlhttpPost('/common/ajax.html?serverlist', function(q) {

        if (q == "") {
            return;
        } else {
            f.server.options.length = 0;
            var s = q.split('@@');
            for (var i = 0; i < s.length; i++) {
                var ss = s[i].split('@');
                if (ss.length != 2) continue;
                var ser = new Option(ss[1], ss[0]);
                f.server.options.add(ser);
            }
        }
    
    }, 'game=' + escape(f.game.value));}


function priceGet(sltserver, sltproduct, sltcurrency) {
	if (!fgoldgamegandserver) fgoldgamegandserver = sltserver.form;
	if(!sltserver.form.price){priceGetSpecials(sltserver, sltproduct, sltcurrency);return;}
	sltserver.form.price.value = '';
	if (sltserver.value == '' || sltproduct.value == '' || sltcurrency.value == '') return;
	
	xmlhttpPost('/common/ajax.html?gold.product.price', function(r) {
		if (r == '') return;
		sltserver.form.price.value = r;	
	
    }, 'server=' + escape(sltserver.value) + '&product=' + sltproduct.value + '&currency=' + escape(sltcurrency.value));
	if (typeof productShow == 'function') productShow(sltserver.value, sltcurrency.value);
 
}

function clearcb()
{
 
      var cs = document.getElementsByName('Notforsale');
    for(var i=0;i<cs.length;i++)
    {
       if(cs[i].checked)
       {
        cs[i].checked="";
       }
    }
    var c=0;
	getitem(this,c);
}



function productGet(sltgame, sltproduct) {

	if (!fgoldgamegandserver) fgoldgamegandserver = sltgame.form;
	while (sltproduct.options.length > 0) sltproduct.remove(0);
	if (sltgame.value != '') sltproduct.options.add(new Option('Loading...'));
	else { sltproduct.options.add(new Option('Choose')); return; }
	xmlhttpPost('/common/ajax.html?gold.productlist', function(r) {
		sltproduct.remove(0);
		if (r == '') return; var ss = r.split('\r\n');
		for (var i = 0; i < ss.length; i++) {
			var s = ss[i].split('\t'); if (s.length != 2) continue;
			sltproduct.options.add(new Option(s[1], s[0]));
}
var pro = document.getElementById("gproduct");

if (pro && pro.value != null && pro.value != "") {
    sltproduct.value = pro.value;
    if (sltproduct.value == "" || sltproduct.value == null) {
        window.history.back();
    }
}
		var f = sltgame.form;
		priceGet(f.server, f.product, f.currency);
	}, 'game=' + escape(sltgame.value));
}



function stockGet(sltserver) {
	var dvstock = document.getElementById('dvStock'); if (!dvstock) return;
	var dtr = null;
	try { if (dvstock.parentNode.parentNode.tagName == 'TR') dtr = dvstock.parentNode.parentNode; }
	catch (e) { }
	dvstock.style.display = 'none'; if (dtr != null) dtr.style.display = 'none';
	if (sltserver.value == '') return;
	xmlhttpPost('/common/ajax.html?gold.stock', function(r) {
		if (r == '') return;
		var fr = r.split('\t'); if (fr.length != 2) return;
		dvstock.innerHTML = 'Yesterday we have sent <b style="color:blue;">' + fr[0] + '</b> Gold/Million out on this server.<br/>Currently we have <b style="color:red;">' + fr[1] + '</b> Gold/Million on this server you choose.'
		dvstock.style.display = '';
		if (dtr != null) dtr.style.display = '';
	}, 'server=' + escape(sltserver.value));
}


//Change the game
function changeGame(f) {
    if (f.server) getServer(f);
    if (f.product) getProduct(f);

}
//Changing currency
function changeCurrency(f) {
    if (f.price) getPrice(f.server, f.product, f.currency);
}
//Change server
function changeServer(f) {
    if (f.price) getPrice(f.server, f.product, f.currency);
}
//Change product
function changeProduct(f) {
    if (f.price) getPrice(f.server, f.product, f.currency);
}

//Obtain products
function getProduct(f) {

    f.product.options.length = 0; f.price.value = ''; //Empty price
    if (f.game.value != '') {
        f.product.options.add(new Option('Loading....'));
    } else {
        f.product.options.add(new Option('Choose'));
        return;
    }
    xmlhttpPost('/common/ajax.html?productlist', function(q) {
        if (q == "") { return; }
        var s = q.split('@@');
        f.product.options.length = 0;
        for (var i = 0; i < s.length; i++) {
            var ss = s[i].split('@');
            if (ss.length != 2) continue;
            var pro = new Option(ss[1], ss[0]);
            f.product.options.add(pro);
        }

        //Acquisition of products at the same time obtain all price
        getPriceList(f.server, f.product.options, f.currency, false);

        f.product.remove(s.length - 1);
        if (f.price) getPrice(f.server, f.product, f.currency);

    }, 'game=' + f.game.value);
}

//Access server
function getServer(f) {
    f.server.options.length = 0;
    if (f.game.value != '') {
        f.server.options.add(new Option('Loading....'));
    } else {
        f.server.options.add(new Option('Choose'));
        return;
    }
    xmlhttpPost('/common/ajax.html?serverlist', function(q) {
        if (q == "") {
            return;
        } else {
            f.server.options.length = 0;
            var s = q.split('@@');
            for (var i = 0; i < s.length; i++) {
                var ss = s[i].split('@');
                if (ss.length != 2) continue;
                var ser = new Option(ss[1], ss[0]);
                f.server.options.add(ser);
            }
        }
        if (f.product) getProduct(f);
    }, 'game=' + escape(f.game.value));

}

function serverGet(sltgame, sltserver, sltcode, callback) {

    if (!fgoldgamegandserver) fgoldgamegandserver = sltgame.form;
    if(sltserver){ while (sltserver.options.length > 0) sltserver.remove(0);}
    if (sltgame.value != '') sltserver.options.add(new Option('Loading...'));
    else { sltserver.options.add(new Option('Choose')); stockGet(sltserver); return; }
    xmlhttpPost('/common/ajax.html?sys.game.serverlist', function(r) {
        sltserver.remove(0);
        if (r == '') return; var ss = r.split('\r\n');
        for (var i = 0; i < ss.length; i++) {
            var s = ss[i].split('\t'); if (s.length != 2) continue;
            var o = new Option(s[1], s[0]); if (typeof sltcode != 'undefined' && sltcode == s[0]) o.selected = true;
            sltserver.options.add(o);
        }
        var f = sltgame.form;
        if (callback != null && typeof callback == 'function') callback(f);
        if (f.price) priceGet(f.server, f.product, f.currency);
    }, 'game=' + escape(sltgame.value));
}
//The left gold list displays
function GetProductList() {
    var f = document.getElementById("fgold");
    var proList = document.getElementById("productList");
    proList.innerHTML = "";
    var list = f.product.options;
    for (var i = 0; i < list.length; i++) {
        var str = list[i].text;
        var index = str.indexOf("/");
        var name = str.substring(0, index);
        var price = str.substring(index + 1);

        var html = "<li id='" + i + "' onclick='colorChange(this.id)' onmouseover=\"javascript:this.backgroundColor='#FCFEB7'\" onmouseout=\"javascript:this.backgroundColor=''\">";
        if (name.length > 11)
            html += '<div class=\"gold_box_G\" style="font-size:11px;"> ' + name + ' </div>';
        else
            html += '<div class=\"gold_box_G\"> ' + name + ' </div>';
        html += "<p class=\"red\">" + price + "</p>";
        html += "</li>";
        proList.innerHTML += html;
    }

}
//Style switching
function colorChange(id) {
    var proList = document.getElementById("productList");
    var nodes = proList.childNodes;
    for (var i = 0; i < nodes.length; i++) {
        var node = nodes[i];
        if (id == node.id) {
            node.style.cssText = "background-color:#fcfeb7";
            var price = node.getElementsByTagName("p")[0].innerHTML;
            document.getElementById("fgold").price.value = price;
        }
        else {
            node.style.cssText = "";
        }
    }
    //Change the drop-down box price, text unit price
    document.getElementById("fgold").product.selectedIndex = id;
}
//Acquisition price
function getPrice(fserver, fproduct, fcurrency) {
    if (fserver.value == '' && fproduct.value == '' && fcurrency.value == '') {
        return;
    }
    xmlhttpPost('/common/ajax.html?price', function(q) {
        fserver.form.price.value = q;
    }, 'server=' + escape(fserver.value) + '&product=' + escape(fproduct.value) + '&currency=' + escape(fcurrency.value));

    //Set the left gold list which selected
    colorChange(fproduct.selectedIndex);
}

//Acquisition price list
function getPriceList(fserver, proList, fcurrency, isChange) {
    if (fserver.value == '' && proList == '' && fcurrency.value == '') {
        return;
    }
    var pro = fserver.form.product;
    var priceArray = new Array();
    for (var i = 0; i < proList.length; i++) {
        xmlhttpPost1('/common/ajax.html?price', function(q) {
            priceArray[i] = q;
        }, 'server=' + escape(fserver.value) + '&product=' + escape(proList[i].value) + '&currency=' + escape(fcurrency.value));
        if (i + 1 == proList.length) {
            callback(proList, priceArray, isChange, pro);
        }
    }
    GetProductList(); //Product list on the left
}
//Modify product callback functions
function callback(proList, priceArray, isChange, pro) {
    for (var i = 0; i < proList.length; i++) {
        if (!isChange) {
            pro.options[i].text = pro.options[i].text + " / " + priceArray[i];
        }
        else {
            var str = pro.options[i].text;
            var index = str.indexOf("/");
            var name = str.substring(0, index);
            pro.options[i].text = name.trim() + " / " + priceArray[i];
        }
    }
}

//Obtain game list
function getGame(f) {
    f.game.length = 0;
    f.price.value = '';
    if (f.game.value == '') {
        f.game.options.add(new Option('Please Choose Game', ''));
    }
    xmlhttpPost('/common/ajax.html?gamelist', function(q) {

        if (q == '') { return; }
        var s = q.split('@@');
        for (var i = 0; i < s.length; i++) {
            var ss = s[i].split('@');
            if (ss.length != 2) continue;
            var pro = new Option(ss[1], ss[0]);
            f.game.options.add(pro);
        }
    }, null);
    // getCurrency(f); //Meanwhile loading monetary
}

//Obtain currency
function getCurrency(f) {
    xmlhttpPost('/common/ajax.html?currencylist', function(q) {
        if (q == '') { return; }
        f.currency.remove(0);
        var s = q.split('@');
        for (var i = 0; i < s.length; i++) {
            var pro = new Option(s[i], s[i]);
            f.currency.options.add(pro);

        }
        f.currency.remove(s.length - 1);
        f.currency.value = "USD";
    }, null);

}


//end
function goldQuickFormCheck(f) {
    if (!f.game.value) { alert("Please Select Game"); document.getElementById("divGame").style.color = 'red'; return false; }
    if (!f.server.value) { alert("Please Select Server"); return false; }
    if (!f.product.value) { alert("Please Select Product"); return false; }
    return true;
}
function goldFormCheck(f, pop) {
    fimsgShow(f.fullname, null); fimsgShow(f.rolename, null); fimsgShow(f.email, null); fimsgShow(f.phone, null);
    if (f.game && f.game.value == '') { alert('Please select server.'); return false; }
    if (f.server && (f.server.value == '' || f.server.value == 'Loading....')) { alert('Please select server.'); return false; }
    if (f.product && f.product.value == '') { alert('Please select product.'); return false; }
    if (f.price && f.price.value == '') { alert('Please try again later.'); return false; }
    if (f.fullname && f.fullname.value.trim() == '') { if (pop) fimsgShow(f.fullname, 'Please input your full name.'); else alert('Please input your full name.'); f.fullname.focus(); return false; }
    if (f.rolename && f.rolename.value.trim() == '') { if (pop) fimsgShow(f.rolename, 'Please input your character name .'); else alert('Please input your character name.'); f.rolename.focus(); return false; }
    if (f.email && f.email.value.trim() == '') { if (pop) fimsgShow(f.email, 'Please input your email.'); else alert('Please input your email.'); f.email.focus(); return false; }
    else if (f.email && f.email.value.trim() != '' && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(f.email.value)) { if (pop) fimsgShow(f.email, 'Your email is error.'); else alert('Your email is error.'); f.email.value = ''; f.email.focus(); return false; }
    if (f.phone && f.phone.value.trim() == '') { if (pop) fimsgShow(f.phone, 'Please input your phone number.'); else alert('Please input your phone number.'); f.phone.focus(); return false; }
    if (f.server && f.server.selectedIndex == 0) { if (!confirm("Are you sure your server is   " + f.server.options[0].text + ', please?')) { return false; } }
    //if (!(f.phone || f.email || f.character || f.fullname)) { f.game.disabled = f.price.disabled = true; }
    return true;
}
function plFormCheck(f) {
    fimsgShow(f.fullname, null); fimsgShow(f.email, null); fimsgShow(f.phone, null); fimsgShow(f.account, null); fimsgShow(f.password, null); fimsgShow(f.password1, null); fimsgShow(f.rolename, null); fimsgShow(f.classname, null); fimsgShow(f.gameserver, null);
    if (f.fullname && f.fullname.value.trim() == '') { fimsgShow(f.fullname, 'Please input your full name.'); f.fullname.focus(); return false; }
    if (f.email && f.email.value.trim() == '') { fimsgShow(f.email, 'Please input your email.'); f.email.focus(); return false; }
    else if (f.email.value.trim() != '' && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(f.email.value)) { fimsgShow(f.email, 'Your email is error.'); f.email.value = ''; f.email.focus(); return false; }
    if (f.phone && f.phone.value.trim() == '') { fimsgShow(f.phone, 'Please input your phone number.'); f.phone.focus(); return false; }
    if (f.account && f.account.value.trim() == '') { fimsgShow(f.account, 'Please input your game account.'); f.account.focus(); return false; }
    if (f.password && f.password.value.trim() == '') { fimsgShow(f.password, 'Please input your game password.'); f.password.focus(); return false; }
    if (f.password1 && f.password1.value != f.password.value) { fimsgShow(f.password1, 'Your password is error.'); f.password1.focus(); return false; }
    if (f.rolename && f.rolename.value.trim() == '') { fimsgShow(f.rolename, 'Please input your character name.'); f.rolename.focus(); return false; }
    if (f.classname && f.classname.value.trim() == '') { fimsgShow(f.classname, 'Please input your character class.'); f.classname.focus(); return false; }
    if (f.gameserver && f.gameserver.value.trim() == '') { fimsgShow(f.gameserver, 'Please input your game server.'); f.gameserver.focus(); return false; }
    return true;
}
function accountbuyFormCheck(f) {
    fimsgShow(f.fullname, null); fimsgShow(f.email, null); fimsgShow(f.phone, null);
    if (f.fullname && f.fullname.value.trim() == '') { fimsgShow(f.fullname, 'Please input your full name.'); f.fullname.focus(); return false; }
    if (f.email && f.email.value.trim() == '') { fimsgShow(f.email, 'Please input your email.'); f.email.focus(); return false; }
    else if (f.email.value.trim() != '' && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(f.email.value)) { fimsgShow(f.email, 'Your email is error.'); f.email.value = ''; f.email.focus(); return false; }
    if (f.phone && f.phone.value.trim() == '') { fimsgShow(f.phone, 'Please input your phone number.'); f.phone.focus(); return false; }
    return true;
}
function stuffbuyFormCheck(f) {
    fimsgShow(f.fullname, null); fimsgShow(f.email, null); fimsgShow(f.phone, null);
    if (f.fullname && f.fullname.value.trim() == '') { fimsgShow(f.fullname, 'Please input your full name.'); f.fullname.focus(); return false; }
    if (f.email && f.email.value.trim() == '') { fimsgShow(f.email, 'Please input your email.'); f.email.focus(); return false; }
    else if (f.email.value.trim() != '' && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(f.email.value)) { fimsgShow(f.email, 'Your email is error.'); f.email.value = ''; f.email.focus(); return false; }
    if (f.rolename && f.rolename.value.trim() == '') { fimsgShow(f.rolename, 'Please input your character name.'); f.rolename.focus(); return false; }
    if (f.phone && f.phone.value.trim() == '') { fimsgShow(f.phone, 'Please input your phone number.'); f.phone.focus(); return false; }
    if (f.game && f.game.value == '') { alert('Please select game.'); f.game.focus(); return false; }
    if (f.server && f.server.value == '') { alert('Please select server.'); f.server.focus(); return false; }

    return true;
}
function accountsellFormCheck(f) {
    fimsgShow(f.fullname, null); fimsgShow(f.email, null); fimsgShow(f.phone, null); fimsgShow(f.server, null); fimsgShow(f.level, null); fimsgShow(f.gclass, null); fimsgShow(f.faction, null); fimsgShow(f.gender, null); fimsgShow(f.race, null); fimsgShow(f.link, null);
    if (f.fullname && f.fullname.value.trim() == '') { fimsgShow(f.fullname, 'Please input your full name.'); f.fullname.focus(); return false; }
    if (f.email && f.email.value.trim() == '') { fimsgShow(f.email, 'Please input your email.'); f.email.focus(); return false; }
    else if (f.email.value.trim() != '' && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(f.email.value)) { fimsgShow(f.email, 'Your email is error.'); f.email.value = ''; f.email.focus(); return false; }
    if (f.phone && f.phone.value.trim() == '') { fimsgShow(f.phone, 'Please input your phone number.'); f.phone.focus(); return false; }
    if (f.server && f.server.value.trim() == '') { fimsgShow(f.server, 'Please select your server.'); f.server.focus(); return false; }
    if (f.level && f.level.value.trim() == '') { fimsgShow(f.level, 'Please input your game level.'); f.level.focus(); return false; }
    else if (f.level.value.trim() != '' && !/^[1-9]\d*$/g.test(f.level.value)) { fimsgShow(f.level, 'Your enter error.'); f.level.value = ''; f.level.focus(); return false; }
    if (f.gclass && f.gclass.value.trim() == '') { fimsgShow(f.gclass, 'Please select your game class.'); f.gclass.focus(); return false; }
    if (f.faction && f.faction.value.trim() == '') { fimsgShow(f.faction, 'Please select your game faction.'); f.faction.focus(); return false; }
    if (f.gender && f.gender.value.trim() == '') { fimsgShow(f.gender, 'Please select your game gender.'); f.gender.focus(); return false; }
    if (f.race && f.race.value.trim() == '') { fimsgShow(f.race, 'Please select your game race.'); f.race.focus(); return false; }
    if (f.link && f.link.value.trim() == '') { fimsgShow(f.link, 'Please enter your CTmods or armory link .'); f.link.focus(); return false; }
    return true;
}
function contactFormCheck(f)
{
    //if (f.fullname && f.fullname.value.trim() == '') { fimsgShowSimple(f.fullname, '*',true); f.fullname.focus(); return false; }else fimsgShowSimple(f.fullname, '*',false);
    if (f.email && f.email.value.trim() == '') { fimsgShowSimple(f.email, '*',true); f.email.focus(); return false; }
    else if (f.email.value.trim() != '' && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(f.email.value)){ fimsgShowSimple(f.email, '*',true); f.email.focus(); return false; }
    else fimsgShowSimple(f.email, '*',false);
    //if (f.phone && f.phone.value.trim() == '') { fimsgShowSimple(f.phone, '*',true); f.phone.focus(); return false; }else fimsgShowSimple(f.phone, '*',false);
    //if (f.character && f.character.value.trim() == '') { fimsgShowSimple(f.character, '*',true); f.character.focus(); return false; }else fimsgShowSimple(f.character, '*',false);
    return true;
}
function fimsgShowSimple(ele, msg,isnull) {
	if (!ele) return;
	var inputid = ele.getAttribute('name') == '' ? ele.getAttribute('id') : ele.getAttribute('name');
	var divMsg = document.getElementById(inputid + '__$msg$');
	if (divMsg) divMsg.parentNode.removeChild(divMsg);
	if (msg == null) return;
	divMsg = document.createElement('SPAN');
	divMsg.setAttribute('id', inputid + '__$msg$');
	if(isnull)divMsg.innerHTML = '<span style="color:red;">*</span>';
	else divMsg.innerHTML = '';
	ele.parentNode.insertBefore(divMsg, ele.nextSibling);
}
function couponCheck(ipt, gc) {
    fimsgShow(ipt, null);
    if (!gc) gc = ipt.form.game.value;
    if (ipt.value == '') return;
    if (gc == null) {
        if (ipt.form.game && ipt.form.game.value == '') { alert('Please select game before.'); ipt.form.game.focus(); return; }
        else { gc = ipt.form.game.value; }
    }
    xmlhttpPost('/common/ajax.html?gold.coupon.check', function(r) {
        if (r == '' || r == 'err') fimsgShow(ipt, "This discount code is invalid!");
        else fimsgShow1(ipt, r);
    }
	, 'gc=' + escape(gc) + '&c=' + escape(ipt.value));
}

function plcouponCheck(ipt, gc) {
    fimsgShow(ipt, null);
    if (ipt.value == '') return;
    if (gc == null) {
        if (ipt.form.game && ipt.form.game.value == '') { alert('Please select game before.'); ipt.form.game.focus(); return; }
        else { gc = ipt.form.game.value; }
    }
    xmlhttpPost('/common/ajax.html?pl.coupon.check', function(r) {
        if (r == '' || r == 'err') fimsgShow(ipt, "This discount code is invalid!");
        else fimsgShow1(ipt, r);
    }
	, 'gc=' + escape(gc) + '&c=' + escape(ipt.value));
}


function checkmsgpage(fm) {
     fimsgShow(fm.msgerror, null);
    if (fm.fullname && fm.fullname.value == "")
    { fimsgShow(fm.msgerror, 'Please input your name'); fm.fullname.focus(); return false; }
    if (fm.email && fm.email.value == "")
    { fimsgShow(fm.msgerror, 'Please input your email'); fm.email.focus(); return false; 
    }else if (fm.email.value.trim() != '' && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(fm.email.value)) 
    { fimsgShow(fm.msgerror, 'Your email is error.'); fm.email.value = ''; fm.email.focus(); return false; }
    if (fm.phone && fm.phone.value == "")
    { fimsgShow(fm.msgerror, 'Please input your phone number'); fm.phone.focus(); return false; }
    if (fm.content && fm.content.value == "")
    { fimsgShow(fm.msgerror, 'Please input your content'); fm.content.focus(); return false; }
    else if (fm.content.value.length > 4000)
    { fimsgShow(fm.msgerror, 'your content less than 4000 Character'); fm.content.focus(); return false; }
    fm.submit();
    return true;
}


function fimsgShow(ele, msg) {
    if (!ele) return;
    var inputid = ele.getAttribute('name') == '' ? ele.getAttribute('id') : ele.getAttribute('name');
    var divMsg = document.getElementById(inputid + '__$msg$');
    if (divMsg) divMsg.parentNode.removeChild(divMsg);
    if (msg == null) return;
    divMsg = document.createElement('SPAN');
    divMsg.setAttribute('id', inputid + '__$msg$');
    divMsg.setAttribute('style', 'display:inline-block;');
    divMsg.innerHTML = '<span style="background-color:#FFFF00;margin-left:4px; border:1px solid #FF2200; padding:1px 2px 1px 2px; color:#FF0000; z-index:10000;">' + msg + '</span>';
    ele.parentNode.insertBefore(divMsg, ele.nextSibling);
}
function fimsgShow1(ele, msg) {
    if (!ele) return;
    var inputid = ele.getAttribute('name') == '' ? ele.getAttribute('id') : ele.getAttribute('name');
    var divMsg = document.getElementById(inputid + '__$msg$');
    if (divMsg) divMsg.parentNode.removeChild(divMsg);
    if (msg == null) return;
    divMsg = document.createElement('SPAN');
    divMsg.setAttribute('id', inputid + '__$msg$');
    divMsg.setAttribute('style', 'display:inline-block;');
    divMsg.innerHTML = '<span style="margin-left:4px; padding:1px 2px 1px 2px; color:green; z-index:10000;">' + msg + '</span>';
    ele.parentNode.insertBefore(divMsg, ele.nextSibling);
}
function priceChange2(fid, c, price) {
    var f = document.getElementById(fid);
    if (f && f.currency) { f.currency.value = c; }
    xmlhttpPost('/common/ajax.html?cart.currency2', function(r) {
        if (r != null) { document.getElementById("p").value = r; }
    }, 'currency=' + escape(c) + '&price=' + escape(price) + '&formid=' + escape(fid));
}

function siblingPrevious(ele) {
	if (ele == null || typeof ele.previousSibling == 'undefined') return null;
	while (ele.previousSibling != null && ele.previousSibling.nodeType != 1) ele = ele.previousSibling;
	return ele.previousSibling;
}

function itemsbuyFormCheck(f) {
    fimsgShow(f.fullname, null); fimsgShow(f.rolename, null); fimsgShow(f.email, null); fimsgShow(f.phone, null);
    if (f.fullname && f.fullname.value.trim() == '') { fimsgShow(f.fullname, 'Please input your full name.'); f.fullname.focus(); return false; }
    if (f.rolename && f.rolename.value.trim() == '') { fimsgShow(f.rolename, 'Please input your character name.'); f.rolename.focus(); return false; }
    if (f.email && f.email.value.trim() == '') { fimsgShow(f.email, 'Please input your email .'); f.email.focus(); return false; }
    else if (f.email.value.trim() != '' && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(f.email.value)) { fimsgShow(f.email, 'Your email is error.'); f.email.value = ''; f.email.focus(); return false; }
    if (f.phone && f.phone.value.trim() == '') { fimsgShow(f.phone, 'Please input your phone number. '); f.phone.focus(); return false; }

    return true;
}


    //ff
function getitem(t,c)
    {
      var f = document.getElementById('fgoldbuy'); 
      var productext= f.product.options[f.product.selectedIndex].text;
      var cs = document.getElementsByName('Notforsale');
      var productcount = productext.match(RegExp(/\d+/));
      if(productcount<5000){c=0}
      if(productcount>=50000 && productcount<=100000){c=1;}
      if(productcount>100000){ c=2; }
      var j = 0;
      var k = 0;
	  for(var i=0;i<cs.length;i++){if (cs[i].checked) { j++;k = 1;} }
	  for(var i=0;i<cs.length;i++)
	  {
                if(c==0)
                {
                    cs[i].disabled=true;
                }
                else {
                    
		                if(t.checked)
		                {
		                    if (!cs[i].checked && c == j) cs[i].disabled = true;
        		            
		                }
		                else
		                {
		                    cs[i].disabled = false;
		                  
		                }
		        }
		    }
		    //start
		    var price = document.getElementById("price");
		    if (productcount >= 50000 && productcount < 100000) {
		        if (k != 1) {
		            if (price.value.indexOf("+") != -1) {
		                price.value = price.value.split("+")[0];
		            }
		        }

		        else {
		            price.value = price.value + "+$10";
		        } 
		     }
		//end


}


		  



