﻿// JavaScript Document
function countJump(strSeconds, strUrl) {
    strJump.innerText = strSeconds;
    if (--strSeconds > 0) {
        setTimeout("countJump(" + strSeconds + ",'" + strUrl + "')", 1000);
    } else {
        location.href = strUrl;
    }
}
function $(id){
	if(document.getElementById){
		return document.getElementById(id);
	}
	else if(document.all){
		return document.all[id];
	}
	else if(document.layers){
		return document.layers[id];
	}
}
function SelectAll(tempControl){
	var theBox=tempControl;
	xState=theBox.checked;
	elem=theBox.form.elements;
	for(i=0;i<elem.length;i++)
	if(elem[i].type=="checkbox"&&elem[i].id!=theBox.id){
		if(elem[i].checked==false){
			elem[i].checked=true;
			$('submitAll').disabled=false;
		}else{
			elem[i].checked=false;
			$('submitAll').disabled=true;
		}		
	}
}
function SelectBox(checkBoxID){
	if($(checkBoxID).checked==false){
		//$('submitAll').disabled=true;
	}else{
		$('submitAll').disabled=false;
	}
}
function checkSearch(){
	if ($('strkeywords').value.length<4 || $('strkeywords').value.length>100) {
		$('searchsubmit').disabled=true;
		$('strkeywords').focus();
	}
	else{
		$('searchsubmit').disabled='';
	}
}
function checkEmail(){
	if ($('emailname').value.length<4 || $('strkeywords').value.length>100) {
		$('emailsubmit').disabled=true;
		$('emailname').focus();
	}
	else{
		var filter=/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig;
		if (!filter.test($('emailname').value)){
			$('emailsubmit').disabled=true;
			$('emailname').focus();
		}else{
			$('emailsubmit').disabled='';
			}
	}
}
function checkSend(){
}

function checkForm(theform,thefunc){
var e = theform.elements;
for (var i=0,lngLeng = e.length;i<lngLeng;i++){	
	if (e[i].disabled) continue;
	if (e[i].leixing==null) continue;
	if (e[i].chulibz=='R') continue
	var theMsg = e[i].name+'Msg';
	var strValue,strMaxValue,strMinValue;
	strMinValue = 1;
	strValue=e[i].value.replace(/^\s+|\s+$/,"");
	e[i].value=strValue;
	
	if (strValue==""){
	if (e[i].allowNull==null){
	if (e[i].chulibz=='M'){
		//e[i].className='RegInput';
		_goError(e[i],thefunc,theMsg,"Please fill in the field!")
		return false
	}
	continue
	}
	if (e[i].allowNull=='Y'){
		continue
	}
	if (e[i].chulibz=='M'){
		//e[i].className='RegInput';
		_goError(e[i],thefunc,theMsg,"Please fill in the field!")
		return false
	}
	switch(e[i].leixing){
		case "NVC":
		case "VC":
		case "C":
		continue
		default:
		//e[i].className='RegInput';
		_goError(e[i],thefunc,theMsg,"Please fill in the field!")
		return false;
		}
	}
	
	if (document.all('msg'+e[i].name)!=null){
		document.all('msg'+e[i].name).innerHTML='';
	}
	
	if (e[i].value.length>e[i].maxlength&&(e[i].tagName=='TEXTAREA')){
		alert (e[i].parentElement.previousSibling.innerText+"is too long, should be less than "+e[i].maxlength);
		e[i].focus();
		return false;
	}
	
	switch(e[i].leixing){
		case 'C':
		break
		
		case 'I':{
			var filter=/^((\d+),)*(\d+)$/;
			if (!filter.test(strValue))
			{
			_goError(e[i],thefunc,theMsg,"Please enter the correct number format!")
			return false;
			}
		}
		break		
		
		case 'MAIL':{
			var filter=/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig;
			if (!filter.test(strValue))
			{
			_goError(e[i],thefunc,theMsg,"Please enter a valid e-mail address !")
			return false;
			}
		}
		break
		}
		
		if (e[i].maxLength!=null){
			strMaxValue=e[i].maxLength
			}else if(e[i].tagName=='TEXTAREA'){
				strMaxValue=3000;
				strMinValue=20
			}else{
				strMaxValue=100;
		}
		
		if (strlength(e[i].value) < strMinValue || strlength(e[i].value) > strMaxValue){
			document.getElementById(theMsg).innerHTML='<font color=red>'+e[i].parentElement.previousSibling.innerText+'Your message must be between'+strMinValue+'-'+strMaxValue+'characters!</font>';
			e[i].focus();
			return false;
		}
		document.getElementById(theMsg).innerHTML='';
		
		if(e[i].tagName=='TEXTAREA'){
		}else if(e[i].tagName=='SELECT'){
		}else{
		}
		e[i].parentElement.previousSibling.style.color='#666666'
	}	
	return true;
}

function _goError(e,thefunc,themsg,s){
	if (s!=null){
		document.getElementById(themsg).innerHTML='<font color=red>'+e.parentElement.previousSibling.innerText+s+'</font>';
	}else{
		document.getElementById(themsg).innerHTML='<font color=red>'+e.parentElement.previousSibling.innerText+'Type error!</font>';
	}
	if (thefunc!=null){
		thefunc(e)
	}else{	
		e.focus();
		return false
	}
}
function strlength(str){
	var l = str.length;
	var n = l
	for (var i=0; i<l; i++){
		if (str.charCodeAt(i)<0 || str.charCodeAt(i)>255) n++
	}
return n
}
