var w3c=(document.getElementById)? true: false;
var ns4=(document.layers)?true:false;
var ie5=(w3c && document.all)? true : false;
var ns6=(w3c && !document.all)? true: false;

function MaxPopWindow()
{
	window.moveTo(0,0);
	window.resizeTo(screen.width,screen.height);
	window.focus();	
}
function ChangeContent(id,text)
{
	if(!document.getElementById(id).isExt)
	{
		var d=document.getElementById(id);
		if(ns6)d.style.overflow="hidden";
		d.innerHTML=text;
		if(ns6)d.style.overflow="block";
	}
	else document.getElementById(id).src=text;		//this is for id+'_ifrm'
}
function StringReplaceAll(org, old, newstr)
{
	while(org.indexOf(old) >=0)
		org = org.replace(old, newstr);
	return org;
}
function GetPos(w,h,otherstr) 
{ 
	var winleft = ((screen.width - w) / 2);
	var wintop = ((screen.height - h) / 2)-40;
	if (wintop<0) wintop=10	
	if (otherstr.length==0)
		otherstr='scrollbars=yes,status=yes,resizable=yes'
	return ('height=' + h + ',width=' + w + ',top=' + wintop + ',left=' + winleft + ',' + otherstr);	
} 	
function Pop(htmPage, wndName, w, h, style)
{	
	var today = new Date();
	htmPage +="&tm=" + today.getTime();
	var obj= window.open(htmPage, wndName, GetPos(w, h, style));	
	obj.focus();
	return obj;
}
function PopModal(htmPage, w, h, style)
{	
	var str ='dialogWidth:'+ w + 'px;dialogHeight:' + h + 'px;center:yes;help:no;status:no;';	
	window.showModalDialog(htmPage, window, str);
	return false ;	
}
function CloseReload()
{
	if (window.opener && !window.opener.closed)
		window.opener.location.reload();
	window.close();
}
function CloseSubmit(frm, page, pcmd)
{
	if (window.opener && !window.opener.closed)
	{
		if (page!='')
			frm.page.value=page;
		if (pcmd!='')
			frm.pcmd.value=pcmd;
		window.opener.focus();	
		frm.method='post';
		frm.submit();		
	}
	window.close();
}
function goSubmit(frm, page, cmd, action, method)
{
  if (action!='')
	  frm.action = action;
  if (method!='')
  	frm.method = method  
  frm.page.value=page;
  frm.pcmd.value = cmd; 	
  frm.submit();
  return true ;
}	
function srchIdx(frm, page, sortCol, pageIdx, pcmd)
{
	frm.pageIdx.value=pageIdx
	frm.sortCol.value=sortCol;
	if (pcmd.length>0)
		frm.pcmd.value=pcmd;
	goLink(frm,'','');
	return false ; 	
}
function Sort(frm, col, page, pcmd)
{
	frm.sortCol.value=col;
	frm.page.value=page
	frm.pcmd.value=pcmd;
	frm.sortDir.value=(frm.sortDir.value=='DESC')? '' : 'DESC' ;
	goLink(frm,'','');
}
function ResetSrch(frm)
{
	frm.Keyword.value='';	
	frm.sortCol.value='';
	frm.sortDir.value='';
	frm.pageIdx.value='1';	
}
function IsBlank(obj, msg)
{	
	if (obj.value=="" || obj.value.length ==0 || obj.value=='0' || obj.value=='0.0')
	{
		if (msg.length>0)
		{
			alert(msg);
			obj.focus();
		}
		return true;
	}
	return false;
}
function IsChecked(frm, nm, msg)
{
	for (i=0 ; i < frm.length ; i ++ )
	{
		if (frm.elements[i].name == nm && frm.elements[i].checked)
		{
			return true;
		}
	}
	if (msg.length>0)
		alert(msg);
	return false;
}
function UncheckAll(frm, nm)
{
	for (i=0 ; i < frm.length ; i ++ )
	{
		if (frm.elements[i].name == nm )
		{
			frm.elements[i].checked=false;
		}
	}	
}
function GetRadioBoxValue(objradio)
{
	for (i=0 ; i < objradio.length ; i ++ )
	{		
		if (objradio[i].checked)
		{
			return objradio[i].value;
		}
	}	
	return '';
}
function ToInt(str)
{
	if( typeof str == "undefined"  || str==null )
		return 0;	
	var n = parseInt(str);
	if (isNaN(n))
		return 0;
	else 
		return n;
}
function ToDouble(str)
{
	if( typeof str == "undefined"  || str==null )
		return 0.0;
	var n = parseFloat(str);
	if (isNaN(n))
		return 0.0;
	else 
		return n;
}
function IsNumerical(field, num)
{	
	if (field.value.length > 0) 
	{
		for (i=0 ; i < field.value.length; i++)
		{
				if( field.value[i]<'0' || field.value[i]>'9')
					return false ;				
		}
		if (num>0 && field.value.length > num)
		{
				return false;
		}
	} else if ( num > 0 ) return false;
   return true;
}
function IsDecimal(field, num)
{
	if (field.value.length > 0) 
	{
		for (i=0 ; i < field.value.length; i++)
		{
				if( field.value[i]<'0' || field.value[i]>'9' || field.value[i]!='.')
					return false ;				
		}
		if (field.value.length > num)
		{
				return false;
		}
	} else if ( num > 0 ) return false;
   return true;
}

/**
Check phone # is valid or not.
*/
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function IsPhoneNo(objPhone, msg)
{
	if (objPhone.value.length==0) return true;
	if (checkInternationalPhone(objPhone.value)==false)
	{
		if(msg.length > 0)
			alert(msg)
		objPhone.focus()
		return false
	}
	return true
 }


/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck(str) 
{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
 		 return true					
	}

function IsEmail(objEmail, msg)
{
	if (objEmail.value.length==0) return true;
	if (echeck(objEmail.value)==false)
	{
		if (msg.length>0)
			alert(msg);
		objEmail.focus()
		return false
	}
	return true
 }
function ExpendRegion(divId, cmd)
{
		var div = document.all[divId];
		if (cmd=='toggle')
		{
			if (div.style.display == "none")
			{
				div.style.display = "inline";
			}
			else
			{
				div.style.display = "none";
			}
		} else
		{
			div.style.display = cmd;
		}
}

function FmtMoney(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+		
	//num = num.substring(0,num.length-(4*i+3))+','+	
	num.substring(num.length-(4*i+3));
	
	//return (((sign)?'':'-') + '$' + num + '.' + cents);
	return (((sign)?'':'-') + num + '.' + cents);
}

