function notIn(val,obj)
{
	var obj_size = obj.length;
	for(i = 0; i < obj_size; i++)
	{
		if(obj[i].value == 0 || obj[i].value == val)return false;
	}
	return true;
}

function addTo(theList,theSelect)
{
	var size1 = theList.length;
	var i = 0;
	i = theList.selectedIndex;
	if (i < 0) return false;

	if(notIn(theList[i].value,theSelect))
	{
		if(theList[i].value == 0)
		{
			theSelect.length = 1;
			theSelect[theSelect.length - 1].text = theList[i].text;
			theSelect[theSelect.length - 1].value = theList[i].value;
		}
		else
		{
			var size = theSelect.length;
			if (theSelect.length >= 3)
			{
				alert("......3...");
				return false;
			}
			theSelect.length = size + 1;
			theSelect[theSelect.length - 1].text=theList[i].text;
			theSelect[theSelect.length - 1].value=theList[i].value;
		}
        return true;
	}
	/*
	else
	{
		alert("......");
		return false;
	}*/
	return false;
}

function addToWithSubmit(theList,theSelect)
{
	var success = addTo(theList,theSelect);
	if (success == false) return false;

	var selectName = theSelect.name;
	var selectIndex = theList.selectedIndex;
	var itemNames = document.getElementsByName(selectName + "Names");
	var itemValues = document.getElementsByName(selectName + "Values");

	var i;
	// because addto is success, the length of theSelect is bigger than 0
	if(theSelect[0].value == 0)
	{
		itemNames[0].value = theList[selectIndex].value;
		itemValues[0].value = theList[selectIndex].text;
		// clear the other values
		for (i = 1; i < 3; i++)
		{
			itemNames[i].value = "";
			itemValues[i].value = "";
		}
	}
	else
	{
		// adjust the position of hidden value
		for (i = 0; i < 3; i++)
		{
			if (itemNames[i].value == "") break;
		}
		itemNames[i].value = theList[selectIndex].value;
		itemValues[i].value = theList[selectIndex].text;
	}
}

function moveWithSubmit(theSelect)
{
	theListId = theSelect.selectedIndex;
	var selectName = theSelect.name;
	remove(theSelect);

	if (theListId >= 0) {
		var itemNames = document.getElementsByName(selectName + "Names");
		var itemValues = document.getElementsByName(selectName + "Values");

		var i;
		for (i = theListId + 1; i < 3; i++)
		{
			itemNames[i - 1].value = itemNames[i].value;
			itemValues[i - 1].value = itemValues[i].value;
		}
		itemNames[i - 1].value = "";
		itemValues[i - 1].value = "";
	}
}

function remove(theSelect)
{
	var theListId = theSelect.selectedIndex;
	if (theListId < 0) return;

	if(theListId >= 0)
	{
		theSelect.remove(theListId);
	}

	if (theListId < theSelect.length)
	{
		theSelect.selectedIndex = theListId;
	}
	else
	if (theSelect.length > 0)
	{
		theSelect.selectedIndex = theSelect.length - 1;
	}
}


function changeSubSelect(theParent,theSub,theData)
{
	var theSelectedIndex = theParent.selectedIndex;
	var staff = theData[theSelectedIndex];
	
	len = staff.length / 2;
	theSub.length = len;
	for (var i = 0; i < len; i++)
	{
		theSub.options[i] = new Option(staff[2 * i],staff[2 * i + 1]);
	}
	theSub.selectedIndex = 0;
}

function selectValue(theObj,theSelectValue)
{
    var len = theObj.length;
    if (len == 0) return;

	for (var i = 0; i < len; i++)
	{
		if (theObj.options[i].value == theSelectValue)
       {
           theObj.selectedIndex = i;
           return;
       }
	}
}

function selectSingle(theObj)
{
	if (theObj.checked == false) return;
	var name = theObj.name;
	var itemNames = document.getElementsByName(name);
	var len = itemNames.length;
	for (var i = 0; i < len; i++)
	{
		if (itemNames != itemNames[i])
		{
			itemNames[i].checked = false;
		}
	}
	theObj.checked = true;
}

function popup(sUrl,sName,sFeatures)
{
	window.open(sUrl,sName,sFeatures);
}

function changeSearchList(sUrl,radioButton,labelName,changeList)
{
	var label = document.getElementById(labelName);
	//var labels = document.getElementsByName(labelName);
	//var label = labels[0];
	if (radioButton.value == 'ARTICLE')
	{
		label.innerHTML = ".....";
	}
	else
	{
		label.innerHTML = ".....";
	}	
	//alert('changeList='+changeList);

    document.getElementById("sub").src =
        sUrl + "catType=" + radioButton.value + "&listName=" + changeList ;
}


/*
 * Create Date:2004-06-01
 * Author: Jeff.Zhou
 * Reload the sublist data.
 */
function updateList(changeList,values)
{	
	
    var list = document.getElementById(changeList);
	
	var len = list.length;
	
    for (var i = 1; i < len; i++)
    {
        list.remove(1);
    }

    nLen = values.length/2;
    for (var i = 0; i < nLen; i++)
    {
        list.options[i+1] = new Option(values[2*i+1],values[2*i]);
    }
    list.selectedIndex = 0;
}
/*
 *Author Wulf.wu
 *check the selected checkbox list
*/
function hint(sform,obj)
{
    var sel = false;
    if(obj)
    {
        if(obj.length > 1)
        {
            for(var i=0; i<obj.length; i++)
            {
                if(obj[i].checked)
                {
                    sel = true;
                    break;
                }
            }
            if(sel)
            {
                if(confirm("......."))
                    sform.submit();
            }
            else
                alert("........!");
        }
        else
        {
            if(obj.checked)
            {
                if(confirm("......."))
                    sform.submit();
            }
            else
                alert("........!");
        }
    }
    else
        alert("........!");
}


function checkForm(theForm){

	var str = Trim(theForm.keyword.value);

	if(str==""){

		alert("......");

		theForm.keyword.focus();

		return false;

	}

	return true;

}	

function LTrim(str)

{

    var whitespace = new String(" \t\n\r");

    var s = new String(str);

    if (whitespace.indexOf(s.charAt(0)) != -1)

    {

        var j=0, i = s.length;

        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)

        {

            j++;

        }

        s = s.substring(j, i);

    }

    return s;

}



function RTrim(str)

{

    var whitespace = new String(" \t\n\r");

    var s = new String(str);

    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)

    {

        var i = s.length - 1;

        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)

        {

            i--;

        }

        s = s.substring(0, i+1);

    }

    return s;

}



function Trim(str)

{

    return RTrim(LTrim(str));

}
		
function setSearch(searchType)
{
 	
 	if (searchType == "ART") {
	
	simpleForm.action = "/quickSearchAction.do?action=Search";
	document.all.searchhref.href   = "/articleAdvSearch.do";
	}else
	{
	simpleForm.action="http://forum.dev.ceconline.com/search.jspa";
	
	document.all.searchhref.href   = "http://forum.dev.ceconline.com/search!default.jspa";
	}

}

		
function beforeSearch()
{
 	
	
	simpleForm.q.value=simpleForm.keyword.value;
	

}


function onRecom(){

	with (recommendForm){

    if (recommend.value=="" && file.value=="")

                {

                alert('............');

                recommend.focus();

                return false;

                }

  }

}





//----------Banner part JS
/*
 * Create Date:2004-06-01
 * Author: Jeff.Zhou
 * pop-up a confirm window before delete a row
 */
function confirmDelete(obj) {
    var msg = "Are you sure you want to delete " + obj + "?";
	ans = confirm(msg);
	if (ans) {
        return true;
	} else {
        return false;
    }
}

/*
 * Create Date:2004-06-01
 * Author: Jeff.Zhou
 * Check all the checkbox in a form
 */
function checkAll(theForm) { // check all the checkboxes in the list
  for (var i=0;i<theForm.elements.length;i++) {
    var e = theForm.elements[i];
		var eName = e.name;
    	if (eName != 'allbox' &&
            (e.type.indexOf("checkbox") == 0)) {
        	e.checked = theForm.allbox.checked;
		}
	}
}

/*
 * Create Date:2004-06-01
 * Author: Jeff.Zhou
 * Request sublist data.
 */
function changeList(sUrl,selectList,changeList)
{
    var sName = changeList.name;
    document.getElementById("sub").src =
        sUrl + "mainId=" + selectList[selectList.selectedIndex].value + "&listName=" + sName;
}

/*
 * Create Date:2004-09-17
 * Author: Jeff.Zhou
 * Request sublist data.
 */
function changeExpertList(sUrl,radioButton,catId,changeList)
{
	/*
    	var sName = changeList.name;
	if(sName==undefined)
	{    
		sName = changeList[0].name;
	}*/	
    document.getElementById("sub").src =
        sUrl + "authorType=" + radioButton.value + "&catId=" + catId + "&listName=" + changeList ;
}


/*
 * Create Date:2004-06-01
 * Author: Jeff.Zhou
 * Reload the sublist data.
 */
function updateList(changeList,values)
{
    var list = document.getElementById(changeList);

	var len = list.length;
    for (var i = 1; i < len; i++)
    {
        list.remove(1);
    }

    nLen = values.length/2;
    for (var i = 0; i < nLen; i++)
    {
        list.options[i+1] = new Option(values[2*i+1],values[2*i]);
    }
    list.selectedIndex = 0;
}

/*
 * Create Date:2004-06-01
 * Author: Jeff.Zhou
 * Reload the sublist data.
 */
function updateWholeList(changeList,values)
{
    var list = document.getElementById(changeList);

	var len = list.length;
    for (var i = 0; i < len; i++)
    {
        list.remove(0);
    }

    nLen = values.length/2;
    for (var i = 0; i < nLen; i++)
    {
        list.options[i] = new Option(values[2*i+1],values[2*i]);
    }
    list.selectedIndex = 0;
}

function displayImage(image){
var extname,temp,str,strs,lens;

str= image;
strs=str.toLowerCase();
lens=strs.length;
extname=strs.substring(lens-4,lens);
temp="";
windowtitle = "";
if (image.toLowerCase().substring(0, 7) == "http://") {
	windowtitle = image;
} else {
	windowtitle = "http://"+location.host + image;
}
if (extname==".swf") {
	temp=temp+"<object width='100%' name='themovie' Classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
	temp=temp+" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'>";
	temp=temp+"<param name=movie value='" + image + "'><param name=quality value=high>";
	temp=temp+"<embed src='" + image + "' quality=high";
	temp=temp+" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'" ;
	temp=temp+" type='application/x-shockwave-flash'></embed>";
	temp=temp+"</object>";	
	opendynawin(windowtitle,temp);
}
else if ((extname == ".gif") ||
					(extname == ".jpg") ||
					(extname == ".jpe") ||
					(extname == ".jpeg") ||
					(extname == ".png")) {
	temp=temp+"<img src='"+image+"'>";
	opendynawin(windowtitle,temp);
} else {
	window.open(image,'Preview','width=600,height=300,resizable=yes,scrollbars=yes');
}


}

function callopendynawin(theObj){
var extname,temp,str,strs,lens;
if (theObj.value.length==0) return 0;

str= theObj.value;
strs=str.toLowerCase();
lens=strs.length;
extname=strs.substring(lens-4,lens);
temp="";
windowtitle = "";
if (theObj.value.toLowerCase().substring(0, 7) == "http://") {
	windowtitle = theObj.value;
} else {
	windowtitle = "http://"+location.host + theObj.value;
}

if (extname==".swf") {
	temp=temp+"<object width='100%' name='themovie' Classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
	temp=temp+" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'>";
	temp=temp+"<param name=movie value='" + theObj.value + "'><param name=quality value=high>";
	temp=temp+"<embed src='" + theObj.value + "' quality=high";
	temp=temp+" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'" ;
	temp=temp+" type='application/x-shockwave-flash'></embed>";
	temp=temp+"</object>";	
}
else
	temp=temp+"<img src='"+theObj.value+"'>";

opendynawin(windowtitle,temp);
}

function callopendynawinlocal(theObj){
var extname,temp,str,strs,lens;
if (theObj.value.length==0) return 0;

str= theObj.value;
strs=str.toLowerCase();
lens=strs.length;
extname=strs.substring(lens-4,lens);
temp="";

if (extname==".swf") {
	temp=temp+"<object width='100%' name='themovie' Classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
	temp=temp+" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'>";
	temp=temp+"<param name=movie value='" + theObj.value + "'><param name=quality value=high>";
	temp=temp+"<embed src='file:///" + theObj.value + "' quality=high";
	temp=temp+" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'" ;
	temp=temp+" type='application/x-shockwave-flash'></embed>";
	temp=temp+"</object>";	
}
else
	temp=temp+"<img src='file:///"+theObj.value+"'>";

opendynawin(theObj.value,temp);
}

function callopendynawinonserver(theObj){
var extname,temp,str,strs,lens;
if (theObj.value.length==0) return 0;

str= theObj.value;
strs=str.toLowerCase();
lens=strs.length;
extname=strs.substring(lens-4,lens);
temp="";
windowtitle = "";
if (theObj.value.toLowerCase().substring(0, 7) == "http://") {
	windowtitle = theObj.value;
} else {
	windowtitle = "http://"+location.host + theObj.value;
}
if (extname==".swf") {
	temp=temp+"<object width='100%' name='themovie' Classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
	temp=temp+" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'>";
	temp=temp+"<param name=movie value='" + theObj.value + "'><param name=quality value=high>";
	temp=temp+"<embed src='" + theObj.value + "' quality=high";
	temp=temp+" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'" ;
	temp=temp+" type='application/x-shockwave-flash'></embed>";
	temp=temp+"</object>";	
}
else
	temp=temp+"<img src='"+theObj.value+"'>";

opendynawin(windowtitle,temp);
}

function opendynawin(theTitle,theContent){
var winEx=window.open('','','width=600,height=300,resizable=yes,scrollbars=yes');

winEx.document.write("<html>");
winEx.document.write("<head>");
winEx.document.write("<title>" + theTitle+"</title>");
winEx.document.write("</head>");
winEx.document.write("<body>");
winEx.document.write("<table align='center' width='100%'>"); 
winEx.document.write("<tr><td align='center' >"+theContent+"</td></tr>"); 
//winEx.document.write("<tr><td align='center'><input type='button' style='font-size:9pt' value='....' onclick='javascript:window.close()'></td></tr>"); 
winEx.document.write("</table>");
winEx.document.write("</body>");
winEx.document.write("</html>");
//winEx.document.title='Preview==='+themovie.stage.width; 
winEx.document.close();
}

function overwrite(msg)
{
	var doc = document.forms[0];
	if (confirm(msg)) {
	  document.forms[0].overwrite.value="true";
		doc.submit();
	} else {
	// do nothing
	} 
}

//get visitors' screen resolution, append to a image url, 
//then write to current document
function writeScreenResolution(blankGIF){

	var r;
	do {
		r=Math.ceil(Math.random()*10000000000);
	} while(r<1000000000);
	var w=screen.width;
	var h=screen.height;
	var resolURL=blankGIF+"?resol="+w+"by"+h+"&rand="+r;
	document.write("<img src=\""+resolURL+"\" width=0 height=0 border=0>");
}

