function isPositiveNumber (num1){
	return !(isEmpty (num1) || isNaN (num1) || (parseFloat(num1) <= 0));
}
function isEmpty(strValue)
{
	strValue = strValue.replace(/^\s*/,"");
	strValue = strValue.replace(/\s*$/,"");
	return strValue.length == 0;
}
function Len(strValue)
{
	strValue = strValue.replace(/^\s*/,"");
	strValue = strValue.replace(/\s*$/,"");
	return strValue.length;
}

function trim(strValue)
{
	strValue = strValue.replace(/^\s*/,"");
	strValue = strValue.replace(/\s*$/,"");
	return strValue;
}

function isInteger(strValue)
{
   var numPat = /^[1-9]+(\d{0,})$/;
   var matchArray;
   if ((matchArray = strValue.match(numPat)) == null)
	return false;
   else
	return true;
}

function isNumber(strValue)
{
   var numPat = /^(\d{1,})$/;
   var matchArray;
   if ((matchArray = strValue.match(numPat)) == null)
	return false;
   else
	return true;
}

function isEmailValid(emailStr) {
   var emailPat = /^[\w\.-]+(\+[\w-]*)?@([\w-]+\.)+[\w-]+$/;
   var matchArray;
   if ((matchArray = emailStr.match(emailPat)) == null)
	return false;
   else
	return true;
}

function isMACAddressValid(strMAC) {
   var MACPat = /^[0-9A-F]{12}$/;
   // /^[0-9A-F]{2}[\-|:][0-9A-F]{2}[\-|:][0-9A-F]{2}[\-|:][0-9A-F]{2}[\-|:][0-9A-F]{2}[\-|:][0-9A-F]{2}$/;
   var matchArray;
   if ((matchArray = strMAC.match(MACPat)) == null)
	 return false;
   else
	return true;
}

function isIPValid(strIP) {
   var IPPat = /^(\d{1,3})(\.)(\d{1,3})(\.)(\d{1,3})(\.)(\d{1,3})$/;
     var matchArray = strIP.match(IPPat); // is the format ok?	
     if (matchArray == null) {return false;}
     if (matchArray[1] > 255) {return false;}	 
     if (matchArray[3] > 255) {return false;}	 
     if (matchArray[5] > 255) {return false;}	 
     if (matchArray[7] > 255) {return false;}	 
     return true; 	
}



function chkSpecialChars(str) 
{
	var sChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	for (var i = 0; i < str.length; i++) 
	{
  		if (sChars.indexOf(str.charAt(i)) != -1) 
  			return false;
  		else
  			return true;
  	}
}
function LZ(x) {
   if (x.length == 1)
	return "0" + x;
   else
	return x;
}
function roundOff(value, precision)
{
       if (value != 0) 
       {
     
			value = "" + value //convert value to string
			precision = parseInt(precision);

			var whole = "" + Math.round(value * Math.pow(10, precision));

			var decPoint = whole.length - precision;

			if(decPoint != 0)
			{
			        result = whole.substring(0, decPoint);
			        result += ".";
			        result += whole.substring(decPoint, whole.length);			        
			}
			else
			{
			        result = whole;
			}			
			return result;			
        }
        else 
        {
	        return 0;
        }
}

function chkChequeNumeric(checkStr)
{
	// only allow 0-9 be entered
	var checkOK = "0123456789" 

	var allValid = true;

	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}	

return allValid;
}

function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

function ReplaceParams(mesg,paramArray)
{

	if (paramArray=="undefined" || paramArray==null)
	{
		//Do Nothing
	}
	else //Assumes paramArray is supplied as delimited string to replace place holders in the Mesg.%1,2,3... or %B
	{
		var pArray,intI,rexp;
		if (paramArray.indexOf('|',0)>0 ) 
		{
			pArray=paramArray.split('|');
			for(intI=0;intI<pArray.length;intI++)
			{
				rexp="%"+(intI+1)+"%";
				mesg=mesg.replace(rexp,pArray[intI]);		
			}
		}
	 else if (isArray(paramArray))//Assumes some paramArray is supplied as Array to replace place holders in the Mesg.%1,2,3... or %B
		{
			
			for(intI=0;intI<paramArray.length;intI++)
			{
				rexp="%"+(intI+1)+"%";
				mesg=mesg.replace(rexp,paramArray[intI]);		
			}
		}	
	else
		{
			rexp="%1%";
			mesg=mesg.replace(rexp,paramArray);
		}	
	}
	mesg=mesg.replace("%B%","\n");
	return mesg;
}

function openMQSModalDialog(ctl,par)
{
	if (par==undefined || par==null)
	{
		window.showModalDialog('MqspopupPage.aspx?ctl='+ctl,"","dialogHeight:400px;dialogWidth:400px")
	}
	else
	{
		window.showModalDialog('MqspopupPage.aspx?ctl='+ctl,'',par)
	}
}
function openMQSWindow(ctl,windowW,windowH,autoclose)
{
	    openFrameless('MqspopupPage.aspx?ctl='+ctl,windowW,windowH,'MQSubscribe',autoclose)
}
function openNewWindow(objPage,windowW,windowH,autoclose)
{
		openFrameless(objPage,windowW,windowH,'MQSubscribe',autoclose)
}

function Trim(str){
	var len,start,end,i;
	
	len=str.length;
	if(str.length!=0)
	{for(i=0;i<len;i++){if(str.charAt(i)!=" "){start=end=i;break;}}
	for(i=len-1;i>=0;i--){if(str.charAt(i)!=" "){end=i+1;break;}}
	str=str.substring(start,end);}
	return str;
}
function decimalRoundOff(num,decimalplaces)
{
	var decimalfactor = Math.pow(10,decimalplaces);
	var roundedValue = Math.round(num*decimalfactor)/decimalfactor;
	return roundedValue;
}

/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
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(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=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 : dd/mm/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 openFrameless(urlPop,windowW,windowH,title,autoclose){
var beIE = document.all?true:false
var s = "width="+windowW+",height="+windowH;

// set the screen position where the popup should appear
 var windowX = (window.screen.width-windowW)/2
 var windowY = (window.screen.height-windowH)/2
  if (beIE){
    NFW = window.open("","",s)     
    NFW.blur()
    window.focus()       
    NFW.resizeTo(windowW,windowH)
    NFW.moveTo(windowX,windowY)
    
    var frameString=""+
"<html>"+
"<head>"+
"<title>"+title+"</title>"+
"</head>"+
"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
"<frame name='top' src='"+urlPop+"' scrolling=auto>"+
"<frame name='bottom' src='about:blank' scrolling='no'>"+
"</frameset>"+
"</html>"
    NFW.document.open();
    NFW.document.write(frameString)
    NFW.document.close()
  } else {
	
    NFW=window.open(urlPop,"popFrameless","scrollbars,"+par)
    NFW.blur()
    window.focus() 
    
  }   
  NFW.focus()   
  if (autoclose){
    window.onunload = function(){NFW.close()}
  }
  
}
function showDDToolTip(img,ctrl) {
	//img.title = ctrl.options[ctrl.selectedIndex].text;
}
function DeleteGridLayer(layerID,chkStatus,strMessage)
{
 // to clear selected grid row
  if(layerID != -1)
  {
	var status, cnt1; 
 
		cnt1 = parseInt(document.forms[0].noOfExItems.value) - 1; 
		document.forms[0].noOfExItems.value = cnt1;

		if(document.getElementById)
		{
			document.getElementById(layerID).innerHTML="";
			document.getElementById(layerID).outerHTML="";
		}else if(document.all){
			document.all[layerID].innerHTML="";
			document.all[layerID].outerHTML="";
		}else if(document.layers){
			with(document.layers[layerID].document)
			{
				open();
				write("");
				close();
			}
		}
	}
	// to clear all grid row 
	if(layerID == -1) 
	{
		var status, i, layerID;	
		if (document.forms[0].noOfExItems.value > -1)
		{
			if (chkStatus == true)
			{
				status = confirm(strMessage)
			}else {
				status = true
			}
			
			if (status == true) 
			{				
				for (i=0;i<=document.forms[0].noOfItems.value;i++)
				{
				layerID = "item" + i
					if  ((document.getElementById(layerID)) != undefined)
					{			
						if(document.getElementById)
						{
							document.getElementById(layerID).innerHTML="";
							document.getElementById(layerID).outerHTML="";
						}else if(document.all){
							document.all[layerID].innerHTML="";
							document.all[layerID].outerHTML="";
						}else if(document.layers){
							with(document.layers[layerID].document)
							{
								open();
								write("");
								close();
							}
						}
					}
				}	
				document.forms[0].noOfExItems.value = -1;
			}
		}
	}	
}
function Test()
{

}
function getPageLeft (el) {
  var left = 0;
  do 
    left += el.offsetLeft;
  while ((el = el.offsetParent));
  return left;
}
function getPageTop (el) {
  var top = 0;
  do 
    top += el.offsetTop;
  while ((el = el.offsetParent));
  return top;
}
function showTooltip (nextTo, tip) {
 if (tip.toUpperCase() == "SELECT" || tip.toUpperCase() == "SELECT STOCK POINT") return;
  var tt = document.getElementById('tooltip');
  tt.innerHTML = tip; 
  tt.style.left = (getPageLeft(nextTo) + nextTo.offsetWidth) + 'px';
  tt.style.top = getPageTop(nextTo) + 'px';
  tt.style.visibility = 'visible';
} 
function hideTooltip () {
  document.getElementById('tooltip').style.visibility = 'hidden';
} 