﻿//parameter info
// chkName = the name of the chekboxes list without 1,2,3,... numbers
// frmName = html form name 
// chkTotal = no of checkboxes to look for
function checkAll( chkName , frmName , chkTotal )
{
	var frm = document.forms[frmName];
	var i = 0;
	for (i=0 ; i<=chkTotal ; i++)
	{
		var o = frm.elements[chkName + i.toString()];
		if (o) o.checked = true;
	}
	return false;
}

function clearAll( chkName , frmName , chkTotal )
{
	var frm = document.forms[frmName];
	var i = 0;
	for (i=0 ; i<=chkTotal ; i++)
	{
		var o = frm.elements[chkName + i.toString()];
		if (o) o.checked = false;
	}
	return false;
	
}

//additional err_msg + same parameters list as the above functions checkAll and clearAll 
//err_msg will be displayed if not checkbox is not selected
function is_checked(chkName , frmName , chkTotal, err_msg)
{
	var frm = document.forms[frmName];
	var i = 0;
	for (i=1 ; i<=chkTotal ; i++)
	{
		var o = frm.elements[chkName + i.toString()];
		if(o && o.checked)
			return true;
	}
	alert(err_msg); 
	return false;
}

function get_cookie(Name) 
{
	var Name = Name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(Name) == 0) return unescape(c.substring(Name.length,c.length));
	}
	return "";
}

function open_window(url, width, height)
{
	var sw = window.open(url,"subWnd","Toolbar=1,menubar=0,scrollbars=1,resizable=1,width="+width+",height="+height+",top=100,left=200");
	if (!sw)
	{
		alert("Popup Blocker Detected!\n\nPlease disable your popup blocker software or allow popups on this page.");
	}
	else
	{
		sw.focus();
	}
	return false;
}
function open_window_full(url, width, height)
{
	var sw = window.open(url,"subWnd","Toolbar=0,menubar=0,scrollbars=0,resizable=1,width="+width+",height="+height+",top=0,left=0");
	if (!sw)
	{
		alert("Popup Blocker Detected!\n\nPlease disable your popup blocker software or allow popups on this page.");
	}
	else
	{
		sw.focus();
	}
	return false;
}

//Dont change window name 'subWnd', its being used on some other pages
function open_window_scroll(url, width, height)
{
	var sw = window.open(url,"subWnd","Toolbar=1,menubar=0,scrollbars=1,resizable=1,width="+width+",height="+height+",top=75,left=150");
	if (!sw)
	{
		alert("Popup Blocker Detected!\n\nPlease disable your popup blocker software or allow popups on this page.");
	}
	else
	{
		sw.focus();
	}
	return false;
}

function TextArea_Keypress( txtName , spnName )
{
	if (document.getElementById(txtName).value.length >= parseInt(document.getElementById(txtName).attributes['MaxChars'].value))
		return false;
}

function TextArea_Keyup( txtName , spnName )
{
	if (document.getElementById(txtName).value.length >= parseInt(document.getElementById(txtName).attributes['MaxChars'].value))
	{
		document.getElementById(txtName).value = document.getElementById(txtName).value.substr(0, parseInt(document.getElementById(txtName).attributes['MaxChars'].value)-1);
	}
	//document.getElementById(spnName).innerHTML = (parseInt(document.getElementById(txtName).attributes['MaxChars'].value)-parseInt(document.getElementById(txtName).value.length));
	document.getElementById(spnName).innerHTML = (parseInt(document.getElementById(txtName).value.length));
}

function trim(str)
{
	str = str.replace(/^\s*|\s*$/g,"");
	return str;
}

function loadwin(url)
{
	var left, top;
	var width = screen.width;
	// Resize the screen depending on the users display
	if(screen.width >= 1280 && screen.height >= 1024)
	{
		wdh = 850;
		hgt = 750;
	}
	else if(screen.width > 1024 && screen.height > 768)
	{
		wdh = 850;
		hgt = 700;
	}
	else if(screen.width >= 800 && screen.height >= 600)
	{
		wdh = 850;
		hgt = 640;
	}
	// Open the window in the middle of the screen
	left = (screen.availWidth - wdh) / 2
	top = (screen.availHeight - hgt) / 2 - 10;
	success = open(url, '', 'width=' + wdh + ',height=' + hgt + ',left=' + left + ',top=' + top + ',scrollbars=yes,resizable=yes,status=no');
}

function set_login_required_cookie(value)
{
	var exp = new Date( );
	var expiry = exp.getTime( ) + (60 * 60 * 1000);
	exp.setTime(expiry);
	document.cookie = "c_login_required="+ value +"; expires=" + exp.toGMTString() + ";path=/";
}



function get_validate_keyword(str1, str2, str3, charlimit)
{
var newword1="", newword2="", newword3="";

	if(str1!="")
	{
		cstr = str1.split(",");			
		for(i=0; i<cstr.length; i++)
		{ 	
			newword1 = cstr[i];			
			if(newword1.length > charlimit)
			{				
				newword1 =  newword1 + "~" + "1";				
				return newword1;
			}						
		}
	}
		
	if(str2!="")
	{		
		cstr = str2.split(",");		
		for(i=0; i<cstr.length; i++)
		{	
			newword2 = cstr[i];		
			if(newword2.length > charlimit)
			{
				newword2 =  newword2 + "~" + "2";	
				return newword2;
			} 		
		}
	}			
	
	if(str3!="")
	{		
		cstr2 = str3.split(",");		
		for(i=0; i<cstr2.length; i++)
		{	
			newword3 = cstr2[i];						
			if(newword3.length > charlimit)
			{						
				newword3 =  newword3 + "~" + "3";	
				return newword3;
			} 		
		}
	}
	
	newword2 = "true~0";
	return newword2;		
}

function highlight_table(element, color)
{
	//document.getElementById(element).bgColor = color;
	document.getElementById(element).style.backgroundColor = color;
}


function DBC2SBC(str)
{
var result = '';
for (i=0 ; i<str.length; i++)
{
   code = str.charCodeAt(i);
   if (code >= 65281 && code <= 65373)
   {
    result += String.fromCharCode(str.charCodeAt(i) - 65248);
   }else if (code == 12288)
   {
    result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
   }else
   {
    result += str.charAt(i);
   }
}
return result;
}

function nocn(thisname){
	document.getElementsByName(thisname)[0].value = DBC2SBC(document.getElementsByName(thisname)[0].value);

	for(i=0;i<document.getElementsByName(thisname)[0].value.length;i++){
		var c = document.getElementsByName(thisname)[0].value.substr(i,1);
		var ts = escape(c);
		if(ts.substring(0,2) == "%u"){
			alert("这里不能输入中文/全角字符,比如：“”《》：,请检查！");
			document.getElementsByName(thisname)[0].focus();
			return false;
		}
	}

}