// JavaScript Document
/*检验EMAIL地址*/
function isEmail(email)
{
	var patrn= /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if (!patrn.exec(email)) return false;
	return true;
}
function isUserName(str)
{
	var patrn=/^[a-zA-Z0-9_-]{2,}$/;
	if (!patrn.exec(str)) return false
	return true
}
//判断字符串是否为空
function isNull(s)
{
	if (s+"123" == "123")
	{
		return true;
	}
	return false;
}
//幼儿园.亲子园.提交搜索
function submitSearch(type)
{
	if ( typeof type == 'undefined' )
	{
		return false;	
	}
	var typeVal = $(type).value;

	if ( typeVal == 0 )
	{
		if ( type == 'yey')
		alert('请选择幼儿园!');
		else if( type == 'qzy')
		alert('请选择亲子园!');
		return false;
	}
	window.location.href = 'index.php?channel=' + typeVal;
}

function getChannelListFromProvince(type)
{
	if ( typeof type == 'undefined' )
	{
		return false;	
	}
	var typeArr = document.getElementsByName('radioType');
	for ( var t=0; t<typeArr.length; t++ )
	{
		if ( typeArr[t].checked )
		{
			type = typeArr[t].value;
		}
	}

	var province = $('province').value;

	if ( type == 'yey' )
	{
		$('province').disabled = true;
		province = '';
	}
	else
	{
		$('province').disabled = false;
	}
//	if ( province == '' )
//	{
//		return false;	
//	}
	var ajax = new ajaxObj();
	var postStr = "type=" + type + "&province=" + province + "&n=" + Math.random();

	var url = AJAX_DOMAIN + 'search.php';
	ajax.open("POST", url, true);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send(postStr);

	ajax.onreadystatechange = function()
	{
		if (ajax.readyState == 4 && ajax.status == 200)
		{

			var result = ajax.responseText;
			var option = $(type);
			option.length = 1;
			if ( result != '' )
			{
				var res = splitStr(result,'<+>');
				for ( var i=0; i < res.length; i++ )
				{
					var arr   = splitStr(res[i],'<->');
					
						var opt   = new Option();
						opt.value = arr[0];
						opt.text  = arr[1];
						option.options.add(opt);
				}
			}

		}
	}

}

function splitStr(str,m)
{
	return str.split(m);
}

function getType(name)
{
	var arr = document.getElementsByName(name);
	for ( var i=0; i<arr.length; i++ )
	{
		if ( arr[i].checked == true )
		{
			return 	arr[i].value;
		}
	}
}
function setTypeText(type)
{
	if ( typeof type == 'undefined' )
	{
		return false;	
	}
	if ( type == 'yey' )
	var typeName = '幼儿园';
	else if ( type == 'qzy' )
	var typeName = '亲子园';

	if ( $("style") )
	var style = $("style").value;
	else
	var style = "";

	 html = '<select name="'+type+'" id="'+type+'" style="'+ style +'">';
     html += '<option value="0">--'+typeName+'--</option>';
	 html += '</select>';
	$('typeAdd').innerHTML = html;
	getChannelListFromProvince(type);
}
