gIP = "127.0.0.1";
gPort = ":9080";
getProject = "aromatic";

function getIP(){
	return gIP;
}

function getPort(){
	return gPort;
}

function linkChild(page){
	with(document.cscform){
		action=page+".jsp";
		submit();
	}
}
function bdOnload() {
		document.cscform.action=__pageCall.value+".jsp";
		document.cscform.submit();
}

function linkGenXML(page){
	with(document.cscform){
		__xmlname.value=xmlname.value;
		action="/genxml/"+page+".jsp" ;
		submit();
	}
}

function backHelp(){
	with(document.cscform){
		//		alert("__fieldSearch.value = "+__fieldSearch.value+" fieldV = "+fieldV);
     	action=__pageCall.value+".jsp";
		submit();
	}
}


function  setcmd(acktion){
	with(document.cscform){
		if(acktion=="ack"){
			__gorec.value=__maxrec.value;
			__ack.value="ack";
		}else{
			if(acktion=="del"){
				__cmdchild.value="del";
			}else{
				if(acktion=="next"){
					if(__gorec.value<__maxrec.value){__gorec.value++;
					}
				}else{
					if(acktion=="prev"){
						 if(__gorec.value>1){__gorec.value--;  }
					}else{
						if(acktion=="top"){ __gorec.value=1;
						}else{
							if(acktion=="end"){__gorec.value=__maxrec.value;
							}else{
								if(acktion=="save"){
									__cmdchild.value="save";
									__ack.value="add";
								}

							}
						}

					}
				}
			}
		}

//		alert(acktion+"  "+__gorec.value);
  //   	action="http://192.100.1.129:8080/aromatic/jsp/"+__screen.value+".jsp";
		submit();
	}
}

function showcscupload(record){
	with(document.cscform){
		__gorec.value=record;
		__cmd.value="Child";
	     action="pwcscupload_show.jsp?__headMulti="+__screen.value+"&__pwcscupload0="+record;
		submit();
	}
}

function editcscupload(record){
	with(document.cscform){
		__gorec.value=record;
		//__cmd.value="Child";
	     action="pwcscupload_edit.jsp?__headMulti="+__screen.value+"&__pwcscupload0="+record;
		submit();
	}
}

function childMulti(record){
	with(document.cscform){
		__gorec.value=record;
		__cmd.value=""; // edit
	     action=__childMulti.value+".jsp";

		submit();
	}
}

function backhead(){
	with(window.opener.cscform){
	     //action=__headMulti.value+".jsp";
	    submit();
	     window.close();
		
	}
}

function addMulti(){
	with(document.cscform){
		__cmd.value="";
		__gorec.value="";
		__ack.value="add";
	     //action=__childMulti.value+".jsp?__headMulti="+__screen.value;
	     window.open("CS002.jsp?__gorec= &__ack.value=add");
		//submit();
	}
}

function deleteMulti(){
	with(document.cscform){
		__cmd.value="DelChild";
	//    action=__screen.value+".jsp";
		submit();
		alert(__cmd.value);
	}
}

function  link(jsppage){
	//alert("not in with");
	with(document.cscform){
//		alert("Link");
     	action=jsppage+".jsp";
		submit();
	}
}
function savepass(){
	with(document.cscform){
		if(__pwpassword1.value==__pwpassword2.value){
				bCon=confirm("ต้องการบันทึกข้อมูลหรือไม่ ?");
				if( (bCon==true)&&(__pwpassword.value==__checkpass.value))	{
					__cmd.value="save";
					__pwpassword.value=__pwpassword1.value;
					action=__screen.value+".jsp";
					submit();
					alert("โปรด Login เข้าสู่ระบบใหม่");
				}else{
					alert("รหัสผ่านงานเก่าไม่ถูกต้อง");
				}
		}else{
			alert("ยืนยันรหัสผ่านไม่ถูกต้อง");
		}
	}
}


function  linkReport(jsppage){
	with(document.cscform){
     	action=jsppage+".jsp";
//		submit();
		window.open(jsppage+".jsp?__id="+__id.value);
	}
}

function edelete(){
	with(document.cscform){
		bCon=confirm("ต้องการลบข้อมูลหรือไม่ ?");
		if (bCon==true)	{
			//	setAction(__jspname.value,"delete");
			__cmd.value="delete";
			submit();
		}
	}
}

function search(){	
	with(document.cscform){
		__cmd.value="search";
		submit();
	}
}

function save(){
	with(document.cscform){
		__cmd.value = "save";
		submit();
		}
}
function update(){
	with(document.cscform){
		bCon=confirm("ต้องการแก้ไขข้อมูลหรือไม่ ?");
		if (bCon==true)	{
			__confirm.value="2";
			__cmd.value = "save";
			submit();
		}
	}
}

function confirmSave(){
	with(document.cscform){
		if(__confirm.value=="0"){
		    	aCon=confirm("ต้องการบันทึกข้อมูลหรือไม่ ?");
				if (aCon==true)	{
					save();
				}
		}else {
			alert("มีข้อมูล Record นี้อยู่แล้ว ถ้าต้องการบันทึกข้อมูลกรุณากด EDIT ?");
			__confirm.value = "0";
		}
	}
}
/*function confirmSave(){
	with(document.cscform){
		if(__confirm.value=="0"){
		    	aCon=confirm("ต้องการบันทึกข้อมูลหรือไม่ ?");
				if (aCon==true)	{
					save();
				}
		}else if(__confirm.value=="1"){
			bCon=confirm("มีข้อมูล Record นี้อยู่ิแล้ว ต้องการบันทึกข้อมูลหรือไม่ ?");
			if(bCon==true){
				save();
			}
		}else if(__confirm.value=="2"){
				cCon=confirm("ต้องการบันทึกข้อมูลหรือไม่ ?");
				if (cCon==true)	{
					__confirm.value="0";
					save();
				}
		}
	}
}*/

function checkConfirm(){
	//alert(document.cscform.confirm.value)
	with(document.cscform){
		if(__confirm.value=="1"){
			alert("มีข้อมูล Record ถ้าต้องการบันทึกข้อมูลกรุณากด EDIT ?");
//			__confirm.value = "0";
		}else __confirm.value = "0";
	}
}

function save_pwcscupload01(){
	with(document.cscform){
		bCon=confirm("ต้องการบันทึกข้อมูลหรือไม่ ?");
		if (bCon==true)	{
			__cmd.value="save";
			action="pwcscupload01"+".jsp";
			submit();
		}
	}
}

function linkHelp_pwtran(help,input){
	with(document.cscform){
		__cmd.value="help";
		__fixCon.value="";
//		alert(__cmd.value);
     	action="TestHelp.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall="+__screen.value;
		submit();
	}
}

function linkHelp_fc(help,input){
	with(document.cscform){
		__cmd.value="help";
		__cmdchild.value="save";
     	action="testhelp.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall=bgfactorclass1";
		submit();
	}
}

function linkHelp_fc_active(help,input){
	with(document.cscform){
		__active.value="active";
		__cmd.value="help";
		__cmdchild.value="save";
     	action="testhelp.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall=bgfactorclass1";
		submit();
	}
}

function linkHelp_bgtemp_active(help,input){
	with(document.cscform){
		__active.value="active";
		__cmd.value="help";
		__cmdchild.value="save";
     	action="testhelp.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall=bgcscuploadtemplate1";
		submit();
	}
}

function linkHelp_bg(help,fieldName,show){
	with(document.cscform){
		__cmd.value="help";
		__cmdchild.value="save";
     	action="testhelp.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall=bgcscuploadgroup1";
		submit();
	}
}

function helpPage(helpName){
	with(document.cscform){
			window.open(helpName+".jsp","Help","left=150,top=150,width=800,height=200,toolbar=no,status=yes,scrollbars=yes");
	}
}
//23/09/03 edit by SUK
function linkHelp(help,input){
	with(document.cscform){
		//alert(__screen.value);
	var param="PRU084.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall="+__screen.value;
	window.open(param,"Help","left=150,top=150,width=500,height=200,toolbar=no,status=yes,scrollbars=yes");
}
}
function helpPageCon(help,input,fcon){
with(document.cscform){
	var param="PRU084.jsp?__fixCon="+fcon+"&__helpName="+help+"&__helpReturn="+input+"&__pageCall="+__screen.value;
	window.open(param,"Help","left=150,top=150,width=500,height=200,toolbar=no,status=yes,scrollbars=yes");
}
}

function linkHelp_Return(help,input){
	with(document.cscform){
		//alert(__screen.value);
	var param="PRU084.jsp?__helpName="+help+"&__helpReturn="+input+"&__pageCall="+__screen.value;
window.open(param,"Help","left=150,top=150,width=500,height=200,toolbar=no,status=yes,scrollbars=yes");
}
}
function backMainPage(page){
	with(document.cscform){
		__screen.value="bgcscuploadgroup";
     	action=page+".jsp";
		submit();
	}
}

/*function backPage(fieldV){
	with(document.cscform){
//		alert("__fieldSearch.value = "+__fieldSearch.value+" fieldV = "+fieldV);
		__cmd.value="search";
     	action=__pageCall.value+".jsp?__help="+__fieldSearch.value+","+fieldV+"&__screen="+__pageCall.value;
		submit();
	}
}*/
//11/09/03   Edit by wut
  //__help="+"employee,comid#007,001"
/*function backPage(valueList){
	with(document.cscform){
      alert(valueList+" back to   --->"+__pageCall.value);
		__cmd.value="search";
     	action=__pageCall.value+".jsp?__help="+valueList+","+"&__screen="+__pageCall.value;
		submit();
	}
	window.close();
}*/
//function backPage(typeid,typename){
function backPage(valueList){
	with(window.opener.document.cscform){
		__help.value = valueList;
		//__codeid.value="412";
		//alert(__help.value);
		//__cmd.value="search";
		
		submit();
		//window.opener.location.refresh();
	}	
	window.close();
}

function backPage_Return(valueList){
var tmp = new Array(50);
var tmp1 = new Array(50);
var inputName="";
var inputValue="";
	with(window.opener.document.cscform){
		tmp=valueList.split(",");
   	for (var i=0; i < tmp.length; i++) { 
   	    tmp1=tmp[i].split("#");
        for (var j=0; j < tmp1.length; j++) { 
              inputName=tmp1[j++];   
              inputValue=tmp1[j];             
    		  for(var z=0;z<elements.length;z++){
    		    if(elements[z].name == inputName){
    		         elements[z].value=inputValue;
    		    }
    		  }
     	}	  
    }		
	}	
	window.close();
}

/*function splitString (stringToSplit,separator) { 
  arrayOfStrings = stringToSplit.split(separator)
     document.write ('<P>The original string is: "' + stringToSplit + '"')
     document.write ('<BR>The separator is: "' + separator + '"') 
     document.write ("<BR>The array has " + arrayOfStrings.length + " elements: ")
     for (var i=0; i < arrayOfStrings.length; i++) { 
          document.write (arrayOfStrings[i] + " / ")
     }
 }
*/




function goPage(page){
	with(document.cscform){
		__goPage.value=page;
//		alert(__goPage.value);
//     	action="http://"+getIP()+getPort()+"/cscupload/jsp/testhelp.jsp";
		submit();
	}
}

function setOrderby(){
//	alert("setOrderby");
	with(document.cscform){
		alert("listOrder.value ==  "+__listOrder.options[__listOrder.selectedIndex].value);
		__orderBy.value=__listOrder.options[__listOrder.selectedIndex].value;
		submit();
	}
}
/*function setSearchby(){
//	alert("setSearchby");
	with(document.cscform){
		__goPage.value="1";
//		__searchBy.value=__searchOrder.options[__searchOrder.selectedIndex].value;
//		alert(__searchBy.options[__searchBy.selectedIndex].value);
		submit();
	}
}*/
function setSearchby(){
	//	alert("setSearchby");
	with(document.cscform){
		__goPage.value="1";
		//__searchBy.value=__searchOrder.options[__searchOrder.selectedIndex].value;
		alert(__searchBy.options[__searchBy.selectedIndex].value);
		alert("value"+__valueSearch.value);
		if (__valueSearch.value == "")	{
			alert("กรุณาใส่ค่าในการค้นหา");
		} else {
				alert("__valueSearch.value = "+__valueSearch.value);
				submit();
			}
	}
}

function ckreport(){
	with(document.cscform){
		action="filereport.jsp";
		submit();
	}
}

function cmdrp(){
		with(document.cscform){
		__cmd.value="pdf";
	//	alert(__cmd.value+"  "+__screen.value);
     	action="filereport.jsp";
		submit();
	}
}

function linkStartup(page){
	with(document.cscform){
     	action=page+".jsp";
		submit();
	}
}

function goBookPage(page){
	with(document.cscform){
		__goPage.value=page;
//		alert(__goPage.value);
     	action="show_help.jsp";
		submit();
	}
}

function linkPage(page){
	with(document.cscform){
	  	action=page+".jsp";
		submit();
	}
}

function viewPayment(pymt) {
	with(document.cscform) {
		__cmd.value="search";
		__pwsalatype.value=pymt;
		//alert("pwsalatype = "+__pwsalatype);
		action=__screen.value+".jsp";
		submit();
	}
}

function  showtime(){
	with(document.cscform){
		__timework.value="go";
		__cmd.value="ack";
		//action="http://192.100.1.129:8080/cscupload/jsp/pwcscupload01.jsp";
		submit();
	}
}

function setstatus(status) {
	with(document.cscform) {
		__cmd.value="save";
		__pwstatus.value=status;
		alert("pwstatus.value = "+__pwstatus.value);
		action=__backpage.value+".jsp";
		submit();
	}
}

function cancel(){
	with(document.cscform){
		reset();
	}
}

function editotsingle(record){
	with(document.cscform){
	     action="pwotsingle_edit.jsp?__pwot0="+record;
		submit();
	}
}

function gopwotgroup2(){
	with(document.cscform){
	     action="pwotgroup2"+".jsp?__headMulti="+__screen.value;
		submit();
	}
}

function gopwotgroup1(){
	with(document.cscform){
	     action=__headMulti.value+".jsp";
		submit();
	}
}
function backpage(){
	with(document.cscform){
	     action=__backpage.value+".jsp";
		submit();
	}
}

function gopwdoctran(pwdoctran,pwdoctype,pwstep){
	with(document.cscform){
	     action=__childMulti.value+".jsp?__pwdoctran="+pwdoctran+"&__pwdoctype="+pwdoctype+"&__pwstep="+pwstep;
		submit();
	}
}



function send(){
	with(document.cscform){
		__pwsend.value ="1";
		__cmd.value="save";

//	     action="http://192.100.1.129:8080/aromatic/jsp/"+__screen.value+".jsp";
		submit();
	}
}
function   changeactor(pwemployee){
	with(document.cscform){
	     action=__screen.value+".jsp?__actor="+pwemployee;
		submit();
	}
}

function genTime(){
	timecode="";
	with(document.cscform){
		__cmd.value="ack";
		if(__timeGroup.value>0){
		for(i =1 ;i<=__timeGroup.value;i++){
			temp=document.cscform['__time'+i];
			if(temp.checked){
				timecode=timecode+temp.value+",";
			}
		}
	     action=__screen.value+".jsp?__genTime=genTime&__timecode="+timecode;
		submit();
	}
	}
}

function next(screen){
	with(document.cscform){
		__cmd.value="ack";
		action=screen+".jsp";
		submit();
	}
}

function backpage1(screen){
	with(document.cscform){
	     action=screen+".jsp";
		submit();
	}
}
function logout(){
	with(document.cscform){
	     action="logout"+".jsp?__logout=ok";
		submit();
	}
}

function admin_logout(){
	with(document.cscform){
		target = "_top";
	    action="admin_logout"+".jsp?__logout=ok";
		submit();
	}
}

function hilightOn(row){
    row.setAttribute('bgcolor','#99FF99',0);
}

function hilightOff(row){
    row.setAttribute('bgcolor','#FFFFFF',0);
}

function setAction(page,cmd){
		with(document.cscform){
			    action= page +".jsp?__cmd=" + cmd;
		}
}

//------------------------------------------------------------------------
// wut edit 15/09/03
//------------------ tooltip -------------------------------------------
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
offsetX = 5;
offsetY = 5;
var toolTipSTYLE="";
function initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
    if(ns4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
  }
}
function toolTip(msg)
{
	
  if(toolTip.arguments.length < 1) // hide
  {
    if(ns4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
  }
  else // show
  {
 
	var tableWidth=msg.length+10;
	var content ="<table border='1' class=\"toolTip\"><tr><td>&nbsp;&nbsp;"+ msg+"&nbsp;&nbsp;</td></tr></table>";
    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }
  }
}
function moveToMouseLoc(e)
{
  if(ns4||ns6)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else
  {
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
  }
  toolTipSTYLE.left = x + offsetX;
  toolTipSTYLE.top = y + offsetY;
  return true;
}
// end of TOOLTIP ------------------
// how to uses 
/*
<BODY>
<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
<script language="javascript">initToolTips();</script>
</BODY>
*/
//SORT TABLE------------------------------------------
<!-- Begin
function setDataType(cValue)
  {
    // THIS FUNCTION CONVERTS DATES AND NUMBERS FOR PROPER ARRAY
    // SORTING WHEN IN THE SORT FUNCTION
    var isDate = new Date(cValue);
    if (isDate == "NaN")
      {
        if (isNaN(cValue))
          {
            // THE VALUE IS A STRING, MAKE ALL CHARACTERS IN
            // STRING UPPER CASE TO ASSURE PROPER A-Z SORT
            cValue = cValue.toUpperCase();
            return cValue;
          }
        else
          {
            // VALUE IS A NUMBER, TO PREVENT STRING SORTING OF A NUMBER
            // ADD AN ADDITIONAL DIGIT THAT IS THE + TO THE LENGTH OF
            // THE NUMBER WHEN IT IS A STRING
            var myNum;
            myNum = String.fromCharCode(48 + cValue.length) + cValue;
            return myNum;
          }
        }
  else
      {
        // VALUE TO SORT IS A DATE, REMOVE ALL OF THE PUNCTUATION AND
        // AND RETURN THE STRING NUMBER
        //BUG - STRING AND NOT NUMERICAL SORT .....
        // ( 1 - 10 - 11 - 2 - 3 - 4 - 41 - 5  etc.)
        var myDate = new String();
        myDate = isDate.getFullYear() + " " ;
        myDate = myDate + isDate.getMonth() + " ";
        myDate = myDate + isDate.getDate(); + " ";
        myDate = myDate + isDate.getHours(); + " ";
        myDate = myDate + isDate.getMinutes(); + " ";
        myDate = myDate + isDate.getSeconds();
        //myDate = String.fromCharCode(48 + myDate.length) + myDate;
        return myDate ;
      }
  }
function sortTable(col, tableToSort)
  {
	  
    var iCurCell = col + tableToSort.cols;
    var totalRows = tableToSort.rows.length;
    var bSort = 0;
    var colArray = new Array();
    var oldIndex = new Array();
    var indexArray = new Array();
    var bArray = new Array();
    var newRow;
    var newCell;
    var i;
    var c;
    var j;
    // ** POPULATE THE ARRAY colArray WITH CONTENTS OF THE COLUMN SELECTED
    for (i=1; i < tableToSort.rows.length; i++)
      {
        colArray[i - 1] = setDataType(tableToSort.cells(iCurCell).innerText);
        iCurCell = iCurCell + tableToSort.cols;
      }
    // ** COPY ARRAY FOR COMPARISON AFTER SORT
    for (i=0; i < colArray.length; i++)
      {
        bArray[i] = colArray[i];
      }
    // ** SORT THE COLUMN ITEMS
    //alert ( colArray );
    colArray.sort();
    //alert ( colArray );
    for (i=0; i < colArray.length; i++)
      { // LOOP THROUGH THE NEW SORTED ARRAY
        indexArray[i] = (i+1);
        for(j=0; j < bArray.length; j++)
          { // LOOP THROUGH THE OLD ARRAY
            if (colArray[i] == bArray[j])
              {  // WHEN THE ITEM IN THE OLD AND NEW MATCH, PLACE THE
                // CURRENT ROW NUMBER IN THE PROPER POSITION IN THE
                // NEW ORDER ARRAY SO ROWS CAN BE MOVED ....
                // MAKE SURE CURRENT ROW NUMBER IS NOT ALREADY IN THE
                // NEW ORDER ARRAY
                for (c=0; c<i; c++)
                  {
                    if ( oldIndex[c] == (j+1) )
                    {
                      bSort = 1;
                    }
                      }
                      if (bSort == 0)
                        {
                          oldIndex[i] = (j+1);
                        }
                          bSort = 0;
                        }
          }
    }
  // ** SORTING COMPLETE, ADD NEW ROWS TO BASE OF TABLE ....
  for (i=0; i<oldIndex.length; i++)
    {
      newRow = tableToSort.insertRow();
      for (c=0; c<tableToSort.cols; c++)
        {
          newCell = newRow.insertCell();
          newCell.innerHTML = tableToSort.rows(oldIndex[i]).cells(c).innerHTML;
        }
      }
  //MOVE NEW ROWS TO TOP OF TABLE ....
  for (i=1; i<totalRows; i++)
    {
      tableToSort.moveRow((tableToSort.rows.length -1),1);
    }
  //DELETE THE OLD ROWS FROM THE BOTTOM OF THE TABLE ....
  for (i=1; i<totalRows; i++)
    {
      tableToSort.deleteRow();
    }
  }
  

	function checkAll(){
		with(document.cscform){
			for(i=0;i<elements.length;i++){
					if(elements[i].type=="checkbox")
							elements[i].checked=true;
			}//end for
		}//end with
	}//end function
	function decheckAll(){
		with(document.cscform){
			for(i=0;i<elements.length;i++){
					if(elements[i].type=="checkbox")
							elements[i].checked=false;
			}//end for
		}//end with
	}//end function