/*
**********************************************************************************************
*  Modified Date: 06/04/2006 
*  Modified By : T.Shanmugam
*  Purpose/Change: changeFocus() function is changed for Phone number control focusing issue.
*  Ref.Document : Issue #3426
*********************************************************************************************
*/
function WinOpen(url,windowname,width,height,scrollbars,resizable,titlebar,toolbar,menubar,location,status,directories){
	var myBars='directories='+directories+',location='+location+',menubar='+menubar+',status=yes,titlebar='+titlebar+',toolbar='+toolbar;
	var myOptions='scrollbars='+scrollbars+',width='+width +',height='+height +',resizable='+ (resizable == "yes"?"1":resizable);
	var myFeatures=myBars+','+myOptions;

	var winleft = (screen.width / 2) - (width / 2);
   	var wintop = (screen.height / 2) - (height / 2);

	if(parseInt(navigator.appVersion)>=4)
	{
		winleft = (screen.width / 2) - (width / 2);
	}

	if(winleft)
		myFeatures = myFeatures + "left="+winleft+";top="+wintop+";";
	var newWin=window.open(url,windowname, myFeatures);
	newWin.focus();
	newWin.moveTo(winleft,wintop);

	return newWin;
}

function ltrim (s)
{
	return s.replace( /^\s*/, "" );
}

function rtrim (s)
{
	return s.replace( /\s*$/, "" );
}

function trim (s)
{
	return rtrim(ltrim(s));
}

function isTime(text)
{
	var m;
	if ((m = text.match("^([0-2]?[0-9])(:([0-5][0-9]))? ?([AP]M$)")) != null)
	{
		if (m[0] > 12) return false;
		return true;
	}
	else
	return false;
}

function isEmpty(value)
{
	value = value + "";
	if (trim(value) != "")
		return false;
	return true;
}

function isPhone(value,value1,value2)
{
	if (( m =value.match("^\\s*(\\d{3})([-])(\\d{3})\\2((\\d{4})|(\\d{4}))\\s*$")) != null)
		return true;
	return false;
}
function isFax(value)
{
	if (( m =value.match("^\\s*(\\d{3})([-])(\\d{3})\\2((\\d{4})|(\\d{4}))\\s*$")) != null)
		return true;
	return false;
}
function isEmail(value)
{
	if (( m =value.match("^([a-zA-Z0-9])+([.\-_]){0,1}(([a-zA-Z0-9])+([.\-_]([a-zA-Z0-9])+)*)*[@]([a-zA-Z0-9])+[.]([a-zA-Z0-9])+([.]([a-zA-Z0-9])+)*$")) != null)
		return true;
	return false;
}


function isDate(value)
{
	var s = value;
	var m;
	var mon = new Array();
	mon[0]=31;
	mon[1]=29;
	mon[2]=31;
	mon[3]=30;
	mon[4]=31;
	mon[5]=30;
	mon[6]=31;
	mon[7]=31;
	mon[8]=30;
	mon[9]=31;
	mon[10]=30;
	mon[11]=31;
	if (( m =s.match("^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$")) != null)
	{
		var day, month, year;
		day = m[3];
		month = m[1];
		year = m[4];
		if(month > 12) return false;
		if(day > mon[month-1])return false;
		return true;
	}
	else
		return false;
}


function isNotNumber(value)
{
	value = value + "";
	var m = value.match("^\\s*[0-9]*\\s*$");
    if (m == null)
        return true;
	if (isNaN(value))
		return true;
	else if (value < 0)
		return true;
	return false;
}

function isNotNumeric(value)
{
	value = value + "";
	if (value < 0)
		return true;
	if (!isDouble(value))
		return true;
	return false;
}


function isDouble(value)
{
	var m = new Array();
    exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\.(\\d{0,2}))?\\s*$");
    m = value.match(exp);
    if (m == null)
        return false;
    cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
    num = parseFloat(cleanInput);
    return (isNaN(num) ? false : true);
}

// T.Shanmugam - 06/04/2006 - Issue #3426
function changeFocus(formObj,countChars,nextformObj,hidPhoneObj,hidNextPhoneObj)
{
	if(document.getElementById(hidPhoneObj).value != "0")
	{
		if (formObj.value.length == countChars)
		{
			 document.getElementById(nextformObj).focus();
			 document.getElementById(hidNextPhoneObj).value = "1";
			 document.getElementById(nextformObj).value = "";
			 document.getElementById(hidPhoneObj).value = "0";
		}
	}
	else
	{
		formObj.value = "";
		document.getElementById(hidPhoneObj).value = "1";
	}
}



function MEZ(value, retVal)
{
	ret = 0;
	if(retVal){
		ret = retVal;
	}
	if (isEmpty(value))

		return ret;
	else
		return value
}

function roundDecimal(number,decimal_points) {
	if(!decimal_points) return Math.round(number);
	if(number == 0) {
		var decimals = "";
		for(var i=0;i<decimal_points;i++) decimals += "0";
		return "0."+decimals;
	}

	var exponent = Math.pow(10,decimal_points);
	var num = Math.round((number * exponent)).toString();
	return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
}


function setPosition(str)
{
	window.location = window.location + str;
}

function isEmailAddr(str)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr-1){
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr-1){
		return false
	}

		if (str.indexOf(at,(lat+1))!=-1){
		return false
		}

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
		}

		if (str.indexOf(dot,(lat+2))==-1){
		return false
		}

		if (str.indexOf(" ")!=-1){
		return false
		}

 		return true
}

function setSelected(cntl)
{
	var cntlValue = cntl.value;
	cntl.value = "";
	if (document.getSelection) {
	    document.getSelection() = cntl.value;
	  } else if (document.selection && document.selection.createRange) {
	  	  var range = document.selection.createRange();
	  	  range.text = cntlValue;
	  	  range.select();
	  }

}

function getCommaSeparatedString(objcol)
{
	var retStr = "";
	if (objcol.length == 0)
		return retStr;

	retStr = objcol[0];

	for (i=1;i<objcol.length;i++)
	{
		retStr += "," + objcol[i];
	}

	return retStr;
}

// used for showing error messages


function progressbar(startPoint,endPoint,increment)
{
	this.show = progressbar_show;
	this.unload = progressbar_unload;
	this.progress = progressbar_progress;
	this.minLimit = startPoint;
	this.maxLimit = endPoint;
	this.increment = increment;

	var interVals = (endPoint - startPoint)/increment;
	interVals++;
	this.paintIncr = Math.floor(200/interVals);
	this.currentWidth = this.paintIncr;

}

function progressbar_unload()
{
	this.window.close();
}

function progressbar_progress()
{
	this.currentWidth += this.paintIncr;
	this.window.document.getElementById('prgbar').style.width = this.currentWidth+"px";
}
function progressbar_show()
{
	var myFeatures = "";
	var width=200;
	var height = 50;
	var winleft = (screen.width / 2) - (width / 2);
	var wintop = (screen.height / 2) - (height / 2);

	if(parseInt(navigator.appVersion)>=4)
	{
		winleft = (screen.width / 2) - (width / 2);
	}
	myFeatures = 'scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,fullscreen=yes';
	var newWin=window.open("","progress", myFeatures);
	newWin.focus();
	newWin.resizeTo(width,height);
	newWin.moveTo(winleft,wintop);

	// clear the contents

	newWin.document.close();
	newWin.document.open();

	newWin.document.write("<style>");
	newWin.document.write("body{border: 4px solid #0000ff;");
	newWin.document.write("scrollbar-face-color:#ffffff;");
	newWin.document.write("scrollbar-shadow-color: #ffffff;");
	newWin.document.write("scrollbar-highlight-color:#ffffff;");
	newWin.document.write("scrollbar-3dlight-color: #ffffff;");
	newWin.document.write("scrollbar-darkshadow-color: #ffffff;");
	newWin.document.write("scrollbar-track-color:#ffffff;");
	newWin.document.write("scrollbar-arrow-color:#ffffff;}");
	newWin.document.write("</style>");
	newWin.document.write("Please wait.<br>");
	newWin.document.write("<div id='prgbar' style='background-color:#ff9933;width:'"+this.currentWidth+"px;'></div>");

	this.window = newWin;
	return newWin;
}

function IsSameDate(date1, date2)
{
    var diff = date2 - date1;
    return ( (diff == 0)?true:false);
}
