
var strParameters;
var selline;

function doPostBack() {
	
	document.forms[0].submit();
	/*
	var strUrl = window.location.href;
	var len = strUrl.length;
	if(strUrl.charAt(len-1)=='#')
		strUrl = strUrl.substring(0, len-1);
	window.location=strUrl;
	*/
}

function activeLine(tr) 
{	
}

function resumeLine(tr) 
{	
}


function selectLine(tr)   
{		
	selline=tr;
}

function selectedLine(tr)
{
}

function unselectedLine(tr)
{
	if(null!=tr)
	{
	}
}

			
function add(pageUrl)
{
	var sURL = appRoot+pageUrl;
	var featuresstring='resizable:yes;help:no;status:no;center:Yes;dialogWidth:650px;dialogHeight:480px';
	
	var sRtn = showModalDialog(sURL,"",featuresstring);
	if (sRtn=='dirty')
	{
		doPostBack();
	}
}
function openAddUrl(pageUrl)
{
	
	var sURL = appRoot+pageUrl;
	var sRtn=window.open(sURL,'','width=720,height=550,left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	if (sRtn=='dirty')
	{
		doPostBack();
	}
}
function openEdit(pageUrl, tr)
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+tr.rowid;
	
	var featuresstring='resizable:yes;help:no;status:no;center:Yes;dialogWidth:650px;dialogHeight:480px';
	//alert(sURL);
	var sRtn = showModalDialog(sURL,"",featuresstring);
	if (sRtn=='dirty')
	{
		doPostBack();
	}
}
function openEdit2(pageUrl, tr)
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+tr.rowid;
	
	var featuresstring='resizable:yes;help:no;status:no;center:Yes;dialogWidth:400px;dialogHeight:250px';
	//alert(sURL);
	var sRtn = showModalDialog(sURL,"",featuresstring);
	if (sRtn=='dirty')
	{
		doPostBack();
	}
}
function openEditUrl(pageUrl, tr)//wxp
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+tr.rowid;
	
	var sRtn=window.open(sURL,'','width=820,height=600,left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	if (sRtn=='dirty')
	{
		doPostBack();
	}
}

function openEditUrl2(pageUrl, tr)//wxp
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+tr.rowid;
	
	var sRtn=window.open(sURL,'','width=800,height=600,left=0,top=0,toolbar=yes,location=no,directories=no,status=yes,center=yes,menubar=yes,scrollbars=yes,resizable=yes');
	if (sRtn=='dirty')
	{
		doPostBack();
	}
}

function gotoSubUrl(pageUrl, tr)
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	
	var sURL = appRoot+pageUrl+"&"+tr.rowid;
	var sRtn=window.open(sURL,'','width=800,height=600,left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	if (sRtn=='dirty')
	{
		doPostBack();
	}
}
function view(pageUrl, tr)
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}

	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+tr.rowid;
	
	var featuresstring='resizable:yes;help:no;status:no;center:Yes;dialogWidth:650px;dialogHeight:480px';
	showModalDialog(sURL,"",featuresstring);
}

function deleteRow(pageUrl,tr)
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	//var sURL = appRoot+pageUrl+jo+"delClick=del&"+tr.rowid+"&xmlName="+document.all.xmlName.value;
	var sURL = appRoot+pageUrl+jo+"delClick=del&"+tr.rowid;
	//alert(sURL);
	var featuresstring='resizable:yes;help:no;status:no;center:Yes;dialogWidth:0px;dialogHeight:0px';
	if (confirm(Message_they))
	{
		var sRtn = showModalDialog(sURL,"",featuresstring);
		if (sRtn=='dirty')
		{
			doPostBack();
		}
	}
}

function auditRow(pageUrl,tr)
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+"auditClick=del&"+tr.rowid+"&xmlName="+document.all.xmlName.value;
	//alert(sURL);
	var featuresstring='resizable:yes;help:no;status:no;center:Yes;dialogWidth:0px;dialogHeight:0px';
	if (confirm(Message_add))
	{
		var sRtn = showModalDialog(sURL,"",featuresstring);
		if (sRtn=='dirty')
		{
			doPostBack();
		}
	}
}
			
function ReAuditRow(pageUrl,tr)
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+"ReAuditClick=del&"+tr.rowid+"&xmlName="+document.all.xmlName.value;
	//alert(sURL);
	var featuresstring='resizable:yes;help:no;status:no;center:Yes;dialogWidth:0px;dialogHeight:0px';
	if (confirm(Message_setting))
	{
		var sRtn = showModalDialog(sURL,"",featuresstring);
		if (sRtn=='dirty')
		{
			doPostBack();
		}
	}
}

function openalert(pageUrl,tr, strAlert)
{
	strAlert = strAlert + "";
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+tr.rowid;
	//alert(sURL);
	var featuresstring='resizable:yes;help:no;status:no;center:Yes;dialogWidth:0px;dialogHeight:0px';
	var bc = false;
	if(strAlert!=""&&strAlert!="undefined")
	{
		bc = confirm(strAlert);
	}
	if(strAlert==""||strAlert=="undefined"||bc)
	{
		var sRtn = showModalDialog(sURL,"",featuresstring);
		if (sRtn=='dirty')
		{
			doPostBack();
		}
	}
}			

function gotoUrl(pageUrl, tr)
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+tr.rowid;
	
	window.location=sURL;
}
function openUrl(pageUrl, tr)
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+tr.rowid;
	
	window.open(sURL);
}
function gotoUrlWin(pageUrl, tr, strTarget)
{
	if (tr==null)
	{
		alert(Grid_SelectOneLine);
		return false;
	}
	
	var jo="?"
	if(pageUrl.indexOf("?")!=-1)
		jo="&"
	var sURL = appRoot+pageUrl+jo+tr.rowid;
	
	window.open(sURL, strTarget);
}

function gotoUrlNoId(pageUrl)
{
	
	var sURL = appRoot+pageUrl;
	window.location=sURL;
}
function openUrlNoId(pageUrl)
{
	
	var sURL = appRoot+pageUrl;
	window.open(sURL);
}
function ViewUrl(pageUrl)
{
	
	var sURL = appRoot+pageUrl
	var sRtn=window.open(sURL,'','width=700,height=600,left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	if (sRtn=='dirty')
	{
		doPostBack();
	}
}

function openDialog(url)
{
	var varg='resizable:yes;help:no;status:no;center:Yes;dialogWidth:380px;dialogHeight:380px'
	var str=window.showModalDialog(url,'',varg);
	if (str=='dirty')
	{
		doPostBack();
		//window.location =window.location.href;
	}
	
	return true;
}



function openWebDialog(url,width,height,msg)
{
	var varg='resizable:yes;help:no;status:no;center:Yes;dialogWidth:'+width+'px;dialogHeight:'+height+'px'
	if(msg!=null&&msg!="")
	{
		if(!confirm(msg)) return;
	}
	var str=window.showModalDialog(appRoot+url,window,varg);
	if (str=='dirty')
			{
				doPostBack();
				//window.location =window.location.href;
			}
	
	return str;
}
function openAbsWindow(url)
{
	var openobj = window;
	if(typeof(window.dialogArguments)=="object")
	{
		
		//if(window.dialogArguments!=null)
			//openobj=window.dialogArguments;
	}
	openobj.open(url);
	//openobj.focus();
	
	
}
function openChooseForm(url,field,oBtn)
{
	var returnval=openWebDialog(url,640,500);
	var btns=document.getElementsByName("btn_"+field);
	var index=0;
	for(var i=0;i<btns.length;i++)
	{
	  if(btns[i]==oBtn)
	  {
	    index=i;break;
	  }
	}
	
	var idField=document.getElementsByName(field)[index];
	var nameField=document.getElementsByName(field+"_name")[index];
	
	if(returnval!=null&&returnval!="")
	{
		
		var vals=returnval.split('|');
		var idval=vals[0];
		var nameval=vals[1];
		_WindowReturnValue=vals[2];
		
		if(nameval=="")
		{	nameval=idval;}
		idField.value=idval;
		nameField.value=nameval;
			
	}
}

function clearChooseForm(field,oBtn)
{
	var btns=document.getElementsByName("cls_"+field);
	var index=0;
	for(var i=0;i<btns.length;i++)
	{
	  if(btns[i]==oBtn)
	  {
	    index=i;break;
	  }
	}
	
	var idField=document.getElementsByName(field)[index];
	var nameField=document.getElementsByName(field+"_name")[index];
	idField.value='';
	nameField.value='';
	

}
function openVideo(url,target,id,width,height)
{
	var showUrl;
	if(url.indexOf("?")!=-1)
		showUrl=url+"&id="+id;
	else
		showUrl=url+"?id="+id;
	showUrl+="&w="+width+"&h="+height;
	if(target=='_blank')
	{
		var varg='resizable:yes;help:no;status:no;center:Yes;dialogWidth:'+width+'px;dialogHeight:'+height+'px'
		window.showModalDialog(showUrl,'',varg);
			
	}
	else
	{	
		
		SetVidelID(id);
	}
	
}

function openWindow(pageUrl,width,height,target,msg)
{
	if(msg!=null&&msg!="")
	{
		if(!confirm(msg)) return;
	}
	
	var swd = window.screen.availWidth;
	var sht = window.screen.availHeight;
	if(width==null) width=790;
	if(height==null) height=580;
	var left = (swd-width)/2;
	var top = (sht-height)/2;
		
	var sURL = appRoot+pageUrl;
	var sTarget="_openWindow";
	if(target!=null)
	{
		sTarget=target;
	}
		
	var sRtn=window.open(sURL,sTarget,'width='+width+',height='+height+',left='+left+',top='+top+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes');
	sRtn.focus();
	return sRtn;
}

function openFileWindow(pageUrl,oBtn)
{
	var btns=document.getElementsByName(oBtn.name);
	var index=0;
	for(var i=0;i<btns.length;i++)
	{
		if(btns[i]==oBtn)
		{
		  index=i;
		}
	}
	
	openWindow(pageUrl+'&idx='+index,420,160)
}
function multiLanguage(id,name)
{
	var idField=document.getElementsByName(id)[0];
	var nameField=document.getElementsByName(name)[0];
	
	var sUrl = "include/MultiInput.aspx?id="+id+"&name="+name;
	var width=400,height=200;
	var varg='resizable:yes;help:no;status:no;center:Yes;dialogWidth:'+width+'px;dialogHeight:'+height+'px'
	var str=window.showModalDialog(appRoot+sUrl,idField,varg);
	if(str!=null)
	{
		var arrStr=str.split('|');
		nameField.value=arrStr[0];
		idField.value=arrStr[1];
		nextFocus(nameField);
	}
}

function SubTable_AddItem(tableId)
{
	var strNum=prompt(Message_riquire,10);
	var num=1;
	try{ num=parseInt(strNum);}catch(e){ num=1;};
	for(n=0;n<num;n++)
	{
      SubTable_AddOneItem(tableId)
  	}
}

function SubTable_AddOneItem(tableId)
{
	var table=document.all(tableId+'_List');
	var fieldArray=eval(tableId+'_array');
	var colLength = fieldArray.length;
	var currRow =table.insertRow();
	for(var i = 0; i< colLength; i++)
	{
        currCell=currRow.insertCell();
        currCell.bgColor="#FFFFFF";
        
		var fieldInput=fieldArray[i];
		if(i==0) currCell.width="10";
		if(i==colLength-1) currCell.width="90%";
		currCell.innerHTML = fieldInput;
        
    }	
    SubTable_CopyItem(tableId);
}

function CheckBoxDelId(form)
{
	var strvalue="";
	for (var i=0;i<form.elements.length;i++)
    {
		var e = form.elements[i];
		if (e.name == 'chkDelete')
		{
			if(e.checked == true) 
			{
				if(strvalue=="") {strvalue=e.value;}
				else { strvalue+=","+e.value;}
			}
		}
    }
    return strvalue;
}

function SubTable_CheckAll(tableId)
{
	ca=document.all(tableId+"_CheckAll");
	d=document.all(tableId+"_RowNo");
	if(ca==null || d==null) return;
	 if(d.length != null){
		for(var i=d.length-1; i>=0; i--)
        {
           if(ca.checked) d(i).checked=true;
           else d(i).checked=false;
        }
	}
	else
	{
		if(ca.checked) d.checked=true;
		else d.checked=false;
	}	
}
function SubTable_DelItem(tableId)
{
	var table=document.all(tableId+'_List');
    d=document.all(tableId+"_RowNo");
    if(d == null) return;
    if(d.length != null){
        for(var i=d.length-1; i>=0; i--)
        {
            if(d(i).checked){
				table.deleteRow(i+1)
           }
        }
    }
    else
        if(d.checked) table.deleteRow(1);
}

function SubTable_CopyItem(tableId)
{
	var fieldArray=eval(tableId+'_fields');
	var colLength = fieldArray.length;
	for(var i = 0; i< colLength; i++)
	{
		var fieldName=fieldArray[i];
		var fieldNameInput=fieldName+"Name"
		fObj=document.all(fieldName);
		fnObj=document.all(fieldNameInput);
		
        if(fObj!=null && fObj.length!=null && fObj.length>=2)
        {
			len=fObj.length;
			fObj(len-1).value=fObj(len-2).value;
        
        }
        if(fnObj!=null && fnObj.length!=null && fnObj.length>=2)
        {
			len=fnObj.length;
			fnObj(len-1).value=fnObj(len-2).value;
        }
    }	
}
function selectChange(control, secondName,all)
{
  if(control.value==''||control.value=='-1') return;		

  var firstCtrls=document.getElementsByName(control.name);
  var sName=secondName.split('|');
  for(var n=0;n<sName.length;n++)
  {
	var secondCtrls=document.getElementsByName(sName[n]);
	var secondControl=secondCtrls;
	if(firstCtrls.length>0)
	{
		for( i=0; i<firstCtrls.length; i++)
		{
		 if(firstCtrls[i]==control){secondControl=secondCtrls[i];}
		}
	}
	
    if(secondControl.tagName.toLowerCase()!="select") return;
    
	var ItemId=eval(sName[n]+control.value+"_id");
	var ItemName=eval(sName[n]+control.value+"_name");
	var myEle ;
	var x ;
	// Empty the second drop down box of any choices
	for (var q=secondControl.options.length;q>=0;q--) secondControl.options[q]=null;
	 
	// ADD Default Choice - in case there are no values
	myEle = document.createElement("option") ;
	myEle.value = '' ;
	if(all==0) myEle.text = Message_please ;
	else  myEle.text = Message_wo ;
	secondControl.add(myEle) ;
	for ( x = 0 ; x < ItemId.length  ; x++ )
    {
          myEle = document.createElement("option") ;
          myEle.value = ItemId[x] ;
          myEle.text = ItemName[x] ;
          secondControl.add(myEle) ;
    }
  }
}

function PrintExcel(TableName)
{
	if(window.confirm(Message_wni))
	{

		var oXL = new ActiveXObject("Excel.Application");
		oXL.Visible = true;

		var oWB = oXL.Workbooks.Add();
		var oSheet = oWB.ActiveSheet;

		omxh = document.getElementById(TableName)
   

  
		for(i=1;i<omxh.rows[0].cells.length;i++)
		{
			oSheet.Cells(1, i).Value = omxh.rows[0].cells[i].innerText;
		}


		oSheet.Range("A1", "AA1").Font.Bold = true;
     

		for(i=1;i<omxh.rows.length;i++)
		{

			for(j=1;j<omxh.rows[i].cells.length;j++)
			{
				oSheet.Cells(i+2, j).Value = omxh.rows[i].cells[j].innerText;
			}
			oSheet.Cells(i+2, 2).NumberFormat = "@";


		}
      
	}
}
function openPageUrl(pageCtrl)
{
	
	var sURL = appRoot+"Model/PageUrl.aspx";
	var featuresstring='resizable:yes;help:no;status:no;center:Yes;dialogWidth:590px;dialogHeight:450px';
	
	var sRtn = showModalDialog(sURL,"",featuresstring);
	if (sRtn!=''&&sRtn!=null)
	{
		pageCtrl.value=sRtn.substring(0,sRtn.indexOf(","));
	}
}

//multiAddform
function Multi_AddItem(tableId)
{
	var strNum=prompt(Message_riquire,10);
	var num=1;
	try{ num=parseInt(strNum);}catch(e){ num=1;};
	for(n=0;n<num;n++)
	{
      Multi_AddOneItem(tableId)
  	}
}

function Multi_AddOneItem(tableId)
{
	var table=document.all(tableId+'_List');
	var rowItem=document.getElementById(tableId+'_RowItem');
	var currRow =table.insertRow();

	rowContent=unescape(decodeURIComponent(rowItem.value));
	//alert(rowContent);
	 currCell=currRow.insertCell();
	 currCell.width="10";
     currCell.bgColor="#FFFFFF";
     currCell.innerHTML = "<input type='checkbox' name='"+tableId+"_RowNo'>";
     
     currCell=currRow.insertCell();
     currCell.bgColor="#FFFFFF";
     currCell.innerHTML = rowContent;
}



function Multi_CheckAll(tableId)
{
	ca=document.all(tableId+"_CheckAll");
	d=document.all(tableId+"_RowNo");
	if(ca==null || d==null) return;
	 if(d.length != null){
		for(var i=d.length-1; i>=0; i--)
        {
           if(ca.checked) d(i).checked=true;
           else d(i).checked=false;
        }
	}
	else
	{
		if(ca.checked) d.checked=true;
		else d.checked=false;
	}	
}

function Multi_DelItem(tableId)
{
	var oTable=document.all(tableId+'_List');
	if(oTable!=null && oTable.rows.length>0)
	{
	for(var n=oTable.rows.length-1;n>=0;n--)
	{
		var oRow=oTable.rows[n];
		dd=oRow.cells[0].all(tableId+"_RowNo");
		if(dd.checked)
		 {oTable.deleteRow(n);}
	
	}
	}
		
}
