
//function RunEditor()
//{
//	_editor_url = "Editor/";                     // URL to htmlarea files
//	var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
//	if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
//	if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
//	if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
//	if (win_ie_ver >= 5.5) {
//	document.write('<script src="Editor/editor.js" language="JavaScript"></script>');
//	}else{
//		document.write('<script>function editor_generate() { return false; }</script>'); 
//	}
//}
//RunEditor();

function SetForwordSlash( Obj , val)
	{
		if( val.length == 2 )
		{val = val + '/' ;}
		if( val.length == 5 )
		{val = val + '/' ;}
		document.getElementById(Obj).value = val ;
	}

function GetColor(Obj,Obj1)
	{
		var oldcolor = Obj.value.toString();
		var newcolor = showModalDialog("ColorBox/popups/select_color.html", oldcolor, "resizable: no; help: no; status: no; scroll: no;");// dialogTop: " + 1 + "; dialogLeft: " + 1 + ";");	
		if (newcolor!=null)
			{
				Obj.value = "#" + newcolor;
				Obj1.style.backgroundColor="#" + newcolor ;
			}
		else
			{
			}
	}
function ClearDate(obj)
	{
		obj.value="";
	}
function EnterOnlyLong(event)
{		
	var keyCode = event.keyCode;
    if (keyCode==0)
        keyCode = event.which;
	if (keyCode>=48 && keyCode<=57)
	{
	}
	else
	{
		return GetDefault(event);
	}
	return true;
}
function GetDefault(event)
{
	 var keyCode = event.keyCode;
     if (keyCode==0)
		keyCode = event.which;
     if (keyCode==8 || keyCode==9 || keyCode==37 || keyCode==39 || keyCode==46 || keyCode==116 )
          return true;
     return false;
}
function EnterPhoneNumber(event,obj)
{	
	
	var val=document.getElementById(obj).value.toString().toUpperCase();
	
	var keyCode = event.keyCode;
    if (keyCode==0)
        keyCode = event.which;
	if ((keyCode>=48 && keyCode<=57) || keyCode==32)
	{
	}
	else
	{
		switch (keyCode)
		{
			case 40://(
				if ((val==null || val.length ==0) && val.indexOf("(")==-1)
				{}
				else{return GetDefault(event);}
				break;
			case 41://)
				var t=val.replace(" ","");
				for (var i=0;i<t.length;i++)
					t=t.replace(" ","");				
				if (t.length==4 && val.indexOf(")")==-1)
				{}
				else
					{return GetDefault(event);}
				break;
			case 45://-				
				if (val.indexOf("-",0,3)!=-1)
				{
					if (val.split("-").length>3)
					{
						return GetDefault(event);
					}					
				}
				break;
			case 88://X
			case 120://x
				var t=val;
				for (var i=0;i<t.length;i++)
				{
					t=t.replace(" ","");
					t=t.replace("(","");
					t=t.replace(")","");
					t=t.replace("-","");
				}
				if (t.length==10 && val.indexOf("X")==-1)					
				{}
				else
				{return GetDefault(event);}
				break;
			default:
				return GetDefault(event);
				break;
		}
	}
	return true;
}
/*
function GetCursor(where)
{	
	var pos;
	if (document.selection)
	{
		where.focus();
		sel=document.selection.createRange();
		if(sel.text=="")
		{
			sel.text='µµµ';
			dummy=where.createTextRange();
			dummy.findText('µµµ');
			dummy.select();
			pos=where.value.indexOf('µµµ');
			document.selection.clear();
			where.focus();			
		}
	}
	return pos;
}
*/
function EnterValidDate(event)
{	
	var keyCode = event.keyCode;
    if (keyCode==0)
        keyCode = event.which;
	if ((keyCode>=48 && keyCode<=57)||keyCode==47)
	{
	}
	else
	{
		return GetDefault(event);
	}	
	return true;
}

function EnterOnlyDouble(event,obj)
{	
	var keyCode = event.keyCode;
    if (keyCode==0)
        keyCode = event.which;

	if ((keyCode>=48 && keyCode<=57)||keyCode==46 || keyCode==13)
	{
		if (keyCode==46)
			{
				var text;
				text=document.getElementById(obj).value.toString();
				if(text.toString().indexOf(".")!=-1)
				{
					return false; 
				}
			}
	}
	else
	{
		return GetDefault(event);
	}
	return true;
}


// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1950;
var maxYear=2100;

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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate_1(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month.")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear+".")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date.")
		return false
	}
return true
}

function VFrmDate( Obj ){
	//document.frmSample.txtDate
	if( document.getElementById(Obj).value == "" )
	{}
	else
	{
		if (isDate_1(document.getElementById(Obj).value)==false){
			document.getElementById(Obj).value = "";
			document.getElementById(Obj).focus();
			return false
		}
	}
    return true
 }
/*
function EnterOnlyChar(Length)
{	
	if ((event.keyCode>=65 && event.keyCode<=90) || (event.keyCode>=97 && event.keyCode<=122))
	{
		
	}
	else
	{
		event.keyCode=null;
	}
}
*/
/*
function EnterMobileNo()
{
if ((event.keyCode==43 ||event.keyCode==45 ) || (event.keyCode>=48 && event.keyCode<=57) )
	{
	if (event.keyCode==43)
			{			
				var len=0;
				len=document.activeElement.getAttribute("value").toString().length;
				if(len != 0)
					event.keyCode=null;
			}	
		}
	else
	{
		event.keyCode=null;
	}
}
*/
function EnterChars(event)
{	
	var keyCode = event.keyCode;
    if (keyCode==0)
        keyCode = event.which;

	if ((keyCode>=65 && keyCode<=90) || (keyCode>=97 && keyCode<=122) || (keyCode==32))
	{
		
	}
	else
	{
		return GetDefault(event);
	}
	return true;
}



function SetMaxLength(event, obj , Lenght)
{
	var keyCode = event.keyCode;
    if (keyCode==0)
        keyCode = event.which;

	var l = obj.value.length;
	if (l < Lenght)
	{}
	else
	{	return GetDefault(event);	}
	return true;
}

/*
function OnAddToList( OBJ1 , OBJ2 )
{
	if  (OBJ1.selectedIndex != -1)
	{
			OBJ2.options[OBJ2.length] = new  Option(OBJ1.options[OBJ1.selectedIndex].text , OBJ1.options[OBJ1.selectedIndex].text);
			OBJ1.options[OBJ1.selectedIndex] = null;
	}
}
		
function OnRemoveFrom( OBJ1 , OBJ2 )
{
	if  (OBJ2.selectedIndex != -1)
	{
		OBJ1.options[OBJ2.length] = new  Option(OBJ2.options[OBJ2.selectedIndex].text,OBJ2 .options[OBJ2.selectedIndex].text);
		OBJ2.options[OBJ2.selectedIndex] = null;
	}
}
*/
function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

function SelectAllCTRLs(Obj)
{		// Obj is Main Check Box control
	var i=0;
	for(i=0;i<document.forms[0].length;i++)
	{
		if(document.forms[0][i].type=="checkbox")
		{
			if(Obj.id!=document.forms[0][i].id)
			{
				document.forms[0][i].checked=Obj.checked;
			}
		}	
	}
}
function SelectMainCTRLs(Obj)
{		// Obj is Main Check Box control
	var flag=true;	
	var i=0;
	for(i=0;i<document.forms[0].length;i++)
	{
		if(document.forms[0][i].type=="checkbox")
		{
			if(Obj.id!=document.forms[0][i].id)
			{
				if(document.forms[0][i].checked==false)
				{
					flag=false;
					break;
				}
			}
		}
	}
	Obj.checked=flag;
}
// Function For Select/Deselect All Check Box Of DataGrid
function SelectAll(ObjDG,ChkName) // ObjDG=DataGrid Object, ChkName=(stirng) Name of Bound CheckBox  
{
	
	var flag=document.getElementById('chkmain').checked;
	var i=2;
	
	while (document.getElementById(document.getElementById(ObjDG).id+"__ctl" + i + "_"+ ChkName)!=null)
	{
		if(document.getElementById(document.getElementById(ObjDG).id +"__ctl" + i + "_"+ ChkName).type=="checkbox")
		{
			document.getElementById(document.getElementById(ObjDG).id+"__ctl" + i + "_"+ ChkName).checked = flag;
		}
		i=i+1;
	}
		
}

// Function For Select/Deselect All Check Box Of DataGrid
function SelectMain(DGID,ChkName,ChkMain) // DGID=DataGrid Object, ChkName=(stirng) Name of Bound CheckBox , ChkMain=(string) Main CheckBox Name
{
	var flag=true;	
	var i=2;
	while (document.getElementById(DGID.id +"__ctl" + i + "_"+ ChkName) !=null)
	{
		if(document.getElementById(DGID.id +"__ctl" + i + "_"+ ChkName).type=="checkbox")
		{
			if(document.getElementById(DGID.id +"__ctl" + i + "_"+ ChkName).getAttribute("Checked")==false)
			{
				flag=false;
			}
		}
		i=i+1;
	}
	var PageID;
	PageID=DGID.id.replace(DGID.name,"");
	
	document.getElementById(PageID+ChkMain).checked=flag;
}

function DisableSearch( ObjCHK , ObjTR1 , ObjTR2 , ObjTR3  )
{
		//alert(ObjCHK +','+ ObjMemberBTN +','+ ObjAddBTN +','+ ObjRemoveBTN );
				
		if( document.getElementById(ObjCHK) != null)
		{
			if( document.getElementById(ObjCHK).getAttribute("Checked") == false )
			{		
				document.getElementById(ObjTR1).style.display="none";
				document.getElementById(ObjTR2).style.display="none";
				document.getElementById(ObjTR3).style.display="none";
			}
			else
			{
				document.getElementById(ObjTR1).style.display="inline";
				document.getElementById(ObjTR2).style.display="inline";
				document.getElementById(ObjTR3).style.display="inline";
			}
		}
}
//'###########################################################################
function CheckAll(objInput){
	var ctrl;	
	var blnChekced = objInput.checked;
	for(var i=0;i<chkArr.length;i++){
		ctrl = document.getElementById(chkArr[i]);
		if(ctrl)
			ctrl.checked = blnChekced;
	}
}
//'###########################################################################
function CommaFormatted(inputbox,amount)
{
	amount=CurrencyFormatted(amount);
	if(amount>0)
	{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2);
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	}
	else
	amount='';
	inputbox.value=amount;
	
}

function CommaFormattedAUS(inputbox,amount)
{
  CommaFormattedAUS(inputbox,amount,0);
}

function CommaFormattedAUS(inputbox,amount,isShowAll)
{
	
	amount=CurrencyFormatted(amount);
	if(amount>0)
	{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2);
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	}
	else
	amount='';
	
	if(isShowAll==1)
	{
	if(parseFloat(amount)>0)
	inputbox.value=amount;
	else
	inputbox.value="ALL";
	}
	else
	inputbox.value=amount;
}

function CommaFormattedIND(inputbox,amount)
{
amount=CurrencyFormatted(amount);
if(IsNumeric(amount))
{
amount= Round(amount,2).toString();
cutoff = Number(amount.lastIndexOf("."));
if(cutoff == -1)
{
p1=amount.toString();
p2="00";
}
else
{
p1=amount.substr(0,cutoff).toString();
p2=amount.substr(cutoff+1,2).toString();
}
if(p1.length > 3)
{
 p11=p1.substr(0,p1.length-3);
 p12=p1.substr(p1.length-3,3);
 output='';
 IsComma=false;
 for(var i=p11.length-1;i>=0;i--)
 {
  output = p11.charAt(i) + output;
  if(IsComma && i!=0)
  { IsComma=false;
    output = ","+ output;
  }
  else
  { IsComma=true; }
 }
 amount=output+="," + p12 + "." + p2;
}
else
 amount=p1 + "." + p2;
}
else
 amount="0.00";
 
cutoff = Number(amount.lastIndexOf("."));
p2=amount.substr(cutoff,3).toString();
if(p2==".00")amount=amount.substr(0,cutoff).toString();
if(parseFloat(amount)>0)
inputbox.value=amount;
else
inputbox.value="";
}

function IsNumeric(strString)
{
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
  
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function Round(rnum, rlength) 
{ 
  return Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);   
}


function CommaFormattedAUS(inputbox,amount)
{
	amount=CurrencyFormatted(amount);
	if(amount>0)
	{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2);
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	}
	else
	amount='';
	inputbox.value=amount;
	
}
function CurrencyFormatted(amount)
{
	amount=amount.replace(/,/g,'');
	amount=amount.replace(/ /g,'');
	
	var lcheck=amount.replace(".",'');
	var lcheck=amount.replace(" ",'');
	//alert(lcheck+"..len.."+lcheck.length);
	if(lcheck.length>18)
	{
		amount=amount.substring(0,17);
	}
	
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; } 
	var minus = '';
	if(i < 0) { minus = '-'; }
	//alert(i);
	i = Math.abs(i);
	//alert("Math.abs(i): "+i);
	i = parseInt((i + .005) * 100);
	//alert("parseInt((i + .005) * 100): "+i)
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function GetCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
function goBack(step)
{  
  if(step!=null)
  window.history.go(step);
  else
  window.history.back();
  
  /*bName = navigator.appName; //1
  bVer = parseInt(navigator.appVersion); //2  
  if(GetCookie("IsPostBack")=="True" && bName == "Microsoft Internet Explorer" && bVer >= 4 )window.location.reload(); 
  */
}


