﻿// JScript File

$(document).ready( function()
{
	    beginjs();
}
);


jQuery.extend({

ievent:function(e)
    {
        if(jQuery.browser.msie)
        {
            if(e.button==1)e.button=0;
            if(e.button==4)e.button=1;
        }
    }

});



function beginjs()
{

}


function getWindow()
{
    var xx=$(this)[0].scrollLeft;
   }

function ToInt(val)
{
var x="0";
x=parseInt(val);
if(isNaN(x))
    x="0";
return x;
}


function Trim(txt)
{
var val=txt.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
return val;
}

function ajaxCall(serverControl,argument,success,context,error)
{
    WebForm_DoCallback(serverControl,argument,success,context,error,true)
}



function CallBackX(argument,success)
{
    var idx=(IdPrefix=="") ? "" :IdPrefix + "$";
    ajaxCall(idx + "AjaxCommands",argument,function(e){success(e);},"",function(ee){});
}


 function JSon(text)
{
    try
    {
    var o = eval("("+ text +")");
    return o;
    }catch(e){return undefined;}
}


function Id(ctrl)
{
return document.getElementById(ctrl);
}


function Xml(val)
{
var xmlobject = (new DOMParser()).parseFromString(val, "text/xml");
return xmlobject;
}
function Xvalue(xml,node)
{
    try
        {
            return xml.getElementsByTagName(node)[0].childNodes[0].nodeValue
         }
         catch(e)
         {
         return "";
         }
}

function newElement(tag,type,id,name)
{
        var obj=document.createElement(tag,type);
        obj.setAttribute("id",id);
        obj.setAttribute("name",name);
        return obj;
}


function ASP(divId)
{
return $("#"+divId).children(0);
}

function IdX(id,prefix)
{
var x=id.replace(prefix,"");
return x;
}





function XmlToObject(XML)
{
    // Name/reference to give to text elements
    var TextNodeName = "text";
 
    // Name/reference to give to attribute elements
    var AttributeNodeName = "attributes";
 
    // Verity that XML is not empty
    if (!XML) return;
 
    // Object to return
    var XMLObject = new Object();
 
    // Verify that object contains ChildNodes
    if (XML.hasChildNodes())
    {
        XMLObject = NodeLoop(XML.childNodes, XMLObject);
    }	
 
    /**
    * @param XMLNodes XMLNode collection to loop/parse through
    * @param ParentObject Object to which to attach converted nodes
    * @return Object Returns object containing child objects (if any)
    */
    function NodeLoop(XMLNodes, ParentObject)
    {
        // Store length in variable for efficiency
        var NodeLength = XMLNodes.length;
 
        // Loop through XML Nodes
        for (var i = 0; i < NodeLength; i++)
        {
            var NodeObject = new Object();
            var CurrentNode = XMLNodes[i];
            var CurrentNodeName = CurrentNode.nodeName;
 
            // Store increment value
            var NodeInteger = 0;
 
            // Return only if current node isn't a text node
            if (CurrentNodeName != "#text")
            {				
                // Does current node have child nodes?
                if (CurrentNode.hasChildNodes())
                {
                    // Node contains children, recurse
                    NodeObject = NodeLoop(CurrentNode.childNodes, NodeObject);
                }
                else
                {
                    NodeObject = CurrentNode;
                }
 
                // Verify that current object doesn't already exist
                if (ParentObject[CurrentNodeName] != undefined)
                {
                    // Name is already taken, modify
                    NodeInteger++;
                    CurrentNodeName = CurrentNodeName + "_" + NodeInteger;
                }
 
                // Does current node have attributes
                if (CurrentNode.attributes.length != 0)
                {
                    NodeObject[AttributeNodeName] = AttributeLoop(CurrentNode.attributes);
                }
            }
            else
            {
                // Current node is a text element
                CurrentNodeName = TextNodeName;
                NodeObject = CurrentNode.data.toString();
            }
 
            // Attach object to its namesake
            ParentObject[CurrentNodeName] = NodeObject;
 
        }
 
    return ParentObject;
 
    }
 
    /**
    * @param Attributes Array containing attributes to loop through
    * @return Object Returns object containing attributes
    */
    function AttributeLoop(Attributes)
    {
        // Store length in variable for efficiency
        var AttributeLength = Attributes.length;
 
        // Object to return
        var AttributeObject = new Object();
 
        // Loop through attributes
        for (var i = 0; i < AttributeLength; i++)
        {
            var CurrentAttribute = Attributes[i];
            var CurrentAttributeName = CurrentAttribute.nodeName;
            var CurrentAttributeValue = CurrentAttribute.nodeValue;
 
            // Attach attribute to its namesake
            AttributeObject[CurrentAttributeName] = CurrentAttributeValue;
        }
 
        return AttributeObject;
 
    }
 
    // Conversion complete, return XMLObject
    return XMLObject;
 
}




function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}


var popupindex=Date();

function PopupIt(url) 
{
    popupindex++;
    var dt=EscapeDate();
    var newname="mywindow_" + dt;
	newwindow=window.open(url,newname,'fullscreen="yes"');
	if (window.focus) {newwindow.focus()}
	return false;
}

var popupindex=0;
function PopupItX(url,width,height) 
{

    popupindex++;
    var dt=EscapeDate();
    var newname="mywindow_" + dt;
    var newwindow = window.open(url,newname,"resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+width + ",height=" + height); 
   	if (window.focus) {newwindow.focus()}
	return false;
}

function EscapeDate()
{
   var dt=new Date()
   
    var xx=dt.getTime() + "" ;
    return xx;
}

function  PopupFull(url)
{
	newwindow=window.open(url,'name' + popupindex++ ,'fullscreen=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}


//Query String

var qs = new Array();
function defined( item )
{
    return typeof item != "undefined";
}
function queryString( key )
{

    if ( !defined( qs[ key ] ) )
    {
        var reQS = new RegExp( "[?&]" + key + "=([^&$]*)", "i" );
        var offset = location.search.search( reQS );
        qs[ key ] = ( offset >= 0 ) ? RegExp.$1 : null;
    }
    return qs[ key ];
}


function SafeCallBack(callback)
{
setTimeout(callback,100);
}

function PopupDiv(div,width,height)
{
    var h = $(window).height();
    var w = $(window).width();
    var hh=height;
    var ww=width;
    var nh=(h/2)-(hh/2);
    var nw=(w/2)-(ww/2);
    var scrlH= document.documentElement.scrollTop;
    var scrlW= document.documentElement.scrollLeft;
    nh+=scrlH;
    nw+=scrlW;

    div.style.left=nw+"px";
    //div.style.top=nh+"px";
    div.style.top="-" + height +  "px";
    $(div).animate({top: nh+"px"}, 500);
    
}

function setStyle(element, text) 
{
    var x=element.style.cssText;
    if(x== undefined || x==null || x=="")
	element.setAttribute("style", text)
	element.style.cssText = text;
	x=element.style.cssText;
}


function openInNewWindow(url) 
{
    var newWindow = window.open(url, '_blank');
    newWindow.focus();
    return false;
}

function AspId(name)
{
    var idx=(IdPrefix=="") ? "" :IdPrefix + "$";
    return Id(idx);
}
function getCurrentPageId()
{
    var x= getCookie("page");
    return x;
}
function getCurrentSiteId()
{
    var x= getCookie("site");
    return x;
}


function getStyleTextAlign(el)
{
	var x = document.getElementById(el);
	if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue("text-align");
	else if(x.currentStyle)
		var y = x.currentStyle.textAlign;
	return y;
}

function IsIE()
{
    return $.browser.msie;
}
function IsFirefox()
{
    return $.browser.mozilla;
}

function ToArr(obj)
{
    var l=obj.length;
    if(l==undefined)
    {
        var arr=new Array();
        arr.push(obj);
        return arr;
    }
    return obj;
}

function extend(subclass,superclass) 
{
    subclass.prototype = new superclass();
    subclass.prototype.constructor = subclass;
    subclass.superclass = superclass;
    subclass.superproto = superclass.prototype;
    subclass.prototype.func=subclass.prototype;
    subclass.prototype.base=subclass.superproto;
}function base(){}  
