function FromToDateCheck(fromobj,toobj,fromtomessage)
{
	var fromDate = fromobj.getValue().getDate();
	var fromMonth = fromobj.getValue().getMonth()+1;
	var fromYear = fromobj.getValue().getYear();

	var toDate = toobj.getValue().getDate();
	var toMonth = toobj.getValue().getMonth()+1;
	var toYear = toobj.getValue().getYear();

	if (fromDate != "" && toDate != "")
	{
		if (eval(fromYear) > eval(toYear))
		{
			alert(fromtomessage);
			return false;
		}
		else if (eval(fromYear) == eval(toYear) && eval(fromMonth) > eval(toMonth))
		{
			alert(fromtomessage);
			return false;
		}
		else if (eval(fromYear) == eval(toYear) && eval(fromMonth) == eval(toMonth) && eval(fromDate) > eval(toDate))
		{
			alert(fromtomessage);
			return false;
		}
	}
	return true;
}

/*Check half byte characters*/
function checkIsHalfByte(obj,message)
{
	var byteflag;
	var objval = obj.value;
	for (var i = 0; i < objval.length; ++i)
	{
		var c = objval.charCodeAt(i);
		if (c >= 0xff61 && c <= 0xff9f)
		{
			byteflag = "Y";
			break;
		}
	}
	if (byteflag == "Y")
	{
		alert(message);
		obj.focus();
		obj.select();
		byteflag="";
		return false;
	}
	return true;
}

/*Trim Left/Right spaces of a string*/
function Trim(obj)
{
	var objval = obj.value;
	if(objval.length < 1)
	{
		return "";
	}
	objval = RTrim(objval);
	objval = LTrim(objval);
	if(objval=="")
	{
		obj.value = objval;
		return "";
	}
	else
	{
		obj.value = objval;
		return objval;
	}
}

function RTrim(val)
{
	var w_space = String.fromCharCode(32);
	var dw_space = String.fromCharCode(12288);
	var v_length = val.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;
	while(iTemp > -1)
	{
		if(val.charAt(iTemp) == w_space || val.charAt(iTemp) == dw_space){}
		else
		{
			strTemp = val.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	}
	return strTemp;
}

function LTrim(val)
{
	var w_space = String.fromCharCode(32);
	var dw_space = String.fromCharCode(12288);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = val.length;
	var strTemp = "";
	var iTemp = 0;
	while(iTemp < v_length)
	{
		if(val.charAt(iTemp) == w_space || val.charAt(iTemp) == dw_space){}
		else
		{
			strTemp = val.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}

/*Check for special characters*/
function SpecialCharacterCheck(obj,iChars,message)
{
	for (var i = 0; i < obj.value.length; i++)
	{
		if (iChars.indexOf(obj.value.charAt(i)) != -1)
		{
			alert (message + "\n" + iChars);
			obj.focus();
			obj.select();
			return false;
		}
	}
	return true;
}

/*Check maximum number of bytes*/
function CharacterCheck(obj,maxchar,message)
{
	if (obj.value.length > maxchar)
	{
		alert(message);
		obj.focus();
		obj.select();
		return false;
	}
	return true;
}

/*Close window on click of Logout*/
function CloseWindow()
{
	//self.opener = null;
	self.close();
}
function ClearSession()
{
	window.location.href("/ExternalPages/AbandonSession.aspx");
}

/*Give underline effect for Logout link*/
function rollIn(obj)
{
	obj.className = 'logoutunderline';
}

function rollOut(obj)
{
	obj.className = 'logoutnone';
}
/**/

//Open Popup
function openpopup(url, params) 
{
	window.open(url,'',params);
}

/*Png Image*/
function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
window.attachEvent("onload", correctPNG);
/**/

//Global variable declared for SelectBox Tree UI
var MulitpleMasterTableCheck;


/* Start */
// Find the left(x) & top(y) position of Element
function getXYPosition(xy,placeNodeId) {
	var placerObj = document.getElementById(placeNodeId); 
	var rPos=(xy=="x")? placerObj.offsetLeft : placerObj.offsetTop;
	
	if ((placerObj.tagName) && (placerObj.tagName.toUpperCase()=="TABLE") && (placerObj.border)&&(placerObj.border>0)) {
		rPos++;
	}
	var tmpPlacerObj = placerObj.offsetParent;
	while(tmpPlacerObj != null) {
		rPos+=(xy=="x") ? tmpPlacerObj.offsetLeft : tmpPlacerObj.offsetTop;
		if ((tmpPlacerObj.tagName.toUpperCase()=="TABLE") && (tmpPlacerObj.border)&&(tmpPlacerObj.border>0)) {
			rPos++;
		}
		tmpPlacerObj = tmpPlacerObj.offsetParent;
	}
	return rPos;
}
/* End */

/* Start */
// Find the parent object of Element according Tag name
function getParent(el, pTagName) {
	if (el == null) {
		return null;
	}
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) {	// Gecko bug, supposed to be uppercase
		return el;
	}
	else {
		return getParent(el.parentNode, pTagName);
	}
}
/* End */


/* Start */
// Find the parent object of Element according Id
function findParentById(elem, id) { 
	while(isExists(elem)) {
		if(isExists(elem.id) && elem.id.indexOf(id) != -1)
		break; 
		elem = elem.parentElement;
	}
	return elem;
}
function isExists(obj) {
	return null != obj && (typeof(obj) == "string" && obj == "") == false && "undefined" != typeof(obj); 
}
/* End */

function replaceSpaceWithOtherChar(strValue, strReplacer) {
	if(strValue.length < 1) {
		return "";
	}
	else {
		strValue = RTrim(LTrim(strValue));
		var w_space = String.fromCharCode(32);
		var dw_space = String.fromCharCode(12288);
		var rExp_wSpace = new RegExp(w_space +"+","gi");
		var rExp_dwSpace = new RegExp(dw_space +"+","gi");
		
		for(var c=0; c<strValue.length; c++)
		{
			if(strValue.charAt(c) == dw_space)
			{
				strValue = strValue.replace(dw_space,w_space);
			}
		}
		var replacedVal = "";
		replacedVal = strValue.replace(rExp_wSpace, strReplacer);
		replacedVal = replacedVal.replace(rExp_dwSpace, strReplacer);
		return replacedVal;
	}
	
}
function replaceSpaceWithOtherChar2(strValue, strReplacer) {
	var w_space = String.fromCharCode(32);
	var dw_space = String.fromCharCode(12288);
	var strNew = "";
	
	if(strValue.length < 1) {
		return "";
	}
	else {
		strValue = RTrim(LTrim(strValue));
		var matchCount = false;
		for(var c=0; c<strValue.length; c++) {
			if(strValue.charAt(c) == w_space || strValue.charAt(c) == dw_space)
			{
				if(strReplacer != strNew.substr(strNew.length-1, strNew.length))
				{
					strValWithSpace = strValue.substr(c, strValue.length);
					strValWithOfSpace = LTrim(strValWithSpace);
					strNew += strReplacer
					//alert(strNew);
				}
			}
			else {
				var strBeforeSpaceVal = strValue.substr(c, 1);
				strNew += strBeforeSpaceVal;
			}
		}
		return strNew;
	}
}

function dynTransparentPanel(divId) {
	if(document.all == true)return null;
	var existObjTransLayer = document.getElementById("transIframe_"+ divId)
	if(existObjTransLayer)
	{
		return new dynTransparentPanel_setting(existObjTransLayer);
	}
	else
	{
		var transLayer=document.createElement("IFRAME");
		transLayer.id = "transIframe_"+ divId;
		transLayer.style.zIndex=1000;
		transLayer.frameBorder="no";
		transLayer.scrolling="no";
		transLayer.style.filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=0);";
		transLayer.style.visibility='hidden';
		transLayer.style.display='none';
		transLayer.style.position="absolute";
		transLayer.src='javascript:new String("<html></html>")';
		var e = document.body.firstChild;
		document.body.insertBefore(transLayer, e);
		return new dynTransparentPanel_setting(transLayer, divId);
	}
}
function dynTransparentPanel_setting(transLayer, reletiveDivId){
	this.Element=transLayer;
	this.reletiveDivId = reletiveDivId;
	this.show=function(){
		this.Element.style.visibility="visible";
		this.Element.style.display="";
	}
	this.hide=function(){
		this.Element.style.visibility="hidden";
		this.Element.style.display="none";
	}
	this.remove=function(obj){
		document.body.removeChild(obj);
	}
	this.setPosition=function(top,left,width,height){
		this.Element.style.top=top;
		this.Element.style.left=left;
		this.Element.style.width=width;
		this.Element.style.height=height;
	}
}

function findHigherZindex(objSrc, objTransIframe) {
	z=0;
	edit = objSrc;
	tPan = objTransIframe;
	while((edit=edit.parentNode)!=null)if(edit.style!=null)if(edit.style.zIndex>z)z=edit.style.zIndex;
	if(++z>tPan.style.zIndex)tPan.style.zIndex=z;
	return tPan.style.zIndex+1;
}

//To load Correct single png file
function correctSinglePNG(objPngImg) 
{
	var img = objPngImg;
	var imgName = img.src.toUpperCase()
	if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	{
		var imgID = (img.id) ? "id='" + img.id + "' " : ""
		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		var imgStyle = "display:inline-block;" + img.style.cssText 
		if (img.align == "left") imgStyle = "float:left;" + imgStyle
		if (img.align == "right") imgStyle = "float:right;" + imgStyle
		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
		+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		img.outerHTML = strNewHTML
	}
}



//Maximize & minimize General function for Navigation wepparts
function maxminDiv(imageName,divId,btnWPMaximizeStr,btnWPMinimizeStr)
{
	var contentDiv = document.getElementById(divId);
	if (contentDiv.style.display == '')
	{
		contentDiv.style.display = 'none';
		imageName.src = "usercontrols/images/icon_maximizeNew.gif";
		imageName.title = btnWPMaximizeStr;
	}
	else if (contentDiv.style.display == 'none')
	{
		contentDiv.style.display = '';
		imageName.src = "usercontrols/images/icon_minimizeNew.gif";
		imageName.title = btnWPMinimizeStr;
	}
}

//Maximize & minimize General function for Utilities wepparts
/*function maxminutilDiv(imageName,contentdivId,footerdivId)
{
	var contentDiv = document.getElementById(contentdivId);
	var footerDiv = document.getElementById(footerdivId);
	if (contentDiv.style.display == '')
	{
		contentDiv.style.display = 'none';
		footerDiv.style.display = 'none';
		imageName.src = "usercontrols/images/icon_maximizeNew.gif";
	}
	else if (contentDiv.style.display == 'none')
	{
		contentDiv.style.display = '';
		footerDiv.style.display = '';
		imageName.src = "usercontrols/images/icon_minimizeNew.gif";
	}
}*/



function maxminutilDiv(imageName,contentdivId,btnWPMaximizeStr,btnWPMinimizeStr)
{
	var contentDiv = document.getElementById(contentdivId);
	//var footerDiv = document.getElementById(footerdivId);
	if (contentDiv.style.display == '')
	{
		contentDiv.style.display = 'none';
		//footerDiv.style.display = 'none';
		imageName.src = "usercontrols/images/icon_maximizeNew.gif";
		imageName.title = btnWPMaximizeStr;
	}
	else if (contentDiv.style.display == 'none')
	{
		contentDiv.style.display = '';
		//footerDiv.style.display = '';
		imageName.src = "usercontrols/images/icon_minimizeNew.gif";
		imageName.title = btnWPMinimizeStr;
	}
}

// Add by Leo for Mulit-row style
function mulitTRStyle( tableId, startIndex )
{
	var tbl = document.getElementById(tableId);
	alternateTRStyle( tbl, startIndex );
}

// Add by Leo for Mulit-row style
function alternateTRStyle( tbl, startIndex )
{
	if ( tbl == null )
	{
		return;
	}

	var index = 0;
	if ( startIndex != null )
	{
		index = startIndex;
	}

	for( var i = index, j = 0; i < tbl.rows.length; i++ ) 
  	{
		var currentTrDisplay = tbl.rows[ i ].style.display;
		if ( currentTrDisplay != null && currentTrDisplay.toLowerCase() == 'none' )
		{
			continue;
		}
		else
		{
			var mod = j % 2;
			if ( mod == 0 )
			{
				tbl.rows[ i ].className = 'ms-conttableoddtrbg';
			}
			else
			{
				tbl.rows[ i ].className = 'ms-conttableeventrbg';
			}

			j++;
		}
  	}
}

	
/* -- BASE64 Related -- */
/* Added By TonyQ */
/* BEGIN */
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64DecodeChars = new Array(
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);

function base64encode(str) 
{
	if(str)
	{

		//Do convert first for non-ASCII characters	
		str = utf16to8(str);
		//--------------------

		var out, i, len;
		var c1, c2, c3;

		len = str.length;
		i = 0;
		out = "";
		while(i < len) {
	c1 = str.charCodeAt(i++) & 0xff;
	if(i == len)
	{
		out += base64EncodeChars.charAt(c1 >> 2);
		out += base64EncodeChars.charAt((c1 & 0x3) << 4);
		out += "==";
		break;
	}
	c2 = str.charCodeAt(i++);
	if(i == len)
	{
		out += base64EncodeChars.charAt(c1 >> 2);
		out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
		out += base64EncodeChars.charAt((c2 & 0xF) << 2);
		out += "=";
		break;
	}
	c3 = str.charCodeAt(i++);
	out += base64EncodeChars.charAt(c1 >> 2);
	out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
	out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
	out += base64EncodeChars.charAt(c3 & 0x3F);
		}
		return out;
	}
	else
	{
		return "";
	}
}

function base64decode(str)
{
	if(str)
	{
			
		var c1, c2, c3, c4;
		var i, len, out;

		len = str.length;
		i = 0;
		out = "";
		while(i < len)
		{
	/* c1 */
		do{
				c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
			} while(i < len && c1 == -1);
		if(c1 == -1)
			break;

	/* c2 */
		do {
				c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
			} while(i < len && c2 == -1);
		if(c2 == -1)
			break;

		out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));

	/* c3 */
		do {
				c3 = str.charCodeAt(i++) & 0xff;
				if(c3 == 61)
				return out;
				c3 = base64DecodeChars[c3];
			} while(i < len && c3 == -1);
		if(c3 == -1)
			break;

		out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));

	/* c4 */
		do {
			c4 = str.charCodeAt(i++) & 0xff;
			if(c4 == 61)
			return out;
			c4 = base64DecodeChars[c4];
			} while(i < len && c4 == -1);
		if(c4 == -1)
			break;
		out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
		}
		
		
		//Do convert for non-ASCII characters
		return utf8to16(out);
	}
	else
	{
		return "";
	}
}


function utf16to8(str) 
{

    var out, i, len, c;

    out = "";
    len = str.length;
    for(i = 0; i < len; i++) {
 c = str.charCodeAt(i);
 if ((c >= 0x0001) && (c <= 0x007F)) {
     out += str.charAt(i);
 } else if (c > 0x07FF) {
     out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
     out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
     out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
 } else {
     out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
     out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
 }
    }
    return out;
}

function utf8to16(str) 
{
    var out, i, len, c;
    var char2, char3;

    out = "";
    len = str.length;
    i = 0;
    while(i < len) {
 c = str.charCodeAt(i++);
 switch(c >> 4)
 { 
   case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
     // 0xxxxxxx
     out += str.charAt(i-1);
     break;
   case 12: case 13:
     // 110x xxxx   10xx xxxx
     char2 = str.charCodeAt(i++);
     out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
     break;
   case 14:
     // 1110 xxxx  10xx xxxx  10xx xxxx
     char2 = str.charCodeAt(i++);
     char3 = str.charCodeAt(i++);
     out += String.fromCharCode(((c & 0x0F) << 12) |
        ((char2 & 0x3F) << 6) |
        ((char3 & 0x3F) << 0));
     break;
 }
    }

    return out;
}
/* END */
/* -- BASE64 Related -- */
