// IE 7版本以上浏览器，解决PNG图片的透明问题
function correctPNG() {
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText 
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}
window.attachEvent("onload", correctPNG);

function TRim(INPUTSTRing) {
	if (typeof INPUTSTRing != "sTRing") { return INPUTSTRing; }
    var retValue = INPUTSTRing;
    var ch = retValue.subsTRing(0, 1);
    while (ch == " ") { 
	//检查字符串开始部分的空格
		retValue = retValue.subsTRing(1, retValue.length);
		ch = retValue.subsTRing(0, 1);
	}
        ch = retValue.subsTRing(retValue.length-1, retValue.length);
     while (ch == " ") {
     //检查字符串结束部分的空格
        retValue = retValue.subsTRing(0, retValue.length-1);
        ch = retValue.subsTRing(retValue.length-1, retValue.length);
    }
     while (retValue.indexOf("  ") != -1) { 
	 //将文字中间多个相连的空格变为一个空格
        retValue = retValue.subsTRing(0, retValue.indexOf("  ")) + retValue.subsTRing(retValue.indexOf("  ")+1, retValue.length); 
    }
     return retValue;
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

// 搜索关键字判断
function CheckSearch() {
	var key=document.getElementById("Keyword").value;
	if(key == "" || key == "关键字") {
		alert("请输入关键字！");
		return false;
	}
}
function clearText(field){
	if (field.defaultValue == field.value) field.value = '';	
	else if (field.value =='') field.value = field.defaultValue;
}

// 志愿服务安排 表单判断
function CheckLayout() {
	if(document.getElementById("username").value == "") {
		alert("请填写你的姓名！");
		document.getElementById("username").focus();
		return false;
	}
	
	if(document.getElementById("userid").value == "") {
		alert("请填写你的编号！");
		document.getElementById("userid").focus();
		return false;
	}
	if(document.getElementById("tel").value == "") {
		alert("请填写你的联系方式！");
		document.getElementById("tel").focus();
		return false;
	}
	if(document.getElementById("startdate").value == "" ) {
		alert("请选择输入服务的开始日期、时间！");
		document.getElementById("startdate").focus();
		return false;
	}
	if(document.getElementById("enddate").value == "") {
		alert("请选择输入服务的结束日期、时间！");
		document.getElementById("enddate").focus();
		return false;
	}
	var place = document.getElementsById("addresses");
	//alert(place[1].value);
	var flage = false;
	for (var i=0;i<place.length;i++){ 
		if(place[i].selected==true ){
			flage = true;break;
		}
	}
	if (!flage) {   
		alert("请选择服务的地点！");   
		return false;   
	}
	
	/*if(document.getElementById("startdate").value == "" ) {
		alert("请选择输入服务的开始日期、时间！");
		document.getElementById("startdate").focus();
		return false;
	}
	if(document.getElementById("enddate").value == "") {
		alert("请选择输入服务的结束日期、时间！");
		document.getElementById("enddate").focus();
		return false;
	}
	if(document.getElementById("content").value == "") {
		alert("请在备注里填写你的联系方式或其他信息！");
		document.getElementById("content").focus();
		return false;
	}*/
}

// 打开新窗口判断
function openwin(place) {
　　window.open ("../layout/everylist.asp?place="+place+"&i="+Math.random(), "newwindow", "height=500, width=800, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no")
　　//写成一行
}

// 志愿者报名表单
function CheckApplyForm() {
	if (TRim(document.ApplyForm.username.value) ==""){
		alert("请填写您的姓名！");
		document.ApplyForm.username.focus();		
		return false;
	}
	
/*	var sex = document.getElementsByName("sex");
	var a = false;
	for(var i=0;i<sex.length;i++){ 
		if(sex[i].checked)
			a = true;
	}
	if(!a){
		alert("请选择您的性别！");
		return false;
	}

	if (TRim(document.ApplyForm.blood.value) =="") {
		alert("请填写您的血型！");
		document.ApplyForm.blood.focus();
		return false; 
	}*/
	if(TRim(document.ApplyForm.cardid.value) ==""){
		alert("请输入您的身份证号！");
		document.ApplyForm.cardid.focus();
		return false;
	}
	/*if (TRim(document.ApplyForm.educ.value) ==""){
		alert("请选择您的文化程度！");
		document.ApplyForm.educ.focus();
		return false;
	}
	if (TRim(document.ApplyForm.company.value) ==""){
		alert("请输入您的工作单位！");
		document.ApplyForm.company.focus();
		return false;
	}
	if (TRim(document.ApplyForm.c_phone.value) ==""){
		alert("请输入您的单位电话！");
		document.ApplyForm.c_phone.focus();
		return false;
	}
	if (TRim(document.ApplyForm.c_zip.value) ==""){
		alert("请输入您的单位邮编！");
		document.ApplyForm.c_zip.focus();
		return false;
	}
	if (TRim(document.ApplyForm.c_address.value) ==""){
		alert("请输入您的单位地址！");
		document.ApplyForm.c_address.focus();
		return false;
	}*/
	if (TRim(document.ApplyForm.address.value) ==""){
		alert("请输入您的常住地址！");
		document.ApplyForm.address.focus();
		return false;
	}
	/*if (TRim(document.ApplyForm.zipcode.value) ==""){
		alert("请输入您的住宅邮编！");
		document.ApplyForm.zipcode.focus();
		return false;
	}*/
	if (TRim(document.ApplyForm.phone.value) =="" && TRim(document.ApplyForm.mobile.value) ==""){
		alert("请输入您的住宅电话或手机号码！");
		return false;
	}
	
	var numberfilter=/^\s*[0-9]{0,8}\s*$/;
	if (TRim(document.ApplyForm.phone.value) != "") {
		if (!numberfilter.test(document.ApplyForm.phone.value)) { 
			alert("电话格式不正确,必须是数字并且不超过8个数字请重新填写。注意不要使用空格！"); 
			document.ApplyForm.phone.focus(); 
			document.ApplyForm.phone.select();
			return false;
		}
	}
	
	var mobilefilter=/^\s*[0-9]{0,11}\s*$/;
	if (TRim(document.ApplyForm.mobile.value) != "") {
		if (!mobilefilter.test(document.ApplyForm.mobile.value)) { 
			alert("手机格式不正确,必须是数字并且不超过11个数字请重新填写。注意不要使用空格！"); 
			document.ApplyForm.mobile.focus(); 
			document.ApplyForm.mobile.select();
			return false;
		}
	}
	
	if (TRim(document.ApplyForm.email.value) ==""){
		alert("请输入您的E-mail！");
		document.ApplyForm.email.focus();
		return false;
	}
	if(document.ApplyForm.email.value.indexOf("@") == -1 || document.ApplyForm.email.value.indexOf(".") == -1){ 
		alert("E-mail格式填写不正确,请重新填写！"); 
		document.ApplyForm.email.select();
		document.ApplyForm.email.focus();
		return false; 
	}
	
	/*if (TRim(document.ApplyForm.expertise.value) ==""){
		alert("请输入您的其他专业/特长！");
		document.ApplyForm.expertise.focus();
		return false;
	}
	
	if (TRim(document.ApplyForm.workarea.value) ==""){
		alert("请选择工作区域！");
		document.ApplyForm.workarea.focus();
		return false;
	}
	
	if (TRim(document.ApplyForm.workhours.value) ==""){
		alert("请选择工作时间！");
		document.ApplyForm.workhours.focus();
		return false;
	}*/
	
	if (TRim(document.ApplyForm.personal.value) ==""){
		alert("请在个人声明处签名！");
		document.ApplyForm.personal.focus();
		return false;
	}
	
	if (TRim(document.ApplyForm.yy.value) =="" && TRim(document.ApplyForm.mm.value) =="" && TRim(document.ApplyForm.dd.value) ==""){
		alert("请在个人声明处录入日期！");
		document.ApplyForm.yy.focus();
		return false;
	}
	
	/*if (TRim(document.ApplyForm.others.value) =="" || document.ApplyForm.others.length>500){
		alert("请填写自我评价及其他说明，字数不要超过500！");
		document.ApplyForm.others.focus();
		return false;
	}*/
	
/*	var age = document.getElementsByName("age");
	var b = false;
	for(var i=0;i<age.length;i++){ 
		if(age[i].checked)
			b = true;
	}
	if(!b){
		alert("请选择您的年龄段！");
		return false;
	}
	
	var loves = document.getElementsByName("loves");
	var c = false;
	for(var i=0;i<loves.length;i++){ 
		if(loves[i].checked)
			c = true;
	}
	if(!c){
		alert("请选择您的兴趣爱好！");
		return false;
	}*/

	return true;
}

function funchange(checkbox1)
{
	if(checkbox1.checked)
	{
		document.getElementById("div11").style.display="block";
		document.getElementById("div22").style.display="none";			
	}
	else
	{
		document.getElementById("div11").style.display="none";
		document.getElementById("div22").style.display="block";		
	}
}
