
/*************************************************

Validator v1.0

cody by Future Software

http://www.future-software.com.cn

*************************************************/

function trim(w) {
  while (w.length>0 && (w.substr(0,1)==' ' || w.substr(0,1)=='?')) w=w.substr(1);
  while (w.length>0 && (w.substr(w.length-1)==' ' || w.substr(w.length-1)=='?')) w=w.substr(0,w.length-1);
  return(w);
}


function keypresscheck(msgtxt,textname,max)
{
	
	if(textname.length>max)
	{	
		alert(msgtxt+max);
		return false;
	}else{		
		return true;
	}
}
var checkflag="false";
function checkform()
{	
	var value = document.mainform.id;
	if(checkflag=="false")
	{
		for(i=0;i<value.length;i++)
		{
			value[i].checked = true;
		}
		checkflag="true";
	}
	else 
	{
		for(i=0;i<value.length;i++) 
		{
		    value[i].checked = false;
		}
		checkflag="false";
	} 
}


function resetCheckBox()
{	
	var value = document.mainform.id;
	for(i=0;i<value.length;i++)
	{
		if(value[i].checked == true)
		{
		  value[i].checked = false;
		}
	}
}

function deleteEntry()
{	
	var value = document.getElementsByName("id");
	for(i=0;i<value.length;i++)
	{
		if(value[i].checked == true)
		{
			return true;				
		}
	}
	return false;
}


function submitDelete(alertmsg1,delUrl,alertmsg2)
{
	if(deleteEntry())
	{
		if(confirm(alertmsg1))
		{
			setAction(delUrl);
		}
	}
	else
	{
		alert(alertmsg2) ;
	}
}


function setAction(actionName){
	document.mainform.action=actionName;
	document.mainform.submit();
}

function checkdatetonow(msg){	
	if(document.mainform.birthday.value >= document.mainform.now.value)	{
		alert(msg);
		document.mainform.birthday.focus();
		return false;
	}else{
		return true;
	}	
}


function checkdate(msg){	
	if(document.mainform.startdt.value > document.mainform.stopdt.value)	{
		alert(msg);
		document.mainform.startdt.focus();
		return false;
	}else{
		return true;
	}	
}
function checkdate1(msg){	
	if(document.mainform.endtime.value != ""){
		if(document.mainform.starttime.value > document.mainform.endtime.value)	{
			alert(msg);
			document.mainform.starttime.focus();
			return false;
		}else{
			return true;
		}
	}	
	else{
		return true;
	}
}
function showsubmenu(dis)
{
	whichEl = dis;
	if (whichEl.style.display == "none")
	{
		whichEl.style.display="";
	}
	else
	{
		whichEl.style.display="none";
	}
}


function KeyDown(pagecount,msgnum,msgcount){
	var moveto = document.getElementById("pageCurrent").value;
	if(moveto>pagecount){
			alert(msgcount);
		}
	if(moveto.length>8){
		alert(msgnum);
		document.getElementById("pageCurrent").value="";
	}
	if (isNaN(moveto))
		{
			alert(msgnum);
			document.getElementById("pageCurrent").focus();
			return false;
		}else{
				for(var i=0;i<moveto.length;i++){
					oneNum=moveto.substring(i,i+1);
					if (oneNum<"0" || oneNum>"9" && oneNum!="."){
					alert(msgnum);
					return false;}
				}
		}
		document.mainform.submit();
}


function KeyDown1(pagecount,msgnum,msgcount){
	var moveto = document.getElementById("pageCurrent").value;
	if(moveto>pagecount){
		alert(msgcount);
		return false;
	}
	if(moveto.length>8){
		alert(msgnum);
		document.getElementById("pageCurrent").value="";
	}
	if (isNaN(moveto)){
		alert(msgnum);
		document.getElementById("pageCurrent").focus();
		return false;
	}else{
		for(var i=0;i<moveto.length;i++){
			oneNum=moveto.substring(i,i+1);
			if (oneNum<"0" || oneNum>"9" && oneNum!="."){
				alert(msgnum);
				return false;
			}
		}
	}
	document.mainform.submit();
}




function KeyDownJump(pagecount,msgnum,msgcount,jumpurl){
	var moveto = document.getElementById("pageCurrent").value;	
	if(moveto == 0){
			jumpurl = jumpurl +"&pageCurrent=1";
		}
	if(moveto > pagecount){
			alert(msgcount);
			jumpurl = jumpurl +"&pageCurrent="+pagecount;
		}
	if(moveto.length>8){
		alert(msgnum);
		document.getElementById("pageCurrent").value="";
		return false;
	}
	if (isNaN(moveto))
		{
			alert(msgnum);
			document.getElementById("pageCurrent").focus();
			return false;
		}else{
				for(var i=0;i<moveto.length;i++){
						oneNum=moveto.substring(i,i+1);
						if (oneNum<"0" || oneNum>"9" && oneNum!="."){
							alert(msgnum);
							return false;}
					}
			}
		document.mainform.action=jumpurl;
		document.mainform.submit();
 }

function onsearchsubmit(actionUrl){
	if(actionUrl.lastIndexOf("pageCurrent") > -1){
		var temppageno = actionUrl.substring(actionUrl.lastIndexOf("=")+1,actionUrl.length);
		document.getElementById("pageCurrent").value=temppageno;
	}	
	document.mainform.action=actionUrl;
	document.mainform.method = "post";
	document.mainform.submit();
}


function checkNull(inputvalue,msg){
	if(inputvalue.value == "" || inputvalue.value == null)
	{
		alert(msg);
		inputvalue.focus();
		return false;
	}
    return true;	
}


function isspecial(thestring,specstr,msg)
{
	var re=true;
	for(i=0;i<specstr.length;i++)
	{
		if(thestring.indexOf(specstr.charAt(i))!=-1)
		{
			alert(msg);
			re = false;
			break;		
		}
	}
	return re;
}

function isNumber(str) {
	var regexp=/^(\d+)$.^(\d+)$/;
	return regexp.test(str);
} 

function  moveRoleOption(oFromList, oToList, bAll, roleid)  
{  
	var  nFromLen = oFromList.options.length;  
	var  nToLen = oToList.options.length;  
	var  i = 0;
	if(roleid != 1)
	{  
		while(nFromLen > 0)  
		{  
			if(oFromList.options[i].selected || bAll)  
			{        	
				oToList[nToLen++]  =  new  Option(oFromList.options[i].text,  oFromList.options[i].value);
				oFromList.options[i]  =  null; 
			}  
			else  
				i++;
				  
		  nFromLen--;  
		}   
	}
	else
	{  	
		while(nFromLen > 0)  
		{
			if(oFromList.options[i].selected && oFromList.options[i].value != 1 || bAll && oFromList.options[i].value != 1)  
			{
				oToList[nToLen++]  =  new  Option(oFromList.options[i].text,  oFromList.options[i].value);
				oFromList.options[i]  =  null; 			
			}  
			else  
				i++;  
	                	    
			nFromLen--;  
		}   	  
	}
	sortOption(oToList);  
}

  
function  moveOption(oFromList,  oToList,  bAll)  
{  
   var  nFromLen  =  oFromList.options.length;  
   var  nToLen  =  oToList.options.length;  
   var  i  =  0;  
   while  (nFromLen > 0)  
   {  
   		if  (oFromList.options[i].selected || bAll)  
        {        	
        	oToList[nToLen++]  =  new  Option(oFromList.options[i].text,  oFromList.options[i].value);
        	oFromList.options[i]  =  null; 
        }  
        else  
        	i++;  
                	    
        nFromLen--;  
   }  
 
   sortOption(oToList);  
}

function  sortOption(oList)  
{  
     if  (oList.options.length  >  1)  
     {
     	var  optionList    =  new  Array();  
 
        for  (var  i=0;  i  <  oList.options.length;  i++)  
        	optionList.push(oList.options[i]);  
 
        optionList.sort(compare);  
 
        oList.length  =  0;
          
        for  (var  i=0;  i  <  optionList.length;  i++)  
        	oList.options[i]  =  optionList[i];  
     }        
}
  
 
function  compare(a,b)  
{  
   if  (a.text  <  b.text)  
   		return  -1;  
   else  if  (a.text  >  b.text)  
   		return  1;  
   return  0;  
}  

 function getdeptLvalue() {
 	
 	var getList=document.all.departmentidR.options;
 	for(i=0;i<getList.length;i++){
 		getList(i).selected = true;  			
	 } 
 }
 

function listcolumnDelAct(msg)
{
	if(confirm(msg))
	{ 
  		window.parent.self.left.location='ccmbam/column/forColTree.html';
	}
	else
	{
 		return false;
	}
}

function deleteCFM(msg)
{
	if(confirm(msg))
	{ 
  		window.parent.self.left.location='ccmbam/xxgk/catalog/forCatalogTree.html';
	}
	else
	{
 		return false;
	}
}

function listcolumnmodifyAct(colid,columninfoid)
{
	document.mainform.action="./ColumninfoAction.do?dispatch=getColumninfoDetail&colid="+colid+"&columninfoid="+columninfoid;
	document.mainform.submit(); 
} 


function listcolumnSubmitDel(msg1,msg2)
{
	if(deleteEntry())
	{
		if(confirm(msg1))
		{
			window.parent.self.left.location='./ColumninfoAction.do?dispatch=treeCol';
			setAction('./ColumninfoAction.do?dispatch=delColumninfo');
			window.parent.self.left.location='ccmbam/column/forColTree.html';		
		}
	}
	else
	{
		alert(msg2) ;
	}
}



function getRoleLvalue() {
 	
 	var getList=document.all.roleidR.options;
 	for(i=0;i<getList.length;i++)
 	{
 		getList(i).selected = true;  			
	 } 
 }


function listflowtaskSubmitDel(msg1,msg2,flowdefineid)
{
	if(deleteEntry())
	{
		if(confirm(msg1))
		{
			setAction('./FlowtaskAction.do?dispatch=delFlowtask&flowdefineid='+flowdefineid);
			window.parent.self.left.location='ccmbam/flowtask/forFlowtaskTree.jsp?dispatch=flowtaskList&flowdefineid='+flowdefineid;		
		}
	}
	else
	{
		alert(msg2) ;
	}
}         


function listflowtaskDelAct(msg,flowdefineid)
{
	if(confirm(msg))
	{ 
  		window.parent.self.left.location='ccmbam/flowtask/forFlowtaskTree.jsp?dispatch=flowtaskList&flowdefineid='+flowdefineid;
	}
	else
	{
 		return false;
	}
}

function issuedisplayDate(stValue,dis1,dis2)
{
	if(stValue == 3)
	{ 
		dis1.style.display='';
		dis2.style.display='';
	}
	else
	{
		dis1.style.display='none';
		dis2.style.display='none';
	}
}


function contentListmodifyAction(contentid,columninfoid)
{
	document.mainform.action="./ContentAction.do?dispatch=getContentDetail&contentid="+contentid+"&columninfoid="+columninfoid;
	document.mainform.submit();
}

function getCmsuserRvalue() {
 	
 	var getList=document.all.cmsuseridR.options;
 	for(i=0;i<getList.length;i++){
 		getList(i).selected = true;  			
	 } 
 }

function checkWebsitelinkInput(snmsg, msg){
	if(document.mainform.capacity.value == ""){
		alert("站点容量不能为空！")
		return false;
	}
	var sitename = document.mainform.sitename.value;
	if (trim(sitename) == ""){
		alert(snmsg);
		return false;
	}

	if (document.mainform.filedir.value != ""){
		var collinkvalue = document.mainform.filedir.value;
		var pathvalue = collinkvalue.substring(0,7);
		pathvalue = pathvalue.toLowerCase();
		if (pathvalue != "http://"){
			alert(msg);
			document.mainform.filedir.focus();
			return false;
		}
	}
	return true;
}

function checkColumncollinkInput(msg){

  if (document.mainform.collink.value != "")
	{
		var collinkvalue = document.mainform.collink.value;
		var pathvalue = collinkvalue.substring(0,7);
		pathvalue = pathvalue.toLowerCase();
		if (pathvalue != "http://")
		{
			alert(msg);
			document.mainform.collink.focus();
			return false;
		}
	}
	return true;
}

function addContentcheckAllInput(msg){

  if (document.mainform.linkpath.value != "")
	{
		var linkpathvalue = document.mainform.linkpath.value;
		var pathvalue = linkpathvalue.substring(0,7);
		pathvalue = pathvalue.toLowerCase();
		if (pathvalue != "http://")
		{
			alert(msg);
			document.mainform.linkpath.focus();
			return false;
		}
	}	
	document.mainform.contentbody.value = eWebEditor1.getHTML();
	return true;
}



function addContentcheckAllInputTP(msg){

  if (document.mainform.linkpath.value != "")
	{
		var linkpathvalue = document.mainform.linkpath.value;
		var pathvalue = linkpathvalue.substring(0,7);
		pathvalue = pathvalue.toLowerCase();
		if (pathvalue != "http://")
		{
			alert(msg);
			document.mainform.linkpath.focus();
			return false;
		}
	}	
	document.mainform.searchkey.value = eWebEditor2.getHTML();
	document.mainform.contentbody.value = eWebEditor1.getHTML();
	return true;
}

function gourl(url){
	    
	if(url==0)
	{
		return false;
	}
	javascript:window.open(url);     
}

Validator = {

Require : /[^\s*]/,

Email : /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/,

Phone : /^(^(\d{2,4}[-_－—]?)?\d{3,8}([-_－—]?\d{3,8})?([-_－—]?\d{1,7})?$)|(^0?1[35]\d{9}$)$/,

//Phone : /^\d+$/,

Mobile : /^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/,

Url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,

IdCard : /^\d{15}(\d{2}[A-Za-z0-9])?$/,

Currency : /^\d+(\.\d+)?$/,

Number : /^\d+$/,

Zip : /^[1-9]\d{5}$/,

QQ : /^[1-9]\d{4,8}$/,

Integer : /^[-\+]?\d+$/,

Double : /^[-\+]?\d+(\.\d+)?$/,

English : /^[A-Za-z]+$/,

Chinese : /^[\u0391-\uFFE5]+$/,

UnSafe : /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,

IsSafe : function(str){return !this.UnSafe.test(str);},

SafeString : "this.IsSafe(value)",

Limit : "this.limit(value.length,getAttribute('min'), getAttribute('max'))",

LimitB : "this.limit(this.LenB(value), getAttribute('min'), getAttribute('max'))",

Date : "this.IsDate(value, getAttribute('min'), getAttribute('format'))",

Repeat : "value == document.getElementsByName(getAttribute('to'))[0].value",

Range : "getAttribute('min') < value && value < getAttribute('max')",

Compare : "this.compare(value,getAttribute('operator'),getAttribute('to'))",

Custom : "this.Exec(value, getAttribute('regexp'))",

Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",

ErrorItem : [document.forms[0]],

ErrorMessage : ["Error:The following reason causes to submit failure\t\t\t\t"],

Validate : function(theForm, mode){

var obj = theForm || event.srcElement;

var count = obj.elements.length;

this.ErrorMessage.length = 1;

this.ErrorItem.length = 1;

this.ErrorItem[0] = obj;

for(var i=0;i<count;i++){

with(obj.elements[i]){

var _dataType = getAttribute("dataType");

if(typeof(_dataType) == "object" || typeof(this[_dataType]) == "undefined") 
continue;

this.ClearState(obj.elements[i]);

if(getAttribute("require") == "false" && value == 
"") continue;

switch(_dataType){

case "Date" :

case "Repeat" :

case "Range" :

case "Compare" :

case "Custom" :

case "Group" : 

case "Limit" :

case "LimitB" :

case "SafeString" :

if(!eval(this[_dataType])) {

this.AddError(i, getAttribute("msg"));

}

break;

default :

if(!this[_dataType].test(value)){

this.AddError(i, getAttribute("msg"));

}

break;

}

}

}

if(this.ErrorMessage.length > 1){

mode = mode || 1;

var errCount = this.ErrorItem.length;

switch(mode){

case 2 :

for(var i=1;i<errCount;i++)

this.ErrorItem[i].style.color = "red";

case 1 :

alert(this.ErrorMessage.join("\n"));

this.ErrorItem[1].focus();

break;

case 3 :

for(var i=1;i<errCount;i++){

try{

var span = document.createElement("SPAN");

span.id = "__ErrorMessagePanel";

span.style.color = "red";

this.ErrorItem[i].parentNode.appendChild(span);

span.innerHTML = this.ErrorMessage[i].replace(/\d+:/,"*");

}

catch(e){alert(e.description);}

}

this.ErrorItem[1].focus();

break;

default :

alert(this.ErrorMessage.join("\n"));

break;

}

return false;

}

return true;

},

limit : function(len,min, max){

min = min || 0;

max = max || Number.MAX_VALUE;

return min <= len && len <= max;

},

LenB : function(str){

return str.replace(/[^\x00-\xff]/g,"**").length;

},

ClearState : function(elem){

with(elem){

if(style.color == "red")

style.color = "";

var lastNode = parentNode.childNodes[parentNode.childNodes.length-1];

if(lastNode.id == "__ErrorMessagePanel")

parentNode.removeChild(lastNode);

}

},

AddError : function(index, str){

this.ErrorItem[this.ErrorItem.length] = this.ErrorItem[0].elements[index];

this.ErrorMessage[this.ErrorMessage.length] = this.ErrorMessage.length + ":" 
+ str;

},

Exec : function(op, reg){

return new RegExp(reg,"g").test(op);

},

compare : function(op1,operator,op2){

switch (operator) {

case "NotEqual":

return (op1 != op2);

case "GreaterThan":

return (op1 > op2);

case "GreaterThanEqual":

return (op1 >= op2);

case "LessThan":

return (op1 < op2);

case "LessThanEqual":

return (op1 <= op2);

default:

return (op1 == op2); 

}

},

MustChecked : function(name, min, max){

var groups = document.getElementsByName(name);

var hasChecked = 0;

min = min || 1;

max = max || groups.length;

for(var i=groups.length-1;i>=0;i--)

if(groups[i].checked) hasChecked++;

return min <= hasChecked && hasChecked <= max;

},

IsDate : function(op, formatString){

formatString = formatString || "ymd";

var m, year, month, day;

switch(formatString){

case "ymd" :

m = op.match(new RegExp("^\\s*((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})\\s*$"));

if(m == null ) return false;

day = m[6];

month = m[5]--;

year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));

break;

case "dmy" :

m = op.match(new RegExp("^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$"));

if(m == null ) return false;

day = m[1];

month = m[3]--;

year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));

break;

default :

break;

}

var date = new Date(year, month, day);

return (typeof(date) == "object" && year == date.getFullYear() 
&& month == date.getMonth() && day == date.getDate());

function GetFullYear(y){return ((y<30 ? "20" : "19") + 
y)|0;}

}

}
function openWindow(url)
	{
		window.open(url,"displayWindow","scrollbars=yes,width=518,height=300")						
	} 
