function init() {
    var brand = document.getElementById('brand');
	var model = document.getElementById('model');
	//brand.options[0] = new Option('手机品牌','');
	//model.options[0] = new Option('手机型号','');
	var i = 0;
	for (k in brand_array)
	{
	    brand.options[i] = new Option(brand_array[k],k);
		i++;
	}
	show_model('Nokia');
}
function show_model(v) {
    if (v == '') return;
    var model = document.getElementById('model');
	var tmp = model_array[v];
	if (tmp.length <= 0) return;
    del_option(model);
	var last = '';
	for(i = 0; i < tmp.length; i++) {
		if (i == 0)
		{
			last = tmp[i];
		}
	    var text = tmp[i].split('||');
	    model.options[i] = new Option(text[0],tmp[i]);    
	}
	is_java(last);
}
function get_downurl() {
    var brand = document.getElementById('brand');
	var model = document.getElementById('model');
	var str = model.value;
	if (str == '') return '';
	tmp = str.split('||');
	location.href = tmp[1];
}

function is_java(v) {
    var val = v.split('||');
	var tip_java = document.getElementById('tip_java');
	var tip_symbiam = document.getElementById('tip_symbiam');
	if (typeof(tip_java) == 'undefined' || typeof(tip_symbiam) == 'undefined') return;
	if (val[2] == '1'){
		tip_java.style.display = 'none';
		tip_symbiam.style.display = '';
	}else{
	    tip_symbiam.style.display = 'none';
		tip_java.style.display = '';
	 }
}
function del_option(obj) {
	var IsCreate = false;
	obj.selectedIndex = obj[0];
    while  (IsCreate  ==  false) {
		SecIndex = obj.selectedIndex; 
		if (SecIndex < 0) return false;
		theLength  =  obj.length; 
		obj.remove(SecIndex); 
		if  (theLength  ==  1)  
			return  false;                                          
		if  (theLength  ==  SecIndex  +  1)                  
			return  false;  
		if  (obj.options[SecIndex].selected  ==  false)  {  
			IsCreate  =  true;  
		}  
	}  
}

function checkimg() {
	//alert(document.getElementById('checkimg').src);
    document.getElementById('checkimg').src = '/checknumber.php?'+Math.random();
}
function sms_send() {
	var form = document.form1;
	if (form.brand.value == '') {
	    alert('请选择手机品牌');
		return false;
	}
	if (form.model.value == '')
	{
		alert('请选择手机型号');
		return false;
	}
	if (form.mobile.value == '')
	{
		alert('请填写手机号');
		return false;
	}
	var pattern = /^[1][0-9]{10}$/;
	if (!pattern.test(form.mobile.value))
	{
		alert('手机号格式不正确');
		return false;
	}
	if (form.checknumber.value == '')
	{
		alert('请填写验证码');
		return false;
	}
    disabled('button',true);
    var pars = "cmd=sms_send&brand="+form.brand.value;
	pars += "&model="+form.model.value;
	pars += "&mobile="+form.mobile.value;
	pars += "&checknumber="+form.checknumber.value;
	pars += "&"+Math.random();
	var a=new Ajax.Request(
    	"/operation/sms.php",
    		 {method: 'get', parameters: pars, onSuccess: function(xmlRequest) {
	         var ret = trim(xmlRequest.responseText);
			 if (ret == '1') {
				 alert('短信发送成功');
				 disabled('button',false);
				 checkimg();
			 }else{
			     alert(ret);
				 disabled('button',false);
				 checkimg();
			 }
		}}
	);
}



function display(id,val) {
    $(id).style.display = val;
}

function disabled(id,val) {
    $(id).disabled = val;
}
function setvalue(id,val) {
    $(id).value = val;
}

function trim(s){
 	return rtrim(ltrim(s)); 
}
function ltrim(s){
 	return s.replace(/^\s*/, ""); 
} 
function rtrim(s){ 
 	return s.replace(/\s*$/, ""); 
}