﻿var CurrentState=''
var activeThemeField='hdfTheme'
var isLoaded='yes'
var lastTheme=''
function isMaxLength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("MaxLength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

function showError(err,moduleName,functionName){
try{
alert('ERR['+moduleName+'.'+functionName+']:- '+err.description)}
catch(err){
alert('Error showing error description!!!')}}
function GetObject(id)
{return(document.getElementById(id));}
function GetValue(id)
{return(document.getElementById(id).value);}
function getValue(id){
try{
var object=document.getElementById(id)
if(object==null)return('')
if(object.type=='text'|| object.type=='textarea' || object.type=='password')
return(object.value)
else if(object.type=='checkbox' || object.type=='radio')
return(object.checked)
else if(object.type=='select' || object.type=='select-one' || object.type=='select-multiple')
return(object.selectedIndex)}
catch(err){
return('')
showError(err,'common','getValue')}}
function OnSessionExpires(page){
window.location.href=page}
function openWindow(pagelink,isNewWindow){
try{
if(isNewWindow=='yes')
features='menubar=0,maximized=1,scrollbars=1,status=1,toolbar=0,titlebar=0,resizable=1,left=0,top=150,directories=0'
else
features='menubar=0,maximized=1,scrollbars=0,status=1,toolbar=0,titlebar=0,resizable=1,left=0,top=0,directories=0'
mainwindow=window.open(pagelink,'_blank',features)
mainwindow.resizeTo(screen.width,isNewWindow=='yes'?screen.height/1.5:screen.height)}
catch(err){
showError(err,'Common','openWindow')}}
function showStatus(status){
try{
window.status=status}
catch(err){
showError(err,'common','showStatus')}}
//function trim(value){
//value=LTrim(value)
//return RTrim(value)}
function trim(s){
s=s.toString();
var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
return (m == null) ? "" : m[1];}
function ShowElement(fieldId,idmsg){
document.getElementById(idmsg).style.display='block'
document.getElementById(fieldId).style.display='block'}
function rTrim(value){
while(value.charAt((value.length-1))==' '){
value=value.substring(0,value.length-1)}
return value}
function lTrim(value){
while(value.charAt(0)==' '){
value=value.replace(value.charAt(0),'')}
return value}
function openStartup(){
try{
var WINDOW_WIDTH=screen.width,WINDOW_HEIGHT=screen.height
var features='menubar=0, scrollbar=0,status=1,alwaysRaised=1,toolbar=0,titlebar=0, resizable=1,directories=0,left='+((screen.width/2)-(WINDOW_WIDTH/2))+',top='+((screen.height/2)-(WINDOW_HEIGHT/2))
var win
win=window.open('home.aspx','_blank',features)
win.resizeTo(WINDOW_WIDTH,WINDOW_HEIGHT)}
catch(err){showError(err,'Common','openStartup');}}
function getWebCombo(id){
return(ISGetObject(id))}
function getWebComboById(id){
return(wcGetComboById(id))}
function getWebGrid(id){
return(ISGetObject(id))}
function clearWebCombo(id,enable){
var wc=wcGetComboById(id)
wc.Value=''; wc.Text='';
wc.ClearSelection()
if(enable)wc.Enable();else wc.Disable()
}
function showElement(srcId,trgId){
if(srcId==''){
var obj=document.getElementById(trgId)
if(obj==null) return;
var doc=getContentDocument()
var h=(doc.clientHeight)/2-(obj.offsetHeight)/2+doc.scrollTop
var l=(doc.clientWidth)/2-(obj.offsetWidth)/2+doc.scrollLeft
//obj.style.position='absolute';
//alert(obj.style.position);
obj.style.top=h+'px'
obj.style.left=l+'px'
return}
var srcObj=document.getElementById(srcId)
var trgObj=document.getElementById(trgId)
var oTop=parseInt(srcObj.offsetTop,10)+parseInt(srcObj.offsetHeight,10)
var oLeft=parseInt(srcObj.offsetLeft,10)
var obj=srcObj
if(!window.opera){
while(srcObj.tagName!='BODY'&&srcObj.tagName!='HTML'){
oTop-=parseInt(srcObj.scrollTop,10)
oLeft-=parseInt(srcObj.scrollLeft,10)
srcObj=srcObj.parentNode}}
srcObj=obj
do{
srcObj=srcObj.offsetParent
oTop+=parseInt(srcObj.offsetTop,10)
oLeft+=parseInt(srcObj.offsetLeft,10)
}while(srcObj.tagName!='BODY'&&srcObj.tagName!='HTML')
trgObj.style.top=oTop+'px'
trgObj.style.left=oLeft+20+'px'}
function setWebComboValue(id,value,text){
try{
var wc=ISGetObject(id)
wc.SetText(text)
//wc.LoadValue()
wc.SetValue(value)
//wc.SetSelectedRowByValue(value);
}
catch(err){
showError(err,'Common','setWebComboValue('+id+','+value+','+text+')')}}
function getWebComboValue(id){
try{
var wc=ISGetObject(id)
if(wc==null)return null
var value
if(wc.Value==null)value='';else value=wc.Value
return(value)}
catch(err){
showError(err,'Common','getWebcomboValue')}}
function getWebComboText(id){
try{
var wc=ISGetObject(id)
var text=''
if(wc.Text==null)text='';else text=wc.Text
if(text=='')text=wc.GetTextBoxValue()
return(text)}
catch(err){
showError(err,'Common','getWebComboText')}}
function getWebComboTextByIndex(id,index){
try{
var wc=wcGetComboById(id)
var row=wc.GetSelectedRow()
var text=''
if(row!=null)text=row.cells[index].innerText
if(text=='')text=wc.GetTextBoxValue();
return(text)}
catch(err){
showError(err,'Common','getWebComboTextByIndex')}}
function getNextNo(id,columName){
try{
var wg=ISGetObject(id)
var row=wg.RootTable.GetRow(0)
var cells
var max=0,val=0
while(row!=null){
cells=row.GetCells()
val=parseInt(cells.GetNamedItem(columName).Text)
if(val>max)max=val
row=row.GetNextRow()}
return(max+1)}
catch(err){
showError(err,'Common','getNextNo')}}
function setFocusInterval(id,interval){
try{
var obj=document.getElementById(id)
if(obj.disabled ||obj.style.display=='none')return
var script='document.getElementById(\''+id+'\').focus()'
if(interval==null)interval=250
setTimeout(script,interval)}
catch(err){
showError(err,'Common','setFocusInterval')}}
function activateTheme(title){
var i,lnk
try{
if(document.getElementById){
for(i=0;(lnk=document.getElementsByTagName('link')[i]);i++){
if(lnk.getAttribute('rel').indexOf('style')!=-1&&lnk.getAttribute('title')){
try{
document.getElementById(activeThemeField).value=title}
catch(err)
{}
lnk.disabled=true
if(lnk.getAttribute('title')==title)
{lnk.disabled=false}}}}
var doc=window.frames['fraTab1']
var cDoc
if(doc&&doc.isLoaded=='yes'){
doc.activateTheme(title)
for(i=0;(cDoc=doc.document.getElementsByTagName('iframe')[i]);i++){
if(doc.frames[i].activateTheme)doc.frames[i].activateTheme(title)}}
if(lastTheme!=title&&title!=''){
SetCurrentTheme(title)
lastTheme=title}}
catch(err)
{showError(err,'Theme','activateTheme');}}
function SetCurrentTheme(themeName){
try{
if(typeof(PageMethods)=='function'){
PageMethods.SetCurrentTheme(themeName,OnSuccess,OnFailure,'setting current Theme')
return(false)}}
catch(err){}}
function saveTheme(ddlId){
try{
var obj=document.getElementById(ddlId)
var themeId=obj.options[obj.selectedIndex].value
var themeName=obj.options[obj.selectedIndex].text
if(typeof(PageMethods)=='function'){
PageMethods.SaveTheme(themeId,themeName,OnSuccess,OnFailure,'saving Theme')
return(false)}}
catch(err){
showError(err,'Theme','saveTheme')}}
function OnSuccess(result,userContext,methodName){}
function OnFailure(result,userContext,methodName){
alert('ERR['+methodName+']: Error while '+userContext+'...')}
function getContentDocument(){
return((!window.opera&&document.compatMode&&document.compatMode!="BackCompat")? document.documentElement : document.body)}

function getWebComboTextByName(id,name){
try{
var wc=wcGetComboById(id)
var index=wc.Columns.GetNamedItem(name).Position;
var row=wc.GetSelectedRow()
var text=''
if(row!=null)text=row.cells[index].innerText
return(text)
}
catch(err){showError(err,'Common','getWebComboTextByName')}
}
function setWebcomboValueText(id,value,text)
{
var wc=wcGetComboById(id)
wc.Value=value;
wc.Text=text;
}

function setWebcomboFocus(id){
try{var wc=wcGetComboById(id);wc.SetFocus();}
catch(err){//showError(err,'Common','setWebcomboFocus');
}}

function setWebGridFocus(id){
try{var wg=ISGetObject(id); wg.SetFocus()}
catch(err){//showError(err,'Common','setWebcomboFocus');
}}
function disableAll(flag)
{
if(flag==null)flag=true;
var type;
for(i=0;(obj=document.getElementsByTagName('input')[i]);i++)
{type=obj.type
if(type=='text'||type=='checkbox' || type=='radio' ||type=='password')obj.disabled=flag;
}
for(i=0;(obj=document.getElementsByTagName('textarea')[i]);i++)obj.disabled=flag
for(i=0;(obj=document.getElementsByTagName('select')[i]);i++)obj.disabled=flag
ApplyProperyCss()
}
function DateDiff(FromDate,ToDate){
var one_day=1000*60*60*24;
return Math.ceil((ToDate.getTime()-FromDate.getTime())/(one_day));
}
