﻿// JScript File

//    document.onkeydown   = ProcessOnKeyDown;
    document.onmousedown = DisableRigthClick;
	document.onmouseup   = DisableRigthClick;
	    
    //-------------------------------------------------------------------
        
    //Loading images on page load
    function MM_preloadImages()
    { //v3.0
      var d=document;
      if(d.images)
        { 
            if(!d.MM_p)
                d.MM_p=new Array();
            var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
            for(i=0; i<a.length; i++)
                if (a[i].indexOf("#")!=0)
                    { 
                        d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
                    }
        }
    }
    
    //-------------------------------------------------------------------
    
    //Function to Swap two images
    function MM_swapImgRestore() 
    { //v3.0
      var i,x,a=document.MM_sr;
      for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
        x.src=x.oSrc;
    }
    
    //-------------------------------------------------------------------
    
    //Function to Swap image
    function MM_swapImage()
    { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments;
    document.MM_sr=new Array;
    for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null)
            {
                document.MM_sr[j++]=x;
                if(!x.oSrc)
                    x.oSrc=x.src;
                x.src=a[i+2];
            }
    }
	
	//---------------------------------------------------------------------------------------------
   
   	// This function does not allow user to download the image.
	function DisableRigthClick(e) 
	{    
        // Comp#66, Emp#5, 01Dec06 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	    
	    var tag = e ? e.target.tagName : window.event.srcElement.tagName;
						
	    // The image button control finally goes to client side as INPUT tag. 
	    // Image goes as IMG tag.
	    if(tag == 'INPUT' || tag == 'IMG')
	    {
	        var objEvent = e ? e : window.event; 
	        var objSourceElement = e ? e.target : window.event.srcElement; 
		    
		    if ((objEvent.button == 2 || objEvent.button == 3) 
		        && (objSourceElement.type != 'text')) 
		    {			
		        // Comp#66, Emp#5, 01Dec06 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
			
		    //Comp#66, 12May06 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
			
			    alert("Please contact D2U Customer Support.");
			
		    //Comp#66, 12May06 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
						    
			    return false;
		    }
	    }
	    
	    return true;
	}
	
		//---------------------------------------------------------------------------------------------

 
	// cancel return key event for window  
	//to solve problem - when return key is pressed it is redirect to default page
	// comp#5, EmpID=19, 29Nov06
           
//	function ProcessOnKeyDown(e)
//	{
//	    var objEvent = 0; 
//	    if(window.event)// in IE
//	    {
//	        objEvent = window.event;
//	        
//	    }
//	    else  // in FireFox
//		{
//		    objEvent = e; // srcElement not supported. target is supported.
//		    
//		}
//		if(objEvent.keyCode == 13)
//		{
//			objEvent.returnValue=false; 
//			objEvent.cancel = true;
//			
//		}
//	}
	
    // ---------------------------------------------------------------------------------------------
    // Used on :adminchangestoreprofile.aspx,adminlogin.aspx,ClientProfile.aspx,default.aspx,myaccount.aspx
    //          orderinfo.aspx,storesignin.aspx	
	//Trims the given string
	function trim(str)
	{			
		return str.replace(/^\s*|\s*$/g,"");				
	}
	
	 // ---------------------------------------------------------------------------------------------
	
	// Used on :myaccount.aspx,ClientProfile.aspx
	//Returns true if given element's value contains only numbers
	function OnlyNumbers(txtElement)
	{
		var strElementVal = new String();			
		strElementVal = document.getElementById(txtElement).value;		
		
		//regular expresion to accept only letters
		var regExp = /[^\d]/;
		
		//Note: 
		//for Nuimbers only, use RegExp:						/[^\d]/
		//regular expresion to accept letters only, use RegExp:	/[^a-z ]/i;		
		//for Nuimbers & chars only, use RegExp:				/[^a-z\d ]/i
				
		var isValid = !(regExp.test(strElementVal));				
		return isValid;
	}
	
	//---------------------------------------------------------------------------------------------
	// Used on :adminchangestoreprofile.aspx,adminlogin.aspx,ClientProfile.aspx,myaccount.aspx,
	//          orderinfo.aspx,storesignin.aspx
	//Returns true if given element's value contains only letters
	//called on keyUp event	
	function OnlyChars(txtElement)
	{
		var strElementVal = new String();			
		strElementVal = document.getElementById(txtElement).value;		
		
		//regular expresion to accept only letters
		var regExp = /[^a-z ]/i;
		
				
		var isValid = !(regExp.test(strElementVal));				
		return isValid;
	}
		
	//---------------------------------------------------------------------------------------------
	// Used on :adminchangestoreprofile.aspx,ClientProfile.aspx,myaccount.aspx,orderinfo.aspx,storesignin.aspx
	//Avoid spaces
	function CheckSpace( txtElement )
	{
		var strTemp = new String();
		strTemp = document.getElementById(txtElement).value;
	
		var bSpacePresent = false;
		var iCharIdx;
		for( iCharIdx = 0; iCharIdx < strTemp.length; iCharIdx++ )
		{
			if( strTemp.charAt(iCharIdx) == " ")
				bSpacePresent = true;
		}
		if( bSpacePresent )
			return false;
			
		return true;		
	}
	
	//--------------------------------------------------------------------------------------------- 
     // Used on:storesignin.aspx,inputvalidaion.js
	//Email id validation.
	//Comp#66, 14Mar06.
	function ValidateEmailId(txtEmailId)
	{	
		
		document.getElementById(txtEmailId).value = trim(document.getElementById(txtEmailId).value);
				
		if( document.getElementById(txtEmailId).value == "" )
		{
			alert("Please enter email address");
			document.getElementById(txtEmailId).focus();
			return false;
		}
		
		var strEmailId = new String();			
			
		strEmailId = trim(document.getElementById(txtEmailId).value);			
		
		if(strEmailId.length < 1)
		{	
			alert("Please enter your email address");				
			document.getElementById(txtEmailId).focus();
			return false;
		}			
		
		//validation1: Check for '@'
		if(strEmailId.search('@') == -1 )				//|| strEmailId.search('.') == -1)
		{	
			alert("Please enter a valid email address");				
			document.getElementById(txtEmailId).focus();
			return false;
		}		
		
		//validation code updated NOTE:23 Nov 2005	
		
		if( strEmailId.indexOf('.') == -1 || strEmailId.indexOf('.') == 0 ||( (strEmailId.indexOf('.')+ 1) == strEmailId.length ) )
		{
		    alert("Please enter a valid email address");
		   	document.getElementById(txtEmailId).focus();
		  	return false;
		}
		
		if( (strEmailId.charAt(strEmailId.length-4) != '.') && (strEmailId.charAt(strEmailId.length-3) == '.' && strEmailId.charAt(strEmailId.length-6) != '.'))
		{
			alert("Please enter a valid email address");
		   	document.getElementById(txtEmailId).focus();
		  	return false;
		}
		if( (strEmailId.charAt(strEmailId.length-1) == '.') || (strEmailId.charAt(strEmailId.length-2) == '.') )
		{
			alert("Please enter a valid email address");
		   	document.getElementById(txtEmailId).focus();
		  	return false;
		}
		
		var strTest = new String();
		strTest = strEmailId.substring(strEmailId.lastIndexOf('.'),strEmailId.length);
			
		if(strTest.length > 6)
		{
			alert("Please enter a valid email address");
		   	document.getElementById(txtEmailId).focus();
		  	return false;
		} 
		 
		var iIdx = strEmailId.lastIndexOf('@');
		
		if( (strEmailId.charAt(iIdx + 1) == '.') )
		{ 
			alert("Please enter a valid email address");
		   	document.getElementById(txtEmailId).focus();
		  	return false;
		}
	
		
		//Avoid '@' followed by '.'
		if((strEmailId.search('@')+1) == strEmailId.indexOf('.'))
		{	
 			alert("Please enter a valid email address");
		   	document.getElementById(txtEmailId).focus();
		  	return false;
		}	
		
		//Avoid spaces		
		if( !CheckSpace(txtEmailId) )
		{
			alert("Please enter a valid email address");
			document.getElementById(txtEmailId).focus();
			return false;
		}
		
		//@ must not come twice		
		
		//Get the indexOf '@' in iCharIdx1
		var iCharIdx1 = strEmailId.search('@');		
		
		//Get the subString of EmailId starting from char next to '@'
		var strSubStrEmailID = new String();
		strSubStrEmailID = strEmailId.substring(iCharIdx1+1);		
		
		//find the repeating '@' 		
		var iCharIdx2 = strSubStrEmailID.indexOf("@",0);
				
		if( iCharIdx2 > -1)
		{
			//'@' is reapeated
			alert("Please enter a valid email address");
			document.getElementById(txtEmailId).focus();
			return false;
		}		
		
		//Everything validated, continue...	
		
		return true;
	}
	//---------------------------------------------------------------------------------------------
	// Used on:orderlist.aspx,storeorderlist.aspx
	//Check search value entered or not. 
	function ValidateSearchInput()
	{
		if( document.getElementById('txtSearch').value == "")							
		{
			alert("Please enter text to search");
			document.getElementById('txtSearch').focus();
			return false;
		}	
		else
		return true;
	}
	
  
	//-----------------------------------------------------------------------------------------
	// Used on:carddesign.aspx,composeverse.aspx,orderdetails.aspx
	//To display Popup window for Printing only the text contained on the card.
	function OpenPrintCardTextWindow()		 
	{				
		//vTemp is dummy temp variable used while calling showModalDialog()				
		var vTemp = "";
		var retVal = 0;
	
		//dialogWidth:650 & px;dialogHeight: 500 are as per screen ratio
		//param = 0 specifies that session variables 
		//created in Normal user are to be used.
		
		if (window.showModalDialog) // supported by IE
		{
		    window.showModalDialog("Print.aspx?param=0", vTemp, "scroll:yes;resizable:no;dialogWidth:" + 650 + "px;dialogHeight:" + 500 + "px;scrollbars=yes;status=no;center=yes"); 					
		}
		else
		{
		   window.open("Print.aspx?param=0", vTemp, "scroll=yes,resizable=no,width=" + 650 + "px,height=" + 500 + "px,scrollbars=yes,status=no,center=yes"); 					
		}
	}
	
	
	//-----------------------------------------------------------------------------------------
	// used on:preview.aspx,print.aspx
	//Closes the window & returns control back to opener window
	function CloseDialog()
	{
		window.returnValue = false;
		window.close();
	}
		
	//---------------------------------------------------------------------------------------------
	// Used on:carddesignattributes.aspx,composeverse.aspx,default.aspx,myaccount.aspx,speller.aspx
    //Redirect user to shopping cart
    function GotoSCart()
    {
	    location.href = 'SCart1.aspx';
    }		
	    
	//---------------------------------------------------------------------------------------------
	// Used on:carddesignattributes.aspx,composeverse.aspx
    // on page load  sets all lines colors according there content (blank or text)
	function SetLinesColor()
	{
		var txtLineNo ;
		
		
		for(i=24;i>0;i--)
		{
			txtLineNo = "txtLn" + i;		
				
			
			if(document.getElementById(txtLineNo).value == '')
			{
				document.getElementById(txtLineNo).style.background ='#EEEFE9';				
			}				
			else 
			{				
				document.getElementById(txtLineNo).style.background ='#ffffff';								
				return;
			}
		}
	}
	
	//---------------------------------------------------------------------------------------------
	//Used on:carddesignattributes.aspx
	//Give the visual effect of the line format----------------------------------------------------	
	function ApplyLineFormat()
	{
		//Set proper selectedIndex of all the ddlAlign controls of the text lines.
		//The value of alignment is taken from hidden control of the specific line.
		
		//Apply Linewise font to all text lines
		ApplyLinefont();
		
		//Apply Linewise color to all text lines
		ApplyLineColor();
		
		//Apply Linewise Style to all text lines
		ApplyLineStyle();
	}
	
	//---------------------------------------------------------------------------------------------
	// Used on:orderlist.aspx,storeorderlist.aspx
	//Comp#66, 29May06.
	//Enables the button meant for searching because the user needs it
	//when she changes the text in the textBox meant for the search
	//on use of 'tab' key for navigation. 
	function EnableSearch()
	{
		document.getElementById('ibtnSearch').disabled =  false;
	}
	
		
	//-----------------------------------------------------------------------------------------
	// Used on:carddesignattributes.aspx,composeverse.aspx
	// Gives the required key's value from the ParentString. (e.g. Key=Align, Key value=2).
	function GetValueFromKey(v_strParentString, v_strKey)
	{
		// Declare string variables so that we can use string methods.
		var strParentString = new String();
		strParentString     = v_strParentString;		
		
		var strKey  = new String();
		strKey      = v_strKey;		
				
		// find index of key.
		var iIdxOf_Key  = strParentString.indexOf(strKey);					
		var strTemp     = new String();
		strTemp         = strParentString.substr(iIdxOf_Key);		
		
		var iIdxOfDelimiter = strTemp.indexOf(";");				
		
		// Find index of key's value.
		var iStartIdx = parseInt(strKey.length) + 1;
				
		var strValue        = new String();						
		var iSubStringLen   = parseInt(iIdxOfDelimiter) - parseInt(iStartIdx);
		strValue            = strTemp.substr(iStartIdx, iSubStringLen);
		
		return strValue;
	}
	
	
	//---------------------------------------------------------------------------------------------
	// Used on:carddesignattributes.aspx,composeverse.aspx
	//Initializes Empty Line's Hidden control value similar to hdnAllTextAttribs
	//& also sets the selected index of the line drop-down list accordingly.
	//Used by InitializeBody()
	
	function InitializeEmptyLineHidden()
	{
		var iCount; 		
		var sTextName; 
		var txtLinefont;	
	
		//set hidden controls
		for (iCount = 1; iCount < 25; iCount++) 
		{ 
			hdnfontLn = 'hdnfontLn' + iCount; 			
						
			var hdnVal = document.getElementById(hdnfontLn).value;
			if(hdnVal == "")
			{
				//Initialize Empty Line's Hidden control value similar to hdnAllTextAttribs
				document.getElementById(hdnfontLn).value = document.getElementById('hdnAllTextAttribs').value ;				
			
			}
		}
		
	}
	
	
	
	
	//-----------------------------------------------------------------------------------------
	// used on:speller.aspx,carddesignspeller
	// get modified verse text and set text in hidden control variable
	function GetModifiedText()
	{
		var iEleCount = document.forms[0].elements.length;
		var textLine = new String();
		var textAllLines = new Array();
		textLine ='';
		
		for (var iCount = 0; iCount < 24; iCount++)
		{
			var strCnt = new String();
			strCnt = iCount;
			var hiddenLine = "hdnLn" + strCnt;
			document.getElementById(hiddenLine).value = "";
		}
		for (var iCount = 0; iCount < iEleCount; iCount++)
		{
			var ele = document.forms[0].elements[iCount];
			var strEleId = new String();
			strEleId = ele.id;																			
			
			//Get only our dynamic controls
			var strPrefix = 0;
			strPrefix =  strEleId.indexOf('Splr',0);	
										
			if( strPrefix > 1)
			{
				var strText = new String();
				strText = strEleId.slice(0,strEleId.indexOf('id'));	
				var LineNo = strText.slice( strText.indexOf("Splr",0) + 4 ,strText.length);
				var hiddenLine = "hdnLn" + LineNo;
				document.getElementById(hiddenLine).value += ele.value;
				
			}
		}
	}	
	
	//-----------------------------------------------------------------------------------------
	// used on:speller.aspx,carddesignspeller
	//On change of suggestions Drop down list set selected text to text box
	function OnSuggestionChange(theSelect, changeToFieldName) 
	{
		var i = theSelect.selectedIndex;
		document.getElementById(changeToFieldName).value = theSelect.options[i].text;
	}
	
	//-----------------------------------------------------------------------------------------
		
	//Confirms whether to overwrite the card while saving.
	//This confirmation is required while saving an existing card after editing it.
	//Client is asked for the confirmation if the client is saving the card after editing it.
	//This is ubderstood from 'hdnEditingSavedCard' control.
	//Sets the return value in 'hdnOverwriteSavedCard' control.
	//This function is called on form_Submit() event.
	//Comp#66, 03Mar06.
	function ConfirmOverwrite()
	{					
		var strEditingSavedCard = false;
		strEditingSavedCard = document.getElementById('hdnEditingSavedCard').value;
	
		if(strEditingSavedCard == null)
		{
			//Exception situation. Go to make a copy.
			return true;
		}
			
		if(strEditingSavedCard == "false")
		{
			//Not editing a saved card. 
			return true;
		}
		
		var bOverwriteSavedCard = confirm("You are about to save a card.\nDo you want to overwrite the existing card?\n\nClick 'OK' to overwrite or click 'Cancel' to save a copy.");
		if(bOverwriteSavedCard == true)
		{
			//User wants to overwrite the existing card.
			document.getElementById("hdnOverwriteSavedCard").value = "true";
		}
		else
		{
			//User wants to save a copy of the existing card.
			document.getElementById("hdnOverwriteSavedCard").value = "false";
		}
		
		return true;
	}
	
	 //---------------------------------------------------------------------------------------------
	// Used on:default.aspx,orderdetails.aspx,scart1.aspx
	// Stops Form Submission required if wrong input.
    function StopFormSubmission()
    {
        form = document.forms[0];
        addEvent(form, "submit", cancel);
    }
    
    
    //---------------------------------------------------------------------------------------------
    // Used on:default.aspx,orderdetails.aspx,scart1.aspx
    // Allows Form-Submission. Required if wrong input.
    function StartFormSubmission()
    {
        form = document.forms[0];
        removeEvent(form, "submit", cancel);
    }
    
    //---------------------------------------------------------------------------------------------
    // Used on:default.aspx,orderdetails.aspx,scart1.aspx
    // Helps to remove eventListner useful to Start/Stop Form-Submission, etc.
    function removeEvent(obj, evType, fn)
    {
        if (obj.removeEventListener)
        {        
            obj.removeEventListener(evType, fn, false);
            return true;
        }
        else if (obj.detachEvent)
        {
            var r = obj.detachEvent("on"+evType, fn);
            return r;
        }
        else
        {
            return false;
        }
    }
    
     //---------------------------------------------------------------------------------------------
     // Used on:default.aspx,orderdetails.aspx,scart1.aspx
     // Prevents Form-Submission. Required if wrong input.
    function cancel(e)
    {
        if (e && e.preventDefault)
        {
            // DOM style
            e.preventDefault(); 
        }
        
        // IE style  
        return false; 
    }
    
	
    // Used on :adminchangestoreprofile.aspx, adminlogin.aspx,ClientProfile.aspx,index.html,storesignin.aspx
    // Cancel the event (after it is handled).
    function stopEvent(e) 
    {
        var objEvent = e ? e : window.event;  
         
        if(objEvent.preventDefault)
        {
            objEvent.stopPropagation();
            objEvent.preventDefault();
        }    
        else
        {            
            objEvent.cancelBubble = true;
            objEvent.returnValue = false;
            
            return false;
        }
    }
    
    // ---------------------------------------------------------------------------------------------
   
    // Used on :adminchangestoreprofile.aspx,adminlogin.aspx,ClientProfile.aspx,index.html,storesignin.aspx
    // Add eventListner to the given object.
    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] );
        }
    }
    
    //-------------------------------------------------------------------
	//Displays Movie.htm which shows the demo movie
	function DisplayModalMovie()
	{
	    //Dummy variable used for showModalDialog method
		var vTemp = "";	
		var retVal;
		var Style = new String();
		// comp#5, EmpID=19, 27Nov06
		// checking window.showModalDialog is supported by browser
		if (window.showModalDialog) 
		    retVal = window.showModalDialog("Movie.htm", vTemp,"resizable:no;dialogWidth:600px;dialogHeight:425px;scrollbars=no;status=no;center=yes"); 		
		else
		    retVal = window.open("Movie.htm", vTemp,"width=580px,height=400px,toolbar=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,center=yes,dialog=yes,modal=yes");
    }	
	//---------------------------------------------------------------------------------------------
  function setHourglass()
  {
    document.body.style.cursor = 'wait';
  }
  
  //---------------------------------------------------------------------------------------------
  function setNormalCursor()
  {
        document.body.style.cursor = 'default';
  }
  
  //---------------------------------------------------------------------------------------------
  
    function SetZoom()
    {
        var viewportwidth;
        var viewportheight;
    
        // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
        if (typeof window.innerWidth != 'undefined')
        {
            viewportwidth = window.innerWidth,
            viewportheight = window.innerHeight
        }

        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
        else if (typeof document.documentElement !=
                'undefined'&& typeof document.documentElement.clientWidth !=
                'undefined' && document.documentElement.clientWidth != 0)
        {
            viewportwidth = document.documentElement.clientWidth,
            viewportheight = document.documentElement.clientHeight
        }
        // older versions of IE
        else
        {
            viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
            viewportheight = document.getElementsByTagName('body')[0].clientHeight
        }
        
        //Get Screen Height & Width as per resolution    
        //var x = screen.width;
        //var y = screen.height; 
    
        if(navigator.appName == "Microsoft Internet Explorer")
        {
            //Reset the zoom to default.
            //window.parent.document.body.style.zoom = 0;
            //window.parent.document.body.style.zoom = 2.8;            
            //parent.parent.document.all.D2UBody.style.zoom = 1.5;            
        }
    
        if(navigator.appName == "Netscape")
        {
            //var zoomFact = viewportheight/757;
            //alert("Your view port is " + viewportwidth + " by " +  viewportheight + " & zoom factor is " + zoomFact + ".");
            
            //Check if user has enabled AutoZoom feature.
            var AutoZoom =  GetCookie("AutoZoom");
            if (AutoZoom != 0)
            {
                var lPos = getAbsX(document.getElementById("CopyrightBand"));
                var tPos = getAbsY(document.getElementById("CopyrightBand"));
                //parent.parent.document.body.style.zoom = viewportheight/tPos;
                window.parent.document.body.style.zoom = viewportheight/tPos + '%';
                
                //Check if the rendered page has a Vertical Scroll bar
//                var hasVScroll = document.body.scrollHeight > document.body.clientHeight;
//                if (hasVScroll)
//                alert("There is a Vertical scroll here.");
//                else
//                alert("There is No Vertical scroll here.");
                
                //Check if the rendered page has a Horizontal Scroll bar
//                var hasHScroll = document.body.scrollWidth > document.body.clientHeight;
//                if (hasHScroll)
//                alert("There is a Horizontal scroll here.");
//                else
//                alert("There is No Horizontal scroll here.");
            }
            else
            {
                parent.parent.document.body.style.zoom = '100%';
                
                //Check if the rendered page has a Vertical Scroll bar
//                var hasVScroll = document.body.scrollHeight > document.body.clientHeight;
//                if (hasVScroll)
//                alert("There is a Vertical scroll here.");
//                else
//                alert("There is No Vertical scroll here.");
                
                //Check if the rendered page has a Horizontal Scroll bar
//                var hasHScroll = document.body.scrollWidth > document.body.clientHeight;
//                if (hasHScroll)
//                alert("There is a Horizontal scroll here.");
//                else
//                alert("There is No Horizontal scroll here.");
            }
        }
   }   
   //---------------------------------------------------------------------------------------------   
   //The function is retrieve specific cookie from the client's browser.
   
   function GetCookie (name)
   {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            {
                return getCookieVal (j);
            }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return null;
  }

//---------------------------------------------------------------------------------------------   
//The function is retrieve specific cookie value from the client's browser.
   
function getCookieVal (offset)
{
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  {
    endstr = document.cookie.length;
  }
  return unescape(document.cookie.substring(offset, endstr));
}

//---------------------------------------------------------------------------------------------   
//The function sets specific cookie value to the client's browser.

function SetCookie ()
{
    var AutoZoom =  GetCookie("AutoZoom");
    var expdate = new Date();
    expdate.setTime(expdate.getTime() + 180 * 3600 * 24000);
    
    if (AutoZoom != 0)
    {
        ZFVal = 0;
        document.cookie = "AutoZoom=" + escape(ZFVal) + "; expires=" + expdate.toGMTString()+ "; path=/;";
        
        //Check if the rendered page has a Vertical Scroll bar
//        var hasVScroll = document.body.scrollHeight > document.body.clientHeight;
//        if (hasVScroll)
//        alert("There is a Vertical scroll here.");
//        else
//        alert("There is No Vertical scroll here.");
        
        //Check if the rendered page has a Horizontal Scroll bar
//        var hasHScroll = document.body.scrollWidth > document.body.clientHeight;
//        if (hasVScroll)
//        alert("There is a Horizontal scroll here.");
//        else
//        alert("There is No Horizontal scroll here.");
    }
    
    else
    {
        ZFVal = 1;
        document.cookie = "AutoZoom=" + escape(ZFVal) + "; expires=" + expdate.toGMTString()+ "; path=/;";
        
        //Check if the rendered page has a Vertical Scroll bar
//        var hasVScroll = document.body.scrollHeight > document.body.clientHeight;
//        if (hasVScroll)
//        alert("There is a Vertical scroll here.");
//        else
//        alert("There is No Vertical scroll here.");
        
        //Check if the rendered page has a Horizontal Scroll bar
//        var hasHScroll = document.body.scrollWidth > document.body.clientWidth;
//        if (hasVScroll)
//        alert("There is a Horizontal scroll here.");
//        else
//        alert("There is No Horizontal scroll here.");
    }        
}

//---------------------------------------------------------------------------------------------
    //Find The Left Position And Top Position Of Parent Div    
    function getAbsPos(elt, which) 
    {
        iPos = 0;
        while (elt != null) 
        {
        iPos += elt["offset" + which];
        elt = elt.offsetParent;
        }
        return iPos;
    }
    //---------------------------------------------------------------------------------------------
    //Function returns the X Position of the element sent as parameter
    function getAbsX(elt) 
    { 
        return (elt.x) ? elt.x : getAbsPos(elt, "Left"); 
    }
    
    //---------------------------------------------------------------------------------------------
    //Function returns the X Position of the element sent as parameter
    function getAbsY(elt) 
    { 
        return (elt.y) ? elt.y : getAbsPos(elt, "Top"); 
    }
    //---------------------------------------------------------------------------------------------
