﻿var Keys = {
     BACKSPACE: 8,          TAB: 9,               ENTER: 13,          SHIFT: 16,
     CTRL: 17,               ALT: 18,          PAUSE: 19,          CAPS: 20,
     ESC: 27,                PAGEUP: 33,      PAGEDN: 34,      END: 35,
     HOME: 36,               LEFT: 37,           UP: 38,           RIGHT: 39,
     DOWN: 40,               INSERT: 45,      DELETE: 46,      
     n0: 48,     n1: 49, n2: 50, n3: 51, n4: 52, 
     n5: 53, n6: 54,     n7: 55,     n8: 56,     n9: 57,
     A:65, B:66, C:67, D:68, E:68, F:70, G:71, H:72, I:73, J:74, K:75,
     L:76, M:77, N:78, O:79, P:80, Q:81, R:82, S:83, T:84, U:85, V:86,
     W:87, X:88, Y:89, Z:90,
     WINLEFT: 91,           WINRIGHT: 92,     SELECT: 93,      NUM0: 96,
     NUM1: 97,                NUM2: 98,           NUM3: 99,           NUM4: 100,
     NUM5: 101,                NUM6: 102,           NUM7: 103,           NUM8: 104,
     NUM9: 105,                MULTIPLY: 106,      ADD: 107,           SUBTRACT: 109,
     DECIMAL: 110,           DIVIDE: 111,      F1: 112,           F2: 113,
     F3: 114,                F4: 115,          F5: 116,           F6: 117,
     F7: 118,                F8: 119,           F9: 120,           F10: 121,
     F11: 122,                F12: 123,           NUMLOCK: 144,      SCROLLLOCK: 145,
     SEMICOLON: 186,      EQUAL: 187,      COMMA: 188,      DASH: 189,
     PERIOD: 190,           FORWARDSLASH: 191,                     GRAVEACCENT: 192,
     OPENBRACKET: 219,      BACKSLASH: 220,                         CLOSEBRACKET: 221,
     QUOTE: 222
};

/*******************************************************************************
**
** Function				:	maxWin
**
** Purpose				:	To maximise the window..
**
** Parameters			:	None
**
********************************************************************************/
function maxWin()
{
    self.moveTo (0,0);    
    self.resizeTo(screen.availWidth,screen.availHeight);
}
/**************************************************************************************************
**Function Name     : HideAnimation
**
**Function Purpose  : Displays the mesg to user saying "we are processing....Please wait".
**
**Function Parameter: None.
**
***************************************************************************************************/
function HideAnimation() 
{    
	var targetID, divTag;
	targetID = "wait";
	divTag = document.all(targetID);
	if (divTag.style.display == "none") 
	{
		divTag.style.display = "";	
		divtbl.style.display = "none";				
	}
	else 
	{
		divTag.style.display = "none";
		divtbl.style.display = "";
	}			
}

function BlockEnterKey(event, dp, dc, n)
{
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) 
		{
		    return false;
		} 
		else
			return true;
}

// check for white space.
function CheckSpace(evt) {
    if (evt.keyCode == 32)        
        return false;
    
    return true;
} 

// Parameters are (event)
function NumberBoxKeyPress(event) 
{
	var keyChar;
	if( document.all )
    {        
        keyChar = window.event.keyCode;           
    }
    else
    {       
        keyChar = event.which;              
    }	
  
    if ((keyChar < 45) || (keyChar > 57)) 
    {        
        if (keyChar == 8 || keyChar == 13 || keyChar == 0 || keyChar == 45) 
	    {	        
		    return true;
	    }
	    return false;
    }  
    return true;    
	
}

/**************************************************************************************************
**Function Name     : TxtSpaceCheck
**
**Function Purpose  : Function to make sure no illegal characters are gievn in the input field.
**
**Function Parameter: Excepts one Parameter.The actual field.
**
***************************************************************************************************/
function TxtSpaceCheck(event) 
{	
	var keyChar;
	if( document.all )
    {        
        keyChar = window.event.keyCode;           
    }
    else
    {       
        keyChar = event.which;              
    }
   
	if (((keyChar > 96) && (keyChar < 123)) || ((keyChar > 64) && (keyChar < 91)))
		return true;
	else
	{

		if (keyChar != 32)
			return false;
	}    
}

/**************************************************************************************************
**Function Name     : NbrTxtSpaceCheck
**
**Function Purpose  : Function to make sure no illegal characters are gievn in the input field.
**
**Function Parameter: Excepts one Parameter.The actual field.
**
***************************************************************************************************/
function NbrTxtSpaceCheck(event) 
{	
	var keyChar;
	if( document.all )
    {        
        keyChar = window.event.keyCode;           
    }
    else
    {       
        keyChar = event.which;              
    }
   
	if (((keyChar > 96) && (keyChar < 123)) || ((keyChar > 64) && (keyChar < 91)) || ((keyChar > 47) && (keyChar < 58)))
		return true;
	else
	{

		if (keyChar != 32)
			return false;
	}    
}

/**************************************************************************************************
**Function Name     : NbrTxt?.SpaceCheck
**
**Function Purpose  : Function to make sure no illegal characters are gievn in the input field.
**
**Function Parameter: Excepts one Parameter.The actual field.
**
***************************************************************************************************/
function QuestionCheck(event) 
{	
	var keyChar;
	if( document.all )
    {        
        keyChar = window.event.keyCode;           
    }
    else
    {       
        keyChar = event.which;              
    }
   
	if (((keyChar > 96) && (keyChar < 123)) || ((keyChar > 64) && (keyChar < 91)) || ((keyChar > 47) && (keyChar < 58)) || (keyChar == 63) || (keyChar == 46))
		return true;
	else
	{

		if (keyChar != 32)
			return false;
	}    
}

/**************************************************************************************************
**Function Name     : ShowNextBox
**
**Function Purpose  : Automatically sets focus to the next form element. 
**
**Function Parameter: Current field and Next field.
**
***************************************************************************************************/
function Nojunk(event)
{
    var keyChar;
	if( document.all )
    {        
        keyChar = window.event.keyCode;           
    }
    else
    {       
        keyChar = event.which;              
    }
	
	if (((keyChar > 96) && (keyChar < 123)) || ((keyChar > 64) && (keyChar < 91)) || ((keyChar > 47) && (keyChar < 58)) || ((keyChar > 31) && (keyChar < 47)) || (keyChar == 63) || (keyChar == 95))
		return true;
	else
	{

		if (keyChar != 32)
			return false;
	}  
}

/**************************************************************************************************
**Function Name     : ShowNextBox
**
**Function Purpose  : Automatically sets focus to the next form element. 
**
**Function Parameter: Current field and Next field.
**
***************************************************************************************************/
function ShowNextBox(currFld,nxtFld)
{
	var strText =new String(currFld.value);
	if (strText.length ==	currFld.maxLength)
	{
		try
		{
			nxtFld.focus();
		}
		catch(e)
		{}
	}
}

/*******************************************************************************
**	This function moves the "links" up. 
**	It swaps the contents of the div tags and the array which 
**	holds the primary key.
********************************************************************************/
function moveUp(chkGroup,Fld,mesgval,mesg) {

    mesgval = mesgval.replace('~',' ')
	var obj1, obj2;
	var pos1, pos2;
	var previousElement, nextElement;
	var previousValue, currentValue;
	var previousText, currentText;	
	var cnt = 0;
	// we can't move the first link any more "Up"
	
	if (aryLength > 1)
	{
		if (chkGroup[0].checked) 
		{	  
		    cnt = cnt + 1;  
		    Fld.innerHTML = "-Cannot move up first " +mesgval+ ".";
			obj1 = document.getElementById ("div0");
			//chkGroup[0].checked = false;
			return;
		}
		for (var i=1; i < aryLength; i++)
		{
		    Fld.innerHTML = "";
			if (chkGroup[i].checked) 
			{   
			    cnt = cnt + 1;
				previousElement = i - 1;

				//get the div elements
				obj1 = document.getElementById ("div" + i);
				obj2 = document.getElementById ("div" + previousElement);
					
				// swap the content of the div elements
				previousText = obj2.innerHTML;
				currentText = obj1.innerHTML;
				obj1.innerHTML = previousText;
				obj2.innerHTML = currentText;
					
				pos1 = i;
				pos2 = i - 1;	
				
				// Swap the primary key values for the 2 links
				// to be moved.
				previousValue = myArray[pos2];
				currentValue = myArray[pos1];
				myArray[pos2] = currentValue;
				myArray[pos1] = previousValue;
		
				chkGroup[i-1].checked = true;
				chkGroup[i].checked = false;			
			}
		}// end of for	
		
		if (cnt == 0)
		    Fld.innerHTML = "-"+mesg.replace(/~/g," ");
	}
	else 
	    Fld.innerHTML = "-Reorder cannot be done when there is only one " +mesgval+ ".";
	
	//chkGroup.checked = false;
}// End Function moveUp


/*******************************************************************************
**	This function moves the "links" down. 
**	It swaps the contents of the div tags and the array which 
**	holds the primary key.
********************************************************************************/
function moveDown(chkGroup,Fld,mesgval,mesg) {
    mesgval = mesgval.replace('~', ' ')
	var obj1, obj2;
	var pos1, pos2;
	var previousElement, nextElement;
	var previousValue, currentValue;
	var previousText, currentText;	
    var cnt = 0;
    
	if (aryLength > 1)
	{
	
		// we can't move the last link any more "Down"
		if (chkGroup[aryLength - 1].checked)
		{
		    cnt = cnt + 1;
		    Fld.innerHTML = "-Cannot move down last "+mesgval+".";
			obj1 = document.getElementById ("div" + (aryLength - 1));
			//chkGroup[aryLength - 1].checked = false;
			return;
		}	
		for (var i = aryLength - 2; i >= 0; i--)
		{	
		    Fld.innerHTML = "";	   
			if (chkGroup[i].checked) 
			{
			    cnt = cnt + 1;
				nextElement = i + 1;

				//get the div elements
				obj1 = document.getElementById ("div" + i);
				obj2 = document.getElementById ("div" + nextElement);
					
				// swap the content of the div elements
				previousText = obj1.innerHTML;
				currentText = obj2.innerHTML;
				obj2.innerHTML = previousText;
				obj1.innerHTML = currentText;
		
				pos1= i;
				pos2 = i + 1;	
					
				// Swap the primary key values for the 2 links
				// to be moved.
				previousValue = myArray[pos1];
				currentValue = myArray[pos2];
				myArray[pos1] = currentValue;
				myArray[pos2] = previousValue;
		
				chkGroup[i+1].checked = true;
				chkGroup[i].checked = false;
			}
		}// end of for
		if (cnt == 0)
		    Fld.innerHTML = "-"+mesg.replace(/~/g," ");
	}
    else 
	    Fld.innerHTML = "-Reorder cannot be done when there is only one " +mesgval+ ".";
	
	//chkGroup.checked = false;
}// End Function moveDown

var myArray = new Array();
var aryLength ;
function parseOrder()
{
	myArray = document.getElementById("order").value.split("~");	
    aryLength = myArray.length - 1;		
}

function Saveorder()
{  		    
	var neworder = "";
	for(var i=0;i<aryLength;i++)
	{
	   
		neworder = neworder + myArray[i] + "~";
	}
	document.getElementById("order").value = neworder;			
}
		
function Savelayoutorder(chkGroup)
{
    var neworder= "";
    for(var i=0;i<aryLength;i++)
	{   
	    
	    if (chkGroup[i].checked) 
		{   
		   neworder = neworder + chkGroup[i].value + "~";
	    }    
	}  
	
	document.getElementById("order").value= neworder;     

}		
function SaveImageorder(chkimageGroup)
{
    var newimageorder= "";
    for(var i=0;i<aryLength;i++)
	{   
	    if (chkimageGroup[i].checked) 
		{
		    newimageorder = newimageorder + chkimageGroup[i].value + "~";
	    }    
	}  
	
	document.getElementById("imageorder").value= newimageorder;
}
 /**************************************************************************************************
**Function Name     : ShowHide
**
**Function Purpose  : This function deletes the record in db. 
**
**Function Parameter: ID.
**
***************************************************************************************************/
function Show(strElem) 
{	        

    document.getElementById(strElem).style.display = 'block';		        
}
function Hide(strElem) 
{	       
    document.getElementById(strElem).style.display = 'none';
}		

function SelectAllCheckboxes(spanChk)
{

   // Added as ASPX uses SPAN for checkbox
   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? 
        spanChk : spanChk.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;

   for(i=0;i<elm.length;i++)
     if(elm[i].type=="checkbox" && 
              elm[i].id!=theBox.id)
     {
        
       //elm[i].click();
       if(elm[i].checked!=xState)
         elm[i].click();
       //elm[i].checked=xState;
     }
}    
    

function CheckChanged()                                   
{     
    var frm = document.forms[0];       
    var boolAllChecked;  
    boolAllChecked=true; 
    for(i=0;i< frm.length;i++)                                 
    {
        e=frm.elements[i];  
        
        if ( e.type=='checkbox' && e.name.indexOf('Save') != -1 )
        {            
            if(e.checked== false)  
            {                       
                boolAllChecked=false; 
                break; 
            }
        }
    }
    for(i=0;i< frm.length;i++)                                 
    {
        e=frm.elements[i];  
        if ( e.type=='checkbox' && e.name.indexOf('chkAll') != -1 )
        {                 
            if( boolAllChecked==false) 
                e.checked= false ; 
            else
                e.checked= true ;
            break;
        }
    }                                                                 
}

 function Delete(prm,pagename,mesg)
{

    if (window.confirm("Are you sure you want to " + prm + " this " + mesg.replace("~", " ") + "?") == true)
    {
	    window.location.href=pagename;
    }
    else
	    return false;
}

function UDPEdit(prm,pagename)
{
        
    if (window.confirm(prm)==true)
    {
	    window.location.href=pagename;
    }
    else
	    return false;
}

function CheckForAcro(Fld)
{
    var oAcro;
    var acrobat_installed = false;

    if (navigator.plugins && navigator.plugins.length)
    {
         try
        {
            for (x=0; x<10; x++)
            {
                if (navigator.plugins[x].description.indexOf('Adobe Acrobat') != -1)
                {
                    acrobat_installed = true;
                    break;
                }
            }
        }
        catch(e) 
        {           
        }
    }
    else if (window.ActiveXObject)
    {
        try
        {
            oAcro=eval("new ActiveXObject('AcroPDF.PDF.1');");
            if (oAcro)
            {
                acrobat_installed = true;
            }
        }
        catch(e) 
        {           
        }
             
        for (x=1; x<10; x++)
        {
            try
            {
                oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
                if (oAcro)
                {
                    acrobat_installed = true;                  
                }
            }
             catch(e) 
             {               
             }
        }                  
    }
    if(acrobat_installed == false)
        Fld.innerHTML = "<img Title='Adobe' align='left' src='../../images/adobe.jpg'><img Title='Acrobat Image.' onclick=window.open('http://www.adobe.com/products/acrobat/readstep2.html') src='../../images/Adobe.jpg'>";
}

function clickButton(e, buttonid)
{
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);
     
      if (bt)
      { 
          if (evt.keyCode == 13)
          { 
                bt.click(); 
                return false; 
          } 
      } 
}

function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

function OpenWindowToSelectFile(elementId,imageId)
{   
    var windowUrl = '/modules/UploadedImages/Default.aspx?ElementId=' + elementId+'&ImageId='+imageId;    
    var windowId = 'NewWindow_' + new Date().getTime();
    var windowFeatures = 
    'menubar=0,toolbar=0,location=1,scrollbars=0,resizable=0,status=1,' +
    'left=0,top=0,width=400px,height=200px';
    var windowReference = window.open(windowUrl, windowId, windowFeatures);
    windowReference.focus();
}
function SelectedFile(val,elementId,imageId)
{       
    for( var i=0, limit=document.getElementById(elementId).options.length; i < limit; ++i )
	{	    
		if( document.getElementById(elementId).options[i].value==val )
		{
			document.getElementById(elementId).options[i].selected=true;	
			document.getElementById(imageId).innerHTML = "<image Title='Picture.' width='150' align='left' src=" + escape(val) + "></img>";							
		}
	}
}

function OpenWindowToSelectSites(elementId,elementValue)
{       
    var windowUrl =  window.location.protocol + "//" + window.location.host + '/modules/EmailMessaging/Admin/BrandedSites.aspx?PageTitle=v65Z8oIv0T9ILl+TlOZU5g==&ElementId=' + elementId + '&ElementValue=' + escape(elementValue);        
    var windowId = 'NewWindow_' + new Date().getTime();
    var windowFeatures = 
    'menubar=0,toolbar=0,location=1,scrollbars=1,resizable=0,status=1,' +
    'left=0,top=0,width=400px';
    var windowReference = window.open(windowUrl, windowId, windowFeatures);
    windowReference.focus();
}
function SelectedSites(val,elementId)
{     
    document.getElementById(elementId).value=val.replace("~", "'");     	
}

function sendMailTo(name, subject) 
{
    var locationstring = 'mai' + 'lto:' + name + "?subject=" + escape(subject.replace("~", "'"));
    window.location.replace(locationstring);   
}

function NetSheetsOpen(page)
{
    var newwindow=window.open(page);
    newwindow.focus();
}
function imposeMaxLength(Object, MaxLen) {
    
    if (Object.value.length >= MaxLen) {
        Object.value = Object.value.substring(0, MaxLen);
   
    return false;    
  }
  
}
function maxLengthPaste(field,maxChar)
 {
    event.returnValue=false;
    if((field.value.length +  window.clipboardData.getData("Text").length) > maxChar) 
     {
     
        return false;
    }
    event.returnValue = true;
}

 function addLoadEvent(func) {
  
     var oldonload = window.onload;

     if (typeof window.onload != 'function') {
         window.onload = func;
     }
     else {
         window.onload = function() {
             if (oldonload) {
                 oldonload();
             }
             func();
         }
     }
 }
 
//Show & Hide TR tags.
 function ShowHideField(id) {
     //alert(id);
     var mySplitResult = id.split(";");

     for (i = 0; i < mySplitResult.length; i++) {

         if (document.getElementById(mySplitResult[i]) != null) {
             if (document.getElementById(mySplitResult[i]).style.display == 'none') {
                 document.getElementById(mySplitResult[i]).style.display = '';
             }
             else {
                 document.getElementById(mySplitResult[i]).style.display = 'none';
             }
         }
     }
     
 } 

