﻿// JScript File
var ALLOWD_IFRAMES = 0;
function IsInIFrame()
{
    var ret = false;
    if (window.parent.frames.length>ALLOWD_IFRAMES) 
    {
        ret = true;
    }
    return ret;
}

function GetIFrameMe()
{
}
function HandleWindow(iframeElem)
{
    alert ('here');
}
 
function Test()
{
    alert (parent.frameElement);
    //alert(window.frameElement);
}
function FixMoveHelper()
{
    var divs = document.getElementsByTagName('div');
    var len = divs.length;
    var urlTmp = window.location.href;
    var urlMe = urlTmp.toLowerCase().indexOf('user');
    for(var i =0;i<len;i++)
    {
        if(divs[i] != null)
        {
            var moveHelperTo = divs[i].getAttribute('moveHelperTo');
            if (moveHelperTo!=null)
            {
                divs[i].innerHTML = '';
                divs[i].style.visibility='hidden';
            }
            else
            {
                if(urlMe != -1)
                {
                    var isAdminMode = divs[i].getAttribute('isadmin');
                    if (isAdminMode!=null)
                    {
                        if(GetSize_2(isAdminMode) == 1)
                        {
                            divs[i].innerHTML = '';
                            divs[i].style.visibility='hidden';
                        }
                    }
                }
            }
        }
    }   
}
function GetSize_2 (size)
{
    if( size == null)
    {
        return -1;
    }
    else if (size.replace)
    {
        if( size == '')
        {
            return 0;
        }
        else
        {
            return parseInt(size.replace('px',''));
        }
    }
    else 
    {
        return size;
    }
}
///replace textarea to real label
function FixLabels()
{
 var textAreas = document.getElementsByTagName('textarea');
 var len = textAreas.length;

    for(var i =0;i<len;i++)
    {
        var cuuElemInLoop = textAreas[i];
        if (cuuElemInLoop!=null)
        {
            var type = cuuElemInLoop.getAttribute('ctlType');
            if (type == 'Label')
            {
                var parentCont  = cuuElemInLoop.parentNode;
                var dv1 = document.createElement('div');
                var dirVal = parentCont.getAttribute('dir');
                dv1.setAttribute('dir', dirVal);
                
                dv1.style.cssText = cuuElemInLoop.style.cssText;
                
                var textAlignVal = cuuElemInLoop.style.textAlign;//'left';
                if( textAlignVal == '')
                {
                    textAlignVal = 'left';
                    if(dirVal == 'rtl')
                    {
                        textAlignVal = 'right';
                    }
                }
                dv1.style.textAlign = textAlignVal;
                // fix enters
                var val = cuuElemInLoop.innerHTML; 
                val = val.replace( new RegExp( NEW_LINE_TAG, "g" ), '<br />' ); 
//                while(val.indexOf(NEW_LINE_TAG) != -1)
//                {                
//                    val = val.replace(NEW_LINE_TAG,'<br />');
//                } 
                val = val.replace( new RegExp( '\r\n', "g" ), '<br />' ); 
//                while(val.indexOf('\r\n') != -1)
//                {                
//                    val = val.replace('\r\n','<br />');
//                } 
                //( new RegExp( '\r\n', "g" ), '' );
                 val = val.replace( new RegExp( '\n', "g" ), '<br />' );
//                 while(val.indexOf('\n') != -1)
//                {                
//                    val = val.replace('\n','<br />');
//                }   
                dv1.innerHTML = val;
                parentCont.removeChild(cuuElemInLoop);
                parentCont.appendChild(dv1);
                FixLabels();
                break;
            }
            else
            {
                cuuElemInLoop.onkeypress = function(){return CatchEnter(this);} 
                cuuElemInLoop.onpaste = function(){return CatchEnter(this);}; 
            }
        }
    }
    //fix 15px bug with default of 18px
    var lst = document.getElementsByTagName('select');
    var len1= lst.length;

    for(var i2 =0;i2<len1;i2++)
    {
        var cuuElemInLoop2 = lst[i2];
        if (cuuElemInLoop2!=null)
        {
                var sz1 = parseInt(GetSize_2(cuuElemInLoop2.style.height));
                if(sz1 == 15)
                {
                    cuuElemInLoop2.style.height = '20px';
                }
         }
    }
    
//    //fix tab index bug of radio and linkform
//   var lstInput = document.getElementsByTagName('input');
//    var lenInput= lstInput.length;
//    for(var iInput =0;iInput<lenInput;iInput++)
//    {
//        var cuuElemInLoopInput = lstInput[iInput];
//        if (cuuElemInLoopInput!=null && cuuElemInLoopInput.id != null)
//        {
//            var  item = cuuElemInLoopInput.id;
//            if( item != '')
//            {
//            //item = item.toLower();
//           
//            //alert(cuuElemInLoopInput.id);
//            //if(cuuElemInLoopInput.parentNode.getAttribute('ctlType') != null)
//            //{
//                //var typeInput = cuuElemInLoopInput.parentNode.getAttribute('ctlType').toLower();
//                //alert(typeInput);
//                if (item.indexOf('RadioButton') == 0)
//                {
//                    alert(cuuElemInLoopInput.parentNode.getAttribute('tabindex'));
//                    cuuElemInLoopInput.setAttribute('tabindex', cuuElemInLoopInput.parentNode.getAttribute('tabindex'));
//                }
////                if (typeInput == 'linkform')
////                {
////                    var o11 = document.getElementById('div_' + cuuElemInLoopInput.id +'__caption').getAttribute('tabIndex');
////                    cuuElemInLoopInput.setAttribute('tabindex', o11);
////                }
//            }        
//        }
//    }
   
    
    
//    var lst2 = document.getElementsByTagName('div');
//    var len2= lst2.length;

//    for(var i3 =0;i3<len2;i3++)
//    {
//        var cuuElemInLoop3 = lst2[i3];
//        if (cuuElemInLoop3!=null)
//        {
//                if(cuuElemInLoop3.getAttribute('ctlType') != null)
//                {
//                     if(cuuElemInLoop3.getAttribute('ctlType') == 'Link')
//                     {
//                       
//                        //cuuElemInLoop3.childNodes[0].style.cursor = 'pointer';
//                        //cuuElemInLoop3.style.cursor = 'pointer';
//                      }
//                }
//         }
//    }
   
}



