/* $$$ Global funuction to Select left menu : Start $$$ */
function setLeftMnuSelected(mnuObj)
{
    clearLeftbMenu(mnuObj);
    var menuObj=document.getElementById(mnuObj);
    menuObj.className='selected';
}

function clearLeftbMenu(mnuObj)
{
    var menuObj=document.getElementById(mnuObj);            
    var subMenu = document.getElementById(menuObj.parentNode.id);
    var liObj = subMenu.getElementsByTagName("li");            
    var i;
    for(i=0; i<liObj.length; i++){
        liObj[i].className = '';
    }
}

/* $$$ Global funuction to Select left menu : End $$$ */

/* $$$ Global funuction to clear/reset form values : Start $$$ 
   "objElement" = accept form level html control ID as string value i.e. table/DIV etc
*/

function resetForm(objElement)
{   
    var obj=document.getElementById(objElement);
    
    if(objElement)
    {
        var objInput = obj.getElementsByTagName("input");
        var objTextArea = obj.getElementsByTagName("textarea");
        var objDDL = obj.getElementsByTagName("select");
        var z = 0;

        //Clearing Input Controls
        if(objInput.length > 0)
        {
            for(z=0; z<objInput.length;z++)
            {
                if(objInput[z].type == 'text')
                {
                    objInput[z].value="";
                }
                if(objInput[z].type == 'checkbox')
                {
                    objInput[z].checked=false;
                }
                if(objInput[z].type == 'radio')
                {
                    objInput[z].checked=false;
                }
             }
        }
        
        //Clearing Textarea
        if(objTextArea.length > 0)
        {
            for(ta=0; ta<objTextArea.length;ta++)
            {
                if(objTextArea[ta].type == 'textarea')
                {
                    objTextArea[ta].value='';
                }            
             }
        }
        
        //Clearing DDL(s)
        if(objDDL.length > 0)
        {
            for(j=0; j<objDDL.length;j++)
            {
                if(objDDL[j].type == 'select-one')
                {
                    objDDL[j].selectedIndex =0;
                }            
             }
        }
    }    
}
/* $$$ Global funuction to clear/reset form values : End $$$ */

function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() {obj["e"+type+fn]( window.event  ); 
		}
		obj.attachEvent("on"+type, obj[type+fn]);
	} 
}	

/* $$$ Global funuction Set onBlur Event on input type and other : Start $$$*/

function setOnBlur()
{   
    if(document)
    {
        var objInput = document.getElementsByTagName("input");
        var objTextArea = document.getElementsByTagName("textarea");
        var objDDL = document.getElementsByTagName("select");
        var z = 0;

        //Input Controls
        if(objInput.length > 0)
        {
            for(z=0; z<objInput.length;z++)
            {
                if(objInput[z].type == 'text')
                {
                    objInput[z].onblur=new Function("hideAlert();");
                }
                if(objInput[z].type == 'checkbox')
                {
                    objInput[z].onblur=new Function("hideAlert();");
                }
                if(objInput[z].type == 'radio')
                {
                    objInput[z].onblur=new Function("hideAlert();");
                }
             }
        }
        
        //Textarea
        if(objTextArea.length > 0)
        {
            for(ta=0; ta<objTextArea.length;ta++)
            {
                if(objTextArea[ta].type == 'textarea')
                {
                    objTextArea[ta].onblur=new Function("hideAlert();");
                }            
             }
        }
        
        //Setting for DDL(s)
        if(objDDL.length > 0)
        {
            for(j=0; j<objDDL.length;j++)
            {
                if(objDDL[j].type == 'select-one')
                {
                    objDDL[j].onblur=new Function("hideAlert();");
                }            
             }
        }
        
        /*Setting for Anchor Elements
        if(objAnc.length > 0)
        {
            for(j=0; j<objAnc.length;j++)
            {   
                objAnc[j].onblur=new Function("hideAlert();");
             }
        }*/
    }    
}
/* $$$ Global funuction to Set onBlur Event on input type and other : End $$$ */

//cntMax textbox
// Function For Get Ket Value
function getkey(e)
		{
			if (window.event)
				return window.event.keyCode;
			else if (e)
				return e.which;
			else
				return null;
		}
		
// function End

// function for counting & restricting characters in textarea
function setmaxch(id, noOfChar)
{
	if (id.value.length >= noOfChar)
	{
	    //alert(txtDec.value.length);
		id.value = id.value.substring(0, noOfChar);
	}
}				
function fnChar(maxval,objid,txtcnt)
{	
	var tot=maxval;
	var l=(objid.value).length;
	//alert(l);
	//l = l + 1;
	if(l<=maxval)
	{
	    txtcnt.value= tot-l;
	}
	else
	{
	    //alert("Input cannot exceed "+maxval+" characters.\n");
	    //alert(maxval);
	    setmaxch(objid,maxval);
	    txtcnt.value=  maxval-(objid.value).length;
	    objid.focus();
	}
	//alert(l);
	return true;
}     
//cntMax

function stripe() {
	var ids = document.getElementsByTagName("table");
	for(k = 0;k < ids.length; k++){
		var id = ids[k].id;		
		if(id){	
			var table = document.getElementById(id);
			var rows = table.getElementsByTagName("tr");	
			for(i = 0; i < rows.length; i++){
				if(rows[i].className == "" ) {
				    sRc = (i % 2 == 0) ? "even":"odd";
					rows[i].className = sRc;
				}
				else
				{
				    break;
				}
				if(rows[i].parentNode.nodeName=='TBODY') {
					rows[i].onmouseover = function() {this.className='ruled';return false}
					if (i % 2 == 0) {
						rows[i].onmouseout = function() {this.className= "even"; return false}
					} else {
						rows[i].onmouseout = function() {this.className= "odd"; return false}
					}
				}
			}
		}
	}
}	

//addEvent(window,"load", stripe);

function init_fields()
{
	var el, els, e, f = 0, form, forms = document.getElementsByTagName('form');
	while (form = forms.item(f++))
	{
		e = 0; els = form.getElementsByTagName('input');
		while (el = els.item(e++))
			if (el.readOnly)
				el.className = 'readonly';
	}
}

init_fields();

// Check whether string s is empty.
var whitespace = " \t\n\r";
function isEmpty(s)
{ 
    return ((s == null) || (s.length == 0)) 
}

// function to check all the entered values are characters only

function isAlphaNumeric(objValue)
{	
//    alert(objValue);

			var characters="' -_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#*$&^()-[].,/\r\n"
			//var characters=" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$&*()_+=';.,}{[]\\\/-: \"| > < `"
			var tmp
			var lTag
			lTag = 0
			temp = (objValue.length)
			for (var i=0;i<temp;i++)
			{
				tmp=objValue.substring(i,i+1)
				if (characters.indexOf(tmp)==-1)
				{
					lTag = 1     
				}
			}
			if(lTag == 1)
				return false
			else
				return true
	
}

function fnOpenPopup(txt)
{
	document.getElementById('popup_' + txt).style.display='block';
}

function fnClosePopup(txt){
	document.getElementById('popup_' + txt).style.display='none';
}

function checkUncheckAll(obj) {
	var theForm = obj.form, i = 0;
	for(i=0; i<theForm.length;i++){
    if(theForm[i].type == 'checkbox' && theForm[i].name != 'chkSelectAll'){
	  theForm[i].checked = obj.checked;
	  }
     }
    }

/*To Open Window in center */
function wopen(url, name, w, h)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=1, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}

/* Change Tab selection : Start */
function fnSelectTab(objTab)
    {   
        /* Clear All class of li: DONOT MODIFY BELOW THIS LINE */
        var p = document.getElementById("tabMenu");	
        var objLI = p.getElementsByTagName("li");
        var j;		

        for(j=0; j<objLI.length; j++){
	        objLI[j].className = '';
        }
        
        /* Applay Class to selected tab */
        var parent = objTab;      
        parent.className="currentTab";
    }
/* Change Tab selection : End */    

function fnHideShow(clientID, type)
{           
    try
    { 
        arrVal = clientID.split("#");
        if(type == '0') // MouseOver effect
        {   
            for(i=0; i<=arrVal.length; i++)
            {
                document.getElementById(arrVal[i]).className = "hightlighrow";
            }         
        }
        else // MouseOut effect
        {   
            for(i=0; i<=arrVal.length; i++)
            {
                document.getElementById(arrVal[i]).className = "normalrow";
            }
        }
    } 
    catch(e) {} 
}

/* Alert Div : Start */
function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}
function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}

function showAlert(sMsg, sControl)
{
    document.getElementById('errorMsg').innerHTML = '<img src=\'../res/images/dnarrow_ani.gif\' align=\'middle\' alt=\'\' title=\'\'>'+ sMsg;
    document.getElementById('alertMsg').style.left  = (getAbsoluteLeft(sControl) + (document.getElementById(sControl).offsetWidth - 20)) +'px';
    document.getElementById('alertMsg').style.top = (getAbsoluteTop(sControl) - 15) + 'px';
    document.getElementById('alertMsg').style.display = 'block';
}
function showAlertrpt(sMsg, sControl)
{
    document.getElementById('errorMsg').innerHTML = '<img src=\'../../res/images/dnarrow_ani.gif\' align=\'middle\' alt=\'\' title=\'\'>'+ sMsg;
    document.getElementById('alertMsg').style.left  = (getAbsoluteLeft(sControl) + (document.getElementById(sControl).offsetWidth - 20)) +'px';
    document.getElementById('alertMsg').style.top = (getAbsoluteTop(sControl) - 15) + 'px';
    document.getElementById('alertMsg').style.display = 'block';
}
function hideAlert()
{
    document.getElementById('errorMsg').innerHTML = '';
    document.getElementById('alertMsg').style.display = 'none';
}
function hideAlertTimer()
{
    var hideAlert = setTimeout(hideAlert(),1000);
}
function showAlertRoot(sMsg, sControl)
{
    document.getElementById('errorMsg').innerHTML = '<img src=\'res/images/dnarrow_ani.gif\' align=\'middle\' alt=\'\' title=\'\'>'+ sMsg;
    document.getElementById('alertMsg').style.left  = (getAbsoluteLeft(sControl) + (document.getElementById(sControl).offsetWidth - 20)) +'px';
    document.getElementById('alertMsg').style.top = (getAbsoluteTop(sControl) - 15) + 'px';
    document.getElementById('alertMsg').style.display = 'block';
}
/* Alert Div : End */


/* Check Cookies are enable : Start */
function checkcookiesupport()
{
    var status;
    if(navigator.cookieEnabled)
        status=true;
    else
        status=false;
    
    if (typeof navigator.cookieEnabled=="undefined" && !status)
    { 
        document.cookie="wazzup"
        if(document.cookie.indexOf("wazzup")!=-1)
            status=true;
        else
            status=false;
    }
    return status;
}
/* Check Cookies are enable : End */

function DateDiff(CntrlObjectCheck,CntrlObjectWith)
{
    var strCntrlObjCheck = CntrlObjectCheck;
    var strCntrlObjWith = CntrlObjectWith;
      
    var strSplitCntrlObjCheck = strCntrlObjCheck.split("/");
    var strSplitCntrlObjWith = strCntrlObjWith.split("/");
    var flgIsInvalid = "0";
	

    /*If the Years are equal then only check for the month*/
    if(parseInt(strSplitCntrlObjCheck[2],10) > parseInt(strSplitCntrlObjWith[2],10))
    {
	    flgIsInvalid = "1";
    }
    else
    {	
	    /* If the months are equal then only check for the Day*/
	    if(parseInt(strSplitCntrlObjCheck[2],10) == parseInt(strSplitCntrlObjWith[2],10))
	    {
		    if(parseInt(strSplitCntrlObjCheck[0],10) > parseInt(strSplitCntrlObjWith[0],10))
		    {
			    flgIsInvalid = "1";
		    }
		    else
		    {
			    /* Check for the day */
			    if(parseInt(strSplitCntrlObjCheck[0],10) == parseInt(strSplitCntrlObjWith[0],10))
			    {
				    if(parseInt(strSplitCntrlObjCheck[1],10) > parseInt(strSplitCntrlObjWith[1],10))
				    {
					    flgIsInvalid = "1";
				    }
			    }
		    }
	    }
    }    	
    if(flgIsInvalid == "1")
    {
	    return false;			
    }
} 
