
function showMiniReg(mode,entry)
{
        if (mode==null || mode=="")
        {
                mode="intro";
        }
        if (entry==null || entry=="")
        {
                entry="";
        }
   getMiniRegDiv(mode, entry);
}


function break_out_of_frame()
{
        if (top.location != location) {
                top.location.href = document.location.href ;
        }
}

function RedirectTo(url){
        document.location = url;
}

function Get(id)
{
  if (document.getElementById(id)!=null)
  {
          return document.getElementById(id);
  }
  if (document.getElementById('frmMHP')!=null)
  {
     return document.getElementById('frmMHP').contentWindow.document.getElementById(id);
  }
}

function GetDocument()
{
  if (document.getElementById('frmMHP')!=null)
  {
     return document.getElementById('frmMHP').contentWindow.document;
  }
  else
  {
        return document;
  }
}

function GetFromIFrame(id)
{
  return document.getElementById('frmMHP').contentWindow.document.getElementById(id);
}

function GetRegionArr(region)
{
  return document.getElementById('frmMHP').contentWindow.regionArr[region];
}



function findPosX(obj)
{
        var curleft = 0;
        if(obj){
                if (obj.offsetParent)
                {
                        while (obj.offsetParent)
                        {
                                curleft += obj.offsetLeft
                                obj = obj.offsetParent;
                        }
                }
                else if (obj.x)
                        curleft += obj.x;
        }
        return curleft;
}

function findPosY(obj)
{
        var curtop = 0;
        if(obj){
                if (obj.offsetParent)
                {
                        while (obj.offsetParent)
                        {
                                curtop += obj.offsetTop
                                obj = obj.offsetParent;
                        }
                }
                else if (obj.y)
                        curtop = obj.y;
        }
        return curtop;
}
function findPosYscroll(obj)
{
        var curtop = 0;
        if(obj){
                if (obj.offsetParent)
                {
                        while (obj.offsetParent)
                        {
                                curtop += obj.offsetTop
                                curtop -= obj.scrollTop;
                                obj = obj.offsetParent;
                        }
                }
                else if (obj.y)
                        curtop = obj.y;
        }
        var scrollH = 1;
        return curtop;
}

function Max(n,m)
{
        return n>m?n:m;
}

function Min(n,m)
{
        return n<m?n:m;
}

function UpperCase(s)
{
        return s.toUpperCase()
}

function WriteDebugInfo(info, writeToId){
        if(isDebug)
                Get(writeToId).innerHTML = info;
}

function GetClickEvent(){
        var myEvent;
        if(document.all)
                myEvent = window.event.button;
        else
                myEvent = 1;
        return myEvent;
}

function SetRemoteMultiple(querystring,actionIndex){
        if(!isProcessing[actionIndex])
                isProcessing[actionIndex] = 0;

        if(isProcessing[actionIndex] == 0){
                isProcessing[actionIndex] = 1;
                setTimeout('isProcessing["'+actionIndex+'"]=0', 30000);
                callToServerMultiple("remote.aspx?" + querystring + "&actionIndex=" +actionIndex,actionIndex);
                return true;
        }else
        return false;
}

function ReSizePod(key,actionId,podid,newWidth,region,order,podcd,mappingcd,podusernocd){
        var encUno = Get('EncUno');
        SetRemote("remote.aspx?encUno=" + encUno.value +"&key="+key+"&parameters=" + actionId + "|" + podid + "|" + newWidth + "|" + region + "|" + order + "|" + podcd + "|" + mappingcd + "|" + podusernocd, key)
}


function GetInnerDivContent(wholetext){
        var text = TrimString(wholetext);
        if(text.toLowerCase().indexOf("<div") > -1 && text.toLowerCase().lastIndexOf("</div>") > -1){
                var start = text.toLowerCase().indexOf("<div");
                text = text.substring(start,text.length);
                idx = text.indexOf(">")+1;
                text = text.substring(idx,text.length);
                var end = text.toLowerCase().lastIndexOf("</div>");
                text = text.substring(0,end);
                return text;
        }
        return wholetext;
}

function TrimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

function GetInnerDivContentForBYOP(wholetext){
        if(wholetext.toLowerCase().indexOf("<div") == 0){
                idx = wholetext.indexOf(">")+1;
                wholetext = wholetext.substring(idx,wholetext.length);
                wholetext = wholetext.substring(0,wholetext.length-6);
        }
        return wholetext;
}

function Event(ev)
{
        return (ev) ? ev : ((window.event) ? event : null);
}
function pNm(r,i)
{
        var srk = Get("SUPER_RANDOM_KEY");
        if (srk)
                return "pod"+r+"_"+i+"_"+srk.value;
        return "pod"+r+"_"+i+"_";
}
function DestroyDiv(el)
{
        if(!el)
                return;

        el.style.visibility = 'hidden';
        el.style.left = '-1000px';
        el.style.top  = '-1000px';
        el.innerHTML  = '';
}

function MoveEl(el,cx,cy,ox)
{
        el.style.left=(ox)+(cx-x)+'px';
        el.style.top=(cy + document.body.scrollTop) + 'px';
}

function stopper(){
        Get('temp');
}

function Querystring(qs) { // optionally pass a querystring to parse
        this.params = new Object()
        this.get=Querystring_get
        if (qs == null)
                qs=location.search.substring(1,location.search.length)
        if (qs.length == 0) return

        qs = qs.replace(/\+/g, ' ')
        var args = qs.split('&')

        for (var i=0;i<args.length;i++) {
                var value;
                var pair = args[i].split('=')
                var name = unescape(pair[0])

                if (pair.length == 2)
                        value = unescape(pair[1])
                else
                        value = name
                this.params[name] = value
        }
}

function Querystring_get(key, default_) {
        if (default_ == null) default_ = null;

        var value=this.params[key]
        if (value==null) value=default_;

        return value
}

// find out all the images have been loaded up or not ....

function addReadyStateImageCnt()
{
        var obj = event.srcElement;

        // If the image has just loaded, update the count
        if (obj.readyState == "complete")
                totalReadyImages++;
        else
                obj.onreadystatechange = addReadyStateImageCnt;

        if(totalReadyImages == totalImageCnt  )
        {
                d = new Date();
                presentTime = calcTime(d);
                SetRemote("/profile/remote.aspx?SetPresentTime=" + presentTime +"&cft=" + convertedfirsttime+'|'+url, "SetPresentTime");
        }
}


// Event fired from HTML of the client
var totalReadyImages;
var totalImageCnt;
var firsttime;
var convertedfirsttime;

        function Intime()
        {
            firsttime = new Date();
            convertedfirsttime = calcTime(firsttime);
                // reset values
                totalReadyImages = 0;
                var timerID = 0;
                totalImageCnt = 0;

                // go thru the document
                //get the url of the current application here
                url  = window.location.href;
                var images = parent.document.getElementsByTagName("img");
                totalImageCnt = images.length;
                timerID = setTimeout('brokenimage()',60000);

                        for(i=0; i < images.length; i++)
                        {

                                imgvar = images.item(i);
                                if(imgvar.readyState == "complete")
                                        totalReadyImages++;
                                else
                                        imgvar.onreadystatechange = addReadyStateImageCnt;
                        }

                        if(totalReadyImages == totalImageCnt )
                        {
                           if(timerID)
                  clearTimeout(timerID);
                     d = new Date();
                                presentTime = calcTime(d);
                                SetRemote("/profile/remote.aspx?SetPresentTime=" + presentTime +"&cft=" + convertedfirsttime+'|'+url, "SetPresentTime");

                        }
        }


        // If the one of the image is broken
        function brokenimage()
        {
           var images = document.getElementsByTagName("img");
           var nullimage = new Array();
                for(i=0; i < images.length; i++)
                        {
                                imgvar = images.item(i);
                                if(imgvar.readyState != "complete")
                                         nullimage[i] = imgvar.href;
                                else
                                        imgvar.onreadystatechange = addReadyStateImageCnt;
                        }
                d = new Date();
                presentTime = calcTime(d);
                SetRemote("/profile/remote.aspx?SetPresentTime=" + presentTime +"&cft=" + convertedfirsttime+'|'+url, "SetPresentTime");

        }

   // setting the varaible to zero ....

        function VerifySetTime(content)
        {
                isProcessing["SetPresentTime"] = 0;

        }


function calcTime(d)
{
   utc = d.getTime() + (d.getTimezoneOffset() * 60000);
   nd = new Date(utc + (3600000*(-8)));
   PTdatestring = getstringformat(nd);
   return PTdatestring;
}

function getstringformat(nd)
{
   MM =nd.getMonth()+1 ;
   dd= nd.getDate();
   yy = nd.getFullYear();
   HH = nd.getHours();
   mm = nd.getMinutes();
   SS = nd.getSeconds();
   ms = nd.getMilliseconds();
   return ( MM + '/' + dd + '/' +  yy +' '+ HH+':'+ mm + ':'+ SS + '.' + ms);
}

function EmailIsValid(CheckEmail)
{
        var at="@";
        var dot=".";
        var lat=CheckEmail.indexOf(at);
        var lstr=CheckEmail.length;
        var ldot=CheckEmail.indexOf(dot);
        if (CheckEmail.indexOf(at)==-1)
        {
           return false;
        }
        if (CheckEmail.indexOf(at)==-1 || CheckEmail.indexOf(at)==0 || CheckEmail.indexOf(at)==lstr)
        {
           return false;
        }
        if (CheckEmail.indexOf(dot)==-1 || CheckEmail.indexOf(dot)==0 || CheckEmail.indexOf(dot)==lstr)
        {
           return false;
        }
        if (CheckEmail.indexOf(at,(lat+1))!=-1)
        {
           return false;
        }
        if (CheckEmail.substring(lat-1,lat)==dot || CheckEmail.substring(lat+1,lat+2)==dot)
        {
           return false;
        }
        if (CheckEmail.indexOf(dot,(lat+2))==-1)
        {
           return false;
        }
        if (CheckEmail.indexOf(" ")!=-1)
        {
           return false;
        }

         return true;
}

function hasMarkup(inptxt){
        var re= new RegExp('<[^><]*>|<.[^><]*>','g')
        if (inptxt.match(re))
        {
                return true;
        }
        else
        {
                return false;
        }
}

function textRemaining()        {

        var nMaxMessageLength = 120;

        var oMessage = Get("txtMessageBox") ;
        var charLeftText = Get("numCharLeft");

        var charsLeft = nMaxMessageLength - oMessage.innerText.length;
        charLeftText.innerHTML = "&nbsp;" + charsLeft + "&nbsp;";

        if ( charsLeft <= 0 )
        {
           oMessage.blur();
        }

}

function trimAll(sString)
{
        sString = sString.replace(/\s/gi,"");
        return sString;
}

function isNumeric(input)
{
        var numRegEx = "^\\d+$";
        var regex = new RegExp(numRegEx);
        if (!regex.test(input))
        {
                return false;
        }
        else
        {
                return true;
        }
}

function GoToURL(url)
{
        window.location = url;
}