// GENERIC FUNCTIONS

    function CheckNumericKeyInfo($char, $mozChar) 
        {
            if ($mozChar != null) 
                { // Look for a Mozilla-compatible browser
                    if (($mozChar >= 48 && $mozChar <= 57) || $mozChar == 0 || $char == 8 || $mozChar == 13 || $mozChar == 32) $RetVal = true;
                    else 
                        {
                        $RetVal = false;
                        }
                }
            else 
                { // Must be an IE-compatible Browser
                    if (($char >= 48 && $char <= 57) || $char == 13 || $char == 32) $RetVal = true;
                    else 
                        {
                        $RetVal = false;
                        }
                }
            return $RetVal;
        }

	function noAlphabets(e)
		{
			var keynum;
			var keychar;
		
			if(window.event) // IE
				{
    				keynum = e.keyCode;
				}
			else if(e.which) // Netscape/Firefox/Opera
				{
				keynum = e.which;
				}
			var regex = /[\d\s]/;
			keychar = String.fromCharCode(keynum);
			return regex.test(keychar);
		}

	function obtainCountry(DropDown, TextControl)
		{
			var countryDropDown=document.getElementById(DropDown);
			var countryTextControl=document.getElementById(TextControl);
			countryTextControl.value=countryDropDown.options[countryDropDown.selectedIndex].text
        }
		
	function setRadioText(RadioButtonValue, TextControl)
	    {
	        var destinationInput = document.getElementById(TextControl);
	        destinationInput.value=RadioButtonValue
	    }

	function CheckForNumber(inputbox)
		{             
			var objRegExp  =  /[\d\s]/;         
			if(!objRegExp.test(inputbox.value))
				{
				inputbox.value="";//make this field blank so that it is invalidated
				}
		} 

	function JumpTop()
		{
			window.location.hash = "#top";
		}

    function clearMessage()
		{
		    var messageTextArea = document.getElementById("message");
		    if ((messageTextArea.value == 'Please call me about...') || (messageTextArea.value == 'Please send me...'))
		        messageTextArea.value = '';
		}

// FUNCTIONS FOR THE CURRENCY MODULE

	function setTelNo()
		{
		var sterlingImage = document.getElementById('826');
		var imageSrc = sterlingImage.src;
		var telephoneControl = document.getElementById('TelephoneNumber');
		if (imageSrc.indexOf('826.jpg') != -1)
			{
			telephoneControl.innerHTML = 'Tel: 01364 654100';
			}
		else
			{
			telephoneControl.innerHTML = 'Tel: +44 (1364) 654100';
			}
		}

	function invokeCurrency(currencyID)
		{
			document.getElementById('CurrencyID').value=currencyID;    
			CurrencyInvokeButton('0');
		}

// FUNCTIONS FOR THE ACCOUNT REGISTRATION PAGE

	function populateUsername()
		{
			if(navigator.appName == "Microsoft Internet Explorer" ||
			navigator.appName == "Netscape" ||
			navigator.appName == "Opera") // IE/Netscape/Firefox/Opera
				{
				var email=document.getElementById("email");
				var usrname=document.getElementById("username");

				usrname.value=email.value;
				}

		}
	          
	function OnCheck(boxname,inputname,option_checked,option_unchecked)
		{
			var inputbox=document.getElementById(inputname);
			if(boxname.checked)
				{						    
					inputbox.value=option_checked;
				}					   
			else
				{						   
					inputbox.value=option_unchecked;
				}					    
		}
						

// FUNCTIONS FOR THE CREDIT ACCOUNT REGISTRATION PAGE

	function submitButtonCreditAccount()
		{
		      obtainCountry("companycountry", "selectedcountry");
			  ContentInvokeButton('0');
		}

// FUNCTIONS FOR THE ACCOUNT ACTIVATION PAGE

	function toggleBox(szDivID, iState) // 1 visible, 0 hidden
		{                
			if(document.layers)	   //NN4+
				{
					document.layers[szDivID].visibility = iState ? "show" : "hide";
				}
			else if(document.getElementById)	  //gecko(NN6) + IE 5+
				{
					var obj = document.getElementById(szDivID);
					obj.style.visibility = iState ? "visible" : "hidden";
				}
			else if(document.all)	// IE 4
				{
					document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
				}
		}
	function redirectToLogin()
		{
			window.location='http://www.greymatter.com/Home/Login/tabid/112/Default.aspx';
		}

// FUNCTIONS FOR THE CALL ME PAGE

	function submitButtonCallMe()
		{
			obtainCountry("countrycode", "selectedcountry");
			ContentInvokeButton('0');
		}

// FUNCTIONS FOR THE EMBARCADERO PARTNER APPLICATION PAGE

		function submitButtonEmbarcaderoPartnerApp() {
		    obtainCountry("countrycode", "selectedcountry");
		    ContentInvokeButton('0');
		}
		
// FUNCTIONS FOR THE QUOTE MANAGEMENT PAGE

    function CheckOut(data) 
        {
            //var data = RetailStoreID + "_" + WorkstationID + "_" + BusinessDayDate + "_" + TransactionSequenceNumber;
            document.getElementById('SelectedData').value = data;
            ContentInvokeButton('3');
        }

    function ViewQuote(data) 
        {
            document.getElementById('SelectedData').value = data;
            ContentInvokeButton('1');
        }

    function ViewOrderedQuote(data) 
        {
            document.getElementById('SelectedData').value = data;
            ContentInvokeButton('11');
        }
    		
// FUNCTIONS FOR THE MANAGE PERSONAL DETAILS PAGE

    function SubmitFormPersonalDetails() // 1 visible, 0 hidden
        {
            ContentInvokeButton('1');
        }

// FUNCTIONS FOR THE MAIN BASKET PAGE

    function incrementQuantity(itemID)
        {
            var qtyControl = document.getElementById("quantity_" + itemID);
            var currentQty = qtyControl.value;
            currentQty++;
            qtyControl.value = currentQty;
        }

    function decrementQuantity(itemID) 
        {
            var qtyControl = document.getElementById("quantity_" + itemID);
            var currentQty = qtyControl.value;
            if (currentQty > 1) 
                {
                    currentQty--;
                    qtyControl.value = currentQty;
                }
        }  
        
    function checkEnterAndSumbit(e)
        { //e is event object passed from function invocation
            var characterCode; //literal character code will be stored in this variable

            if(e && e.which)
                { //if which property of event object is supported (NN4)
                    e = e;
                    characterCode = e.which;  //character code is contained in NN4's which property
                }
            else
                {
                    e = event;
                    characterCode = e.keyCode;  //character code is contained in IE's keyCode property
                }

            if(characterCode == 13)
                { //if generated character code is equal to ascii 13 (if enter key)
                    ContentInvokeButton('0');
                    return false;
                }
            else
                {
                    return true;
                }

        }
        
// FUNCTIONS FOR THE LISTINGS PAGE

    function call_BRNavPage(ConceptID, RetailStoreGroupID, MenuID, MenuOptionID, Alphabet, pageNumber, pageSize) 
        {
            var prodpp = document.getElementById("prodPerPage").value;
            //var PageDetails ="BrowseByA2Z"+'_'+ConceptID+'_'+ RetailStoreGroupID+'_'+MenuID+'_'+MenuOptionID+'_'+Alphabet+"_1_"+pageSize;
            var PageDetails = "BrowseByA2Z" + '_' + ConceptID + '_' + RetailStoreGroupID + '_' + MenuID + '_' + MenuOptionID + '_' + Alphabet + "_" + pageSize + "_1";
            ContentBRNavigationCallBack('default.Listings', PageDetails);
        }

    function viewCutomerList(listId) 
        {
            var cutomerData = listId + "_Favourite";
            ContentBRNavigationCallBack('default.ViewCustomerList', cutomerData);
        }

    function alphabetSelected(brData, pageSize) 
        {
            var BRPageData = brData + "__" + pageSize;
            ContentBRNavigationCallBack('default.Listings', BRPageData);
        }

// FUNCTIONS FOR THE EVALUATIONS DOWNLOAD PAGE

    function submitButtonEvalDownload() 
        {
            obtainCountry("countrycode", "selectedcountry");
            ContentInvokeButton('0');
        }

// FUNCTIONS FOR THE CHECKOUT - DETAILS PAGE
    function GM_Validate() 
        {
            var promoCode = document.getElementById("PromoCode");
            var promoCodeLabel = document.getElementById("PromoCode_Error");
            if ((promoCode && promoCodeLabel) && ((promoCode.value == "") || (promoCode.value != "GOPARALLEL09"))) 
                {
                    promoCodeLabel.style.color = "red"
                }
            else 
                {
                    ContentInvokeButton('3');
                }
        }        
        
// FUNCTIONS FOR THE CHECKOUT - MANDATORY INFO PAGE

        function confirmMI() 
            {
                var checkBox = document.getElementById('MIConfirm');
                if (checkBox.checked)
                    {
                        ContentInvokeButton('1'); 
                    }
                else
                    {
                        var errorText = document.getElementById('ConfirmText');
                        errorText.style.color = 'red';
                    }
            }
            
        function resetMIColor()
            {
                var errorText = document.getElementById('ConfirmText');
                errorText.style.color = 'black';
            }
            
// FUNCTIONS FOR THE SOURCING REQUEST PAGE

        function ShowHideOther() 
            {
                var otherBoxLabel = document.getElementById('publisherspecificlabel');
                var otherBox = document.getElementById('publisherspecific');
                var optionBox = document.getElementById('PublisherList');
                if (optionBox.options[optionBox.options.selectedIndex].value=='Other') 
                    {
                        otherBoxLabel.style.display = '';
                        otherBox.style.display = '';
                    }
                else 
                    {
                        otherBoxLabel.style.display = 'none';
                        otherBox.style.display = 'none';
                    }
            }
            
    function SubmitSourcingRequest()
        {
            var optionBox = document.getElementById('PublisherList');
            var otherBox = document.getElementById('publisherspecific');
            if (optionBox.options[optionBox.options.selectedIndex].value=='Other')
                {
                    if (otherBox.value == '') 
                        {
                            ValidateForm();
                            var publisherLabel = document.getElementById('PublisherListError');
                            publisherLabel.style.color = 'red';
                        }
                    else
                        {
                            ContentInvokeButton('0');
                        }
                }
            else
                {
                    ContentInvokeButton('0');
                }
        }
