﻿// 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.innerHTML = 'Position: ' + getposition(txtBox) + ' - ' + txtRemaining + ' characters remaining';
    }
    //return true;
    //debugger;
    //
    // NEW - workaround for multiline textbox. DONT set the maxlength propery in asp textbox ensure use a semicolon on call
    //
    //The following is ignored by onkeyup but used by onkeypress in that if false gets returned the character is ignored.
    //
    // Example call (use both lines for mulitline)
    //
    //Me.txtAdBody.Attributes.Add("onkeyup", "return countChars('" & Me.txtAdBody.ClientID & "', 'sAdBody', 125);")
    //Me.txtAdBody.Attributes.Add("onkeypress", "return countChars('" & Me.txtAdBody.ClientID & "', 'sAdBody', 125);")
    var b = txt.value.length <= (maxCount - 1);
    return b;
    
}

function getposition(txtbox) {
    //debugger;
    var obj = document.getElementById(txtbox);
    
var CurPos = 0;
var len = 0;

if (document.selection) {
    var currentRange = document.selection.createRange();
    var workRange = currentRange.duplicate();
    obj.select();
    var allRange = document.selection.createRange();
    
    while (workRange.compareEndPoints("StartToStart", allRange) > 0) {
        workRange.moveStart("character", -1);
        len++;
    }
    currentRange.select();
    return len;
}
else {
    len = obj.selectionStart;
}


return len;
}

// 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 = 700;
    //var height = 900;
    //debugger;
   var LEFT = parseInt((screen.availWidth/2) - (width/2));
   var TOP = parseInt((screen.availHeight/2) - (height/2));
   var windowFeatures = "width=" + width + ",height=" + height + ",toolbar=yes,status=no,location=no,resizable=yes,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
    }
}



var bSaving = false;
var bTested = false;

function checksaved(xForm, btnID) {
    //debugger;
    
    if (!bSaving) {

        try {
            var aa = IsFormDirty(xForm);
            if (aa) {

                var x = confirm('Save before navigating away?');
                if (x == true) {
                    bTested = false;
                    __doPostBack(btnID, '');
                }
            }
        }
        catch (e) {
            //alert(e);
        }
        
    }
    else {
        //alert("bSaving is: " + bSaving);
    }
}



//$(document).ready
//(
//    function() {
//        //debugger;

//        try {
//            $('.widgetcontent').corner("round bl br");
//        }
//        catch (e) { }
//    }
//);

function checksaved2(xForm, btnID) {
    //debugger;
    if (!bSaving) 
    {
        if (!bTested)
        {
            if (IsFormDirty(xForm)) {

                if (confirm('Save changes?')) {
                    return true;
                }
                else {
                    return false;
                }
            }
        }
    }
}

function checksaved3() {

    //debugger;
    if (!bSaving) {
        if (IsFormDirty(xForm)) {
            if (confirm('Save changes?')) {
                __doPostBack(btnID, '');
            }
        }
    }
}


function IsFormDirty(xForm) {
    /* Returns an indication of whether all fields are in their default state */
    /* True means it has changed */

    var eForm = document.getElementById(xForm);

    var iNumElems = eForm.elements.length;

    try {
        for (var i = 0; i < iNumElems; i++) {
            var eElem = eForm.elements[i];
            if ("text" == eElem.type || "TEXTAREA" == eElem.tagName) {
                if (eElem.value != eElem.defaultValue) {

                    if (eElem.parentElement.className.indexOf('Rad') == -1 && (eElem.className.indexOf('Rad') == -1)) {
                        return true;
                    }
                }
            }
            else if ("checkbox" == eElem.type || "radio" == eElem.type) {
                if (eElem.checked != eElem.defaultChecked) {
                    return true;
                }
            }
            else if ("SELECT" == eElem.tagName) {
                var cOpts = eElem.options;
                var iNumOpts = cOpts.length;
                for (var j = 0; j < iNumOpts; j++) {
                    var eOpt = cOpts[j];

                    if (eOpt.selected != eOpt.defaultSelected) {
                        // dont want to validate the drop downs on the html editor
                        //debugger;
                        //eOpt.parentElement.className
                        //if (eOpt.parentElement.id.indexOf('mce_editor_') == -1 && (eOpt.parentElement.id.indexOf('_toolbar') == -1 || eOpt.parentElement.id.indexOf('_styleSelect'))) {
                        if (eOpt.parentElement.className.indexOf('Rad') == -1 && (eOpt.parentElement.id.indexOf('_toolbar') == -1)) {
                            return (true);
                        }
                    }
                }
            }
        }    
    }
    catch (e) {
        return (true);
    }
    
    return false;
}


function trim(str) {
    var trimmed = str.replace(/^\s+|\s+$/g, '');
    return trimmed;
}


//Clear control x if control y is empty
function clearControlXifControlYEmpty(ctrlX, CtrlY) {
    //debugger;
    var currentvalue = $('.' + CtrlY).attr("value");
    if (currentvalue == '') {
        $('.' + ctrlX).attr("value", "");
    }

}


function IsNumeric(strString)
//  check for valid numeric strings	
{
    var strValidChars = "0123456789.";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function IsInteger(strString)
//  check for valid numeric strings	
{
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function RadioButtonSelected(sender, args) {


    //2nd: ensure one of the radios is selected
    $('.rdoUserType').each(function() {
        //if its blank set warning in the warning span immediately after the textbox
        //debugger;
        if ($('.rdoUser')[0].firstChild.checked == false) {
            if ($('.rdoGolfPro')[0].firstChild.checked == false) {
                //debugger;
                args.IsValid = false;
                return;

            }
            else {
                args.IsValid = true;
            }
        }
        if (blnError == true) {
            $('.lblUserType').text("Required");
        }
        else {
            $('.lblUserType').text("");
        }
    })

}

function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}

function URLDecode(encodedString) {
    var output = encodedString;
    var binVal, thisString;
    var myregexp = /(%[^%]{2})/;
    while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
        binVal = parseInt(match[1].substr(1), 16);
        thisString = String.fromCharCode(binVal);
        output = output.replace(match[1], thisString);
    }
    return output;
}


//Is used simply by including server side as follows, passing the id of the div to print. (what you get is a link saying 'print this' which pops up a dialog containing the
//content and the print dialog
//
//              Example include...(see golfpro job
//              Me.cMain.InnerHtml += Common.includePrint("divExtraContent") 
//
function CallPrint(strid,strTitle) 
{
    //debugger;
    var prtContent = document.getElementById(strid);
    var WinPrint =
    window.open('', '', 'left=0,top=0,width=400,resize=1,height=300,toolbar=0,scrollbars=0,status=0');
    WinPrint.document.write('<h1>' + strTitle + '</h1>');
    //WinPrint.document.write(prtContent.innerHTML);
    //debugger;
    WinPrint.document.write(removeHTMLTags(strid));
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close();
    //prtContent.innerHTML=strOldOne;
}

//Is used simply by including server side as follows, passing the id of the div to print. (what you get is a link saying 'print this' which pops up a dialog containing the
//content and the print dialog
//
//              Example include...(see golfpro job
//              Me.cMain.InnerHtml += Common.includePrint("divExtraContent") 
//
function CallPrintEx(strid) {
    //debugger;
    var strInputCode;
    var prtContent = document.getElementById(strid);
    var WinPrint =
    window.open('', '', 'left=0,menubar=yes,resizable=yes,top=0,width=400,height=300,toolbar=1,scrollbars=1  ,status=0');
    WinPrint.document.write("<html>");
    WinPrint.document.write("<head>");
    WinPrint.document.write("<LINK REL=StyleSheet HREF='" + siteroot + "_style/core.css' TYPE='text/css'>");
    WinPrint.document.write("<LINK REL=StyleSheet HREF='" + siteroot + "_style/pglayouts.css' TYPE='text/css'>");
    WinPrint.document.write("</head>");
    WinPrint.document.write("<body>");
    //WinPrint.document.write(prtContent.innerHTML);
    //debugger;

    if (document.getElementById && document.getElementById(strid)) {
        strInputCode = document.getElementById(strid).innerHTML;
    }
    WinPrint.document.write(strInputCode);
    WinPrint.document.write("</body>");
    WinPrint.document.write("</html>");
    WinPrint.document.close();
    WinPrint.focus();
    //WinPrint.print();
    //WinPrint.close();
    //prtContent.innerHTML=strOldOne;
}


//Just prints the content
function CallPrintDirect(strContent) {
    //debugger;
    var strInputCode;
    var prtContent = strContent;
    var WinPrint =
    window.open('', '', 'left=0,menubar=yes,resizable=yes,top=0,width=400,height=300,toolbar=1,scrollbars=1  ,status=0');
    WinPrint.document.write("<html>");
    WinPrint.document.write("<head>");
    WinPrint.document.write("<LINK REL=StyleSheet HREF='" + siteroot + "_style/core.css' TYPE='text/css'>");
    WinPrint.document.write("<LINK REL=StyleSheet HREF='" + siteroot + "_style/pglayouts.css' TYPE='text/css'>");
    WinPrint.document.write("</head>");
    WinPrint.document.write("<body>");

    WinPrint.document.write(strContent);
    
    WinPrint.document.write("</body>");
    WinPrint.document.write("</html>");
    WinPrint.document.close();
    WinPrint.focus();
    //WinPrint.print();
    //WinPrint.close();
    //prtContent.innerHTML=strOldOne;
}

//Is used simply by including server side as follows, passing the id of the div to print. (what you get is a link saying 'print this' which pops up a dialog containing the
//content and the print dialog
//
//              Example include...(see golfpro job
//              Me.cMain.InnerHtml += Common.includePrint("divExtraContent") 
//
function CallPrintExJQ(strid) {
    //debugger;
    var strInputCode;
    //var prtContent = document.getElementById(strid);
    var prtContent = $('.' + strid);
    var WinPrint =
    window.open('', '', 'left=0,menubar=yes,resizable=yes,top=0,width=400,height=300,toolbar=1,scrollbars=1  ,status=0');
    WinPrint.document.write("<html>");
    WinPrint.document.write("<head>");
    WinPrint.document.write("<LINK REL=StyleSheet HREF='" + siteroot + "_style/core.css' TYPE='text/css'>");
    WinPrint.document.write("<LINK REL=StyleSheet HREF='" + siteroot + "_style/pglayouts.css' TYPE='text/css'>");
    WinPrint.document.write("</head>");
    WinPrint.document.write("<body>");
    //WinPrint.document.write(prtContent.innerHTML);
    //debugger;

    if (prtContent) {
        strInputCode = $('.' + strid).attr("innerHTML");
    }
    WinPrint.document.write(strInputCode);
    WinPrint.document.write("</body>");
    WinPrint.document.write("</html>");
    WinPrint.document.close();
    WinPrint.focus();
    //WinPrint.print();
    //WinPrint.close();
    //prtContent.innerHTML=strOldOne;
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Robert Nyman | http://robertnyman.com/ */
function removeHTMLTags(divID) {
    if (document.getElementById && document.getElementById(divID)) {
        var strInputCode = document.getElementById(divID).innerHTML;
        /* 
        This line is optional, it replaces escaped brackets with real ones, 
        i.e. < is replaced with < and > is replaced with >
        */
        strInputCode = strInputCode.replace(/&(lt|gt);/g, function(strMatch, p1) {
            return (p1 == "lt") ? "<" : ">";
        });
        var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
        //alert("Output text:\n" + strTagStrippedText);
        // Use the alert below if you want to show the input and the output text
        //		alert("Input code:\n" + strInputCode + "\n\nOutput text:\n" + strTagStrippedText);
        //debugger;
        return strTagStrippedText;
    }
}







// Handlers for the show and hide loading page animated gif - a template should have the following in the body tag to use this feature
//  <body onload="hideloadingpage()">

function hideloadingpage() {
    //return;
    //debugger;
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('hidepage').style.visibility = 'hidden';
    }
    else {
        if (document.layers) { // Netscape 4 
            document.hidepage.visibility = 'hidden';
        }
        else { // IE 4 
            document.all.hidepage.style.visibility = 'hidden';
        }
    }
    //setInterval("displaytime()", 1000)
}
function showloadingpage() {
    //debugger;
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('hidepage').style.visibility = 'visible';
    }
    else {
        if (document.layers) { // Netscape 4 
            document.hidepage.visibility = 'show';
        }
        else { // IE 4 
            document.all.hidepage.style.visibility = 'visible';
        }
    }
}




//$(document).ready
//(
//    function() {
//        //debugger;

//        try {
//            $('.widgetcontent').corner("round bl br");
//        }
//        catch (e) { }
//    }
//);


function setimage(imgsrc,obj,subtext) {

    //debugger;
    img = $('.' + obj);
    img[0].src = imgsrc;
    if (subtext == '') {
        //do nothing
    }
    else {
        $('.mainimagesubtext')[0].innerText = subtext;
    }

}


//Made publicly avaiable for user custom forms to call eg var formmessage = encodeMyHtml($('.txtFormMessage').attr("value"));
function encodeMyHtml(str) {
     var encodedHtml = escape(str);
     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;
   }


   // default javascript setup code for the vertical menus - see http://qrayg.com/experiment/cssmenus/
   $(document).ready(function() {
       //debugger;
       $("#navmenu-h li,#navmenu-v li").hover(
    function() { $(this).addClass("iehover"); },
    function() { $(this).removeClass("iehover"); }
  );
   });
