﻿// JScript File
var div2print;

// Redirect a page
function getURL(strURL)
{
    try
    {
        window.location = strURL;
    }
    catch (e) {}
}

// Returns Numeric
function getNumeric(strString, allowChars)
{   
    var intRetValue = '';
    
    try
    {
        //debugger;
        var intCount = 0;
        var currentChar = '';
        
        for (intCount = 0; intCount < strString.length; intCount++)
        {
            currentChar = strString.charAt(intCount);
            if (allowChars.indexOf(currentChar) != -1)
            {
                intRetValue += currentChar;
            }
        }
    }
    catch (e) {}
    
    return intRetValue;
}

function taCount(visCnta) 
{ 
    debugger;
    var visCnt = document.getElementById(visCnta);
	var taObj=event.srcElement;
	if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
	if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}

function characters_remaining(txtBox, divId, maxCount) 
{ 
    var txt = document.getElementById(txtBox);
    var txtvalue = '';
    var txtLength = 0;
    var txtRemaining = 0;
    var divbox = document.getElementById(divId);
    if (txt)
    {
        txtvalue = txt.value;
        txtLength = txtvalue.length;
        txtRemaining = maxCount - txtLength;
    }
    if (divbox)
    {
        divbox.innerText = txtRemaining;
    }
    return true;
}

function countChars(txtBox, divId, maxCount) 
{ 
    //debugger;
    var txt = document.getElementById(txtBox);
    var txtvalue = '';
    var txtLength = 0;
    var txtRemaining = 0;
    var divbox = document.getElementById(divId);
    if (txt)
    {
        txtvalue = txt.value;
        txtLength = txtvalue.length;
        txtRemaining = maxCount - txtLength;
    }
    if (divbox)
    {
        divbox.innerText = txtRemaining + ' characters remaining';
    }
    return true;
}


// Check for valid email address
function validEmail(email)
{
	var filter  = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	if (filter.test(email))
	{
	    return true;
	}
	else
	{
	    return false;
	}
}

// Print function for admin pages
function adminPrintMe(id)
{
    //debugger;
    var links = document.getElementById(id);
    if ((links != null) && (links != 'undefined'))
    {
        links.style.display = 'none';
    }
    window.print();
    if ((links != null) && (links != 'undefined'))
    {
        links.style.display = 'block';
    }
}

function PrintDiv(strText, relativePath){
	var a = window.open('','','width=300,height=300');
	a.document.open("text/html");
	a.document.write(strText);
	a.print();
    a.document.write('<a onclick="window.close();" style="background-image:url(' + relativePath + '_images/closeprint.jpg); display: block; width: 50px; cursor: pointer; float: right;">&nbsp;</a>');
	a.document.close();
}

function HtmlEncode(RawHTML) {
var encodedHtml;
     encodedHtml = escape(RawHTML);
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     
     return encodedHtml;
   } 
   
function openPopup(url,width,height) 
{
   var width = 600;
   var height = 800;
   var LEFT = parseInt((screen.availWidth/2) - (width/2));
   var TOP = parseInt((screen.availHeight/2) - (height/2));
   var windowFeatures = "width=" + width + ",height=" + height + ",toolbar=no,status=no,location=no,resizable=no,directories=no,scrollbars=yes,left=" + LEFT + ",top=" + TOP + "screenX=" + LEFT + ",screenY=" + TOP;
   myWindow = window.open(url, "Help", windowFeatures);
   event.returnValue = false;
   return false;
}




//Use as is or customise for popup messageboxes on the client that only perform POSTBACK
//if the user responds YES
//
//Example - heres a delete example where user hits the delete button and they have to
//          confirm before the POSTBACK occurs for the delete to execute
//
// Add a button to page - which requires a messagebox for confirmation of the function...
//
//      <asp:Button runat="server" width="140px" Visible="true" ID="btnDelete" ToolTip="Delete exception messages" Text="Exeptions" />
//
// Wire up the buttons OnClick() handler to the javascript confirm dialog
//
//      Me.btnDelete.Attributes.Add("onclick", "javascript:return confirmDelete('Are you sure you want to delete the exception messages?');")
//
// Finally some code 
//        Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
//            Try
//                DeleteMessages()
//            Catch ex As Exception
//                // Catch error
//            End Try
//        End Sub
//
function confirmDialog(msg)
{
    exit = confirm( msg + " (OK=Yes Cancel=NO)")
 
    if (exit == true)
    {
        return true; //add order
    }
    else
    {
        return false; //dont add order
    }
}
