﻿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 Name     : CheckParent
**
**Function Purpose  : Checks if Login is required..
**
**Function Parameter: None.
**
***************************************************************************************************/

function GoToLoginPage()
{
   window.location.href='default.aspx?Login=Yes';
}
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;
}

// Parameters are (event)
function NumberBoxKeyPress(event) 
{
	var keyChar;
	if( document.all )
    {        
        keyChar = window.event.keyCode;           
    }
    else
    {       
        keyChar = event.which;              
    }	
    if ((keyChar < 48) || (keyChar > 57)) 
    {        
        if (keyChar<1 || keyChar == 8) 
	    {
		    return true;
	    }
	    return false;
    }  
    return true;    
	
}

/**************************************************************************************************
**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 < 60)) || (keyChar == 63) || (keyChar == 46) || (keyChar == 34) || (keyChar == 39) || (keyChar == 44) || (keyChar == 127) || (keyChar == 8) || (keyChar == 46) || (keyChar > 36 && keyChar < 41))
//		return true;
//	else
//	{

//		if (keyChar != 32)
//			return false;
//	}    
//}
// Parameters are (event, Decimal Places, Decimal Symbol, Allow Negatives)
function NumberBoxKeyPressForMoney(event) 
{
/*
	could also check for one period, by passing whole string in and if period present,
	return false
	*/

	var AsciiCode=window.event.keyCode;
	
	if ((AsciiCode >= 48)&&(AsciiCode <= 57)||(AsciiCode == 46))
	{
	    return true;
	}
	else
	{
	    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)
{			
	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 item.";
			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 = "-Please select any item.";
	}
	
	//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)
{    
	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 item.";
			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 = "-Please select any item.";
	}
	//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 limitText(limitField, limitNum) {
     
    if (limitField.value.length < limitNum) {
        return true; 
    } else {
    return false;
    }
}


