﻿/*--==========================================================================================
 Project              : Aegis
 File Name            : GeneralFunctions.js
 Program Description  : Javascript file Which Contains Generalized function for Aegis
 Programmed By        : Robins
 Programmed On        : 18-Feb-2009. 
 Modification History :
==========================================================================================--*/

var _varGlbMouseX = 0;
var _varGlbMouseY = 0;


/*Kumar Rakesh March17 2009*/
// Start :// Function for compatibility in mozilla:equivalent to innerText in IE// 
 	var isIEBrowser = (window.navigator.userAgent.indexOf("MSIE") > 0);
	if (! isIEBrowser) {
  		HTMLElement.prototype.__defineGetter__("innerText", 
              function () { return(this.textContent); });
  		HTMLElement.prototype.__defineSetter__("innerText", 
              function (txt) { this.textContent = txt; });
	}
 // End :// Function for compatibility in mozilla:equivalent to innerText in IE// 
 
 

// Start : Function for detecting the browser 
        var browser   = '';
        var idxOfMSIE = '';
        var isIEBrowser = '';
        var IEversion = '';
        // BROWSER?
        if (browser == ''){
        if (navigator.appName.indexOf('Microsoft') != -1)
        browser = 'IE'
        else if (navigator.appName.indexOf('Netscape') != -1)
        browser = 'Netscape'
        else browser = 'IE';
        }
                        
        isIEBrowser = window.navigator.userAgent.indexOf("MSIE");
        if(isIEBrowser){ 
                        if (IEversion == ''){
                        var idxOfMSIE = window.navigator.userAgent.indexOf("MSIE"); 
                        IEversion = navigator.appVersion.substring(idxOfMSIE,idxOfMSIE-3);
                        //alert('IEversion:'+IEversion);        
                        }
        }
// End : Function for detecting the browser 


/*Kumar Rakesh March17 2009 END*/





function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}	


/*
*   Created By  :   SubrataM
*   Created On  :   26/02/2009
*   Purpose     :   Used while opening a Modal/Popup Window
*/

function openMyWindow( pageToLoad, winName, width, height, center)
{
     xposition=0; yposition=0;
     if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
         xposition = (screen.width - width) / 2;
         yposition = (screen.height - height) / 2;
     }
 	
    var args = "";
    	args += "width=" + width + "," + "height=" + height + ","
		+ "location=0,"
		+ "menubar=0,"
		+ "resizable=0,"
		+ "scrollbars=0,"
		+ "statusbar=false,dependent,alwaysraised,"
		+ "status=false,"
		+ "titlebar=no,"
		+ "toolbar=0,"
		+ "hotkeys=0,"
		+ "screenx=" + xposition + ","  //NN Only
		+ "screeny=" + yposition + ","  //NN Only
		+ "left=" + xposition + ","     //IE Only
		+ "top=" + yposition;           //IE Only
		//fullscreen=yes, add for full screen
    	var dmcaWin = window.open(pageToLoad,winName,args );
    	dmcaWin.focus();
    //window.showModalDialog(pageToLoad,"","dialogWidth:650px;dialogHeight:500px");
}




//Kumar Rakesh :: 27/02/2009 
//Description:: These function gives you the tpo-left corner of the element whose id is passed
var ProductX = 0;
var ProductY = 0;
//Function:Find Absolute Positioning of Div
function findPosX(obj)
  {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft; 
  }

function findPosY(obj)
  {
	 var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
		return curtop; 
  }
//End Function

//Start Trim Function

function trimAll(sString) 
{
    while (sString.substring(0,1) == ' ')
    {
    sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
    sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

//End Function

//Start IsNumeric Function

function IsNumeric(sText)
{
   
    var ValidChars = "0123456789";
    var IsNumber=true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
    return IsNumber;
}

//End IsNumeric Function

//Start Valid Mail function

function isValidEmail(str) {
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

//End Valid Mail Function




/*Rakesh :: 07/03/200 :::For Tabs START*/
function ChangeImg(id, TotalTabs)
{

	document.getElementById('tdLeftCat' + id).innerHTML = '<img src="Images/tab_clkl.gif" width="11" height="28" />';
	document.getElementById('tdCenterCat' + id).style.backgroundImage = 'url(Images/tab_clkb.gif)';
	document.getElementById('tdRightCat' + id).innerHTML = '<img src="Images/tab_clkr.gif" width="11" height="28" />';
	if (document.getElementById('tdLeftCat' + 7) != null && TotalTabs == 6) {
	    TotalTabs = parseInt(TotalTabs, 10) + 2; //Adding 2 for JSD and JSDdef tabs
	}
	for(var i=1;i<=TotalTabs;i++)
	{
		if(i != id)
		{
			document.getElementById('tdLeftCat' + i).innerHTML = '<img src="Images/tab_norl.gif" width="11" height="28" />';
			document.getElementById('tdCenterCat' + i).style.backgroundImage = 'url(Images/tab_norb.gif)';
			document.getElementById('tdRightCat' + i).innerHTML = '<img src="Images/tab_norr.gif" width="11" height="28" />';
		}
	}
}


function FunctMouseOver(id)
{
	
	if(document.getElementById('tdCenterCat' + id).style.backgroundImage != 'url(Images/tab_clkb.gif)')
	{
		document.getElementById('tdLeftCat' + id).innerHTML = '<img src="Images/tab_hovl.gif" width="11" height="28" />';
		document.getElementById('tdCenterCat' + id).style.backgroundImage = 'url(Images/tab_hovb.gif)';
		document.getElementById('tdRightCat' + id).innerHTML = '<img src="Images/tab_hovr.gif" width="11" height="28" />';
	}
	
}

function FunctMouseOut(id)
{

	if(document.getElementById('tdCenterCat' + id).style.backgroundImage != 'url(Images/tab_clkb.gif)')
	{
		document.getElementById('tdLeftCat' + id).innerHTML = '<img src="Images/tab_norl.gif" width="11" height="28" />';
		document.getElementById('tdCenterCat' + id).style.backgroundImage = 'url(Images/tab_norb.gif)';
		document.getElementById('tdRightCat' + id).innerHTML = '<img src="Images/tab_norr.gif" width="11" height="28" />';
	}
}
/*Rakesh :: 07/03/200 :::For Tabs END*/

/*DharmendraS :: 22/04/2009 :::For Tabs START on SubFactor Detail */
function ChangeImgSubFactor(id, TotalTabs)
{

	document.getElementById('tdLeftCat' + id).innerHTML = '<img src="Images/tab_clkl.gif" width="11" height="28" />';
	document.getElementById('tdCenterCat' + id).style.backgroundImage = 'url(Images/tab_clkb.gif)';
	document.getElementById('tdRightCat' + id).innerHTML = '<img src="Images/tab_clkr.gif" width="11" height="28" />';
	for(var i=0;i<=TotalTabs;i++)
	{
		if(i != id)
		{
			document.getElementById('tdLeftCat' + i).innerHTML = '<img src="Images/tab_norl.gif" width="11" height="28" />';
			document.getElementById('tdCenterCat' + i).style.backgroundImage = 'url(Images/tab_norb.gif)';
			document.getElementById('tdRightCat' + i).innerHTML = '<img src="Images/tab_norr.gif" width="11" height="28" />';
		}
	}
}


function FindMousePos(e)
{ 
    
    //get the mouse coordinates 
    // Detect if the browser is IE or not.
    // If it is not IE, we assume that the browser is NS.
    if(!e)e = window.event;
    if (e.clientX) { // grab the x-y pos.s if browser is IE
        tempX = e.clientX + (document.documentElement.scrollLeft ?
        document.documentElement.scrollLeft :
        document.body.scrollLeft);
        
        tempY = e.clientY + (document.documentElement.scrollTop ?
        document.documentElement.scrollTop :
        document.body.scrollTop);
    } else  if (e.pageX) {  // grab the x-y pos.s if browser is NS
        tempX = e.pageX;
        tempY = e.pageY;
    }  
            
    // catch possible negative values in NS4
    if (tempX < 0){tempX = 0}
    if (tempY < 0){tempY = 0}  
    
    _varGlbMouseX = tempX;
    _varGlbMouseY = tempY;
            
} 

/* Added By :: SubrataM for Restricting the user from entering More then the specified length
in the TextArea*/
var TextAreaMaxLengthCheck=function(id,length)
{  
    //alert('Hi');
    length = length-1;
    var val = document.getElementById(id).value;
    if(val.length <= length)
        return true;
    else
    {
        document.getElementById(id).value = val.substring(0, length);
        //alert('Max Length Reached');
    }
}

