//Common Javascript Start 

try 
{
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

//Newly function added by Nimesh 31 Mar 08 starts here =========================

function setPageLayoutImage(strLayout,strImgSrc,PageID)
{

    if(window.top.document.getElementById('pg_tblLeftPanel'))
    {
        window.top.document.getElementById('pg_tblLeftPanel').className = 'mcont';
        window.top.document.getElementById('pg_tblRightPanel').className = 'mcont';
        window.top.document.getElementById('pg_tblLeftRightPanel').className = 'mcont';
        window.top.document.getElementById('pg_tblOnlyCenterPanel').className = 'mcont';
        
        if(strLayout == 'LEFT')
            window.top.document.getElementById('pg_tblLeftPanel').className = 'hmcont';        
        else if(strLayout == 'RIGHT')
            window.top.document.getElementById('pg_tblRightPanel').className = 'hmcont';
        else if(strLayout == 'LEFTRIGHT')
            window.top.document.getElementById('pg_tblLeftRightPanel').className = 'hmcont';
        else if(strLayout == 'CENTER')
            window.top.document.getElementById('pg_tblOnlyCenterPanel').className = 'hmcont';
            
        window.top.document.getElementById('pg_imgSiteLayout').src = strImgSrc;   
        
        window.top.document.getElementById('pg_hidPageID').value = PageID;     
    }
    
}

function toggleClick(str)
{    
    if(str == "SYS")
    {    
        document.getElementById('liSys').style.display = "none";    
        document.getElementById("liCP").style.display = "";
        
        document.getElementById("buttlayout").style.display = "none";
        document.getElementById("buttsitemap").style.display = "none";
    }
    else
    {
        document.getElementById("liSys").style.display = ""
        document.getElementById("liCP").style.display = "none";
        
        document.getElementById("buttlayout").style.display = "";
        document.getElementById("buttsitemap").style.display = "";
    }
    return true;
}

function getQval(name)
{

    try
    {
        var m, Q = window.parent.location.search.substring(1);
        if ('' != Q)
        {
        var re = new RegExp(escape(name) + '=([^&$]+)');
        if (m = Q.match(re))
        return m[1];
        else return '';
        }
        return '';
    }
    catch(obj){}
    
}

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 transferToIndexPage()
{
    //if(window.parent.frames.length < 1)
    if(getQval('url') == '')
    {    
        window.location.href="/index.aspx?url=" + URLEncode(window.location.href + '');
    }
}

function Newshowpopup(url,width,height,winname,otitle)
{ 

    try
    {
        window.top.NewShowpopup2(url,width,height,winname,otitle);
        return false;
    }
    catch(obj){}           
    
} 

function NewShowpopup2(url,width,height,winname,otitle)
{
    try
    {
        var wndHandle = $find('dialogMain');
    
        wndHandle.setUrl(url);  
        wndHandle.set_Title(otitle);  
        wndHandle.show();
        return false;
    }
    catch(obj){}    
}





//Ends here ====================================================================

function fixActiveX()
{
	//Fix ActiveX Activation Issue
	try
	{
		objects = document.getElementsByTagName("object");
		for (var i = 0; i < objects.length; i++)
		{
        		objects[i].outerHTML = objects[i].outerHTML;
		}
	}
	catch(obj2)
	{
	}
	return true;
}

function Redirect(url)
{
    location.href = url;
}

function imagePreLoader()
{
    /*var imgs=new Array()
    imgs[0]="/Skins/Default/Window/close.gif"
    imgs[1]="/Skins/Default/Window/CommandSprites.gif"
    imgs[2]="/Skins/Default/Window/Default.gif"
    imgs[3]="/Skins/Default/Window/FooterSprites.gif"
    imgs[4]="/Skins/Default/Window/Icon.gif"
    imgs[5]="/Skins/Default/Window/Loading.gif"
    imgs[6]="/Skins/Default/Window/StatusBarSprites.gif"
    imgs[7]="/Skins/Default/Window/WindowCornerSprites.gif"
    imgs[8]="/Skins/Default/Window/WindowResizeHandle.gif"
    imgs[9]="/Skins/Default/Window/WindowSprites.gif"
    imgs[10]="/Skins/Default/Window/WindowVerticalSprites.gif"
 
    //preload
    var img = new Image();
	for(i=0;i<imgs.length;i++)
    {
		img.src = imgs[i];
    }
    */
}

function subValidate()
{
        var url;
        url = window.location.href;
        if(url.indexOf('http://6')>-1)
        {
            alert('Please click View Original Web Page from the top of the Page');
            return false;
        }
        else
        {
            
		    if (typeof(ValidatorOnSubmit) == "function")
                return ValidatorOnSubmit();
        }
}

function OnClientDock(dockObj, eventArgs)
{
        var resDoc = '';
        var dDocMgr = Telerik.Web.DragDropManager._instance;
        var dZones = dDocMgr._dropTargets;
        for(j=0;j<dZones.length;j++)
        {
            var dZone = dZones[j];
            if(dZone.get_Docks)
            {
                var docObjs = dZone.get_Docks();
                if(docObjs)
                {
                    for(i=0;i<docObjs.length;i++)
                    {
                        var lobj = docObjs[i];
                        resDoc += lobj.get_UniqueID() + ':' + dZone.get_id() + ":" + lobj._index + '|';
                    }
                }
            }
        }
        
       //Old code commented By Nimesh 31 Mar 08        
        //$get('adminBar_ajaxCommandName').value = 'reorder';
        //$get('adminBar_ajaxCommandArgs').value = resDoc;

        //Newly added code By Nimesh 31 Mar 08
        $get('ajaxCommandName').value = 'reorder';
        $get('ajaxCommandArgs').value = resDoc;

       window.setTimeout(postAjaxCommandToPage,500);
}

    
  
function postAjaxCommandToPage()
{
    //Old code commenete By Nimesh 31 Mar 08
    //postBackHiddenField('adminBar_hidData');
    
    //Newly added code By Nimesh 31 Mar 08
    postBackHiddenField('hidData');
    
    cshowDialog();
}
    
function postBackHiddenField(hiddenFieldID) 
{
        var hiddenField = $get(hiddenFieldID);
        if (hiddenField)
        {
            hiddenField.value = (new Date()).getTime();
            __doPostBack(hiddenFieldID,'ValueChanged');
        }
}


function MainPopup(url,width,height,winname,otitle)
{
    var wndHandle;
    wndHandle = $find('dialogMain');
    wndHandle.setUrl(url);  
    wndHandle.set_Title(otitle);  
    wndHandle.show();
    return false;
}
    
function showpopup(url,width,height,winname,otitle)
{   
    try
    {
        window.top.MainPopup(url,width,height,winname,otitle);
        return false;
    }
    catch(obj){}     
} 



 var theWidth, theHeight;  
 
  function FindParentSize() 
  { 
    // Window dimensions: 
    if (window.innerWidth) { 
        theWidth=window.innerWidth; 
    } 
    else if (document.documentElement && document.documentElement.clientWidth) { 
        theWidth=document.documentElement.clientWidth; 
    } 
    else if (document.body) { 
        theWidth=document.body.clientWidth; 
    } 
    if (window.innerHeight) { 
        theHeight=window.innerHeight; 
    } 
    else if (document.documentElement && document.documentElement.clientHeight) { 
        theHeight=document.documentElement.clientHeight; 
    } 
    else if (document.body) { 
        theHeight=document.body.clientHeight; 
    } 
  } 
   
function MainWinShown(radWindow)
{
    if(radWindow)
        radWindow.center();
}  
    
function AjaxEndRequestHandler(sender,args)
{
    //Old code commeneted by Nimesh 31 Mar 08
    //var ref =  $get('adminBar_reqRef').value;
    
    //Newly added code By Nimesh 31 Mar 08
    var ref =  $get('reqRef').value;
    
    if(ref=='true')
        refreshRVPortalPage();
    window.setTimeout(hideDialog,500);
}

function oDisableScroll()
{
     /*if(document.documentElement && document.documentElement.scrollTop)     
     {     
        var oTop = document.documentElement.scrollTop;     
        document.documentElement.scroll = "no";     
        document.documentElement.style.overflow = "hidden";     
        document.documentElement.scrollTop = oTop;     
                     
      } 
      else if(document.body)     
      {     
        var oTop = document.body.scrollTop;     
        document.body.scroll = "no";     
        document.body.style.overflow = "hidden";     
        document.body.scrollTop = oTop;     
      }*/     
}

function MainWinClosed(radWindow)
{    
    
    refreshRVPage();    
}   


function refreshRVPage()
{
    //iAdmin.window.location.href = iAdmin.window.location.href;    
    window.frames[0].location.reload(true); 
}

function refreshRVPageWithUrl(strUrl)
{
    //iAdmin.window.location.href = iAdmin.window.location.href;    
    window.frames['iAdmin'].location.href = strUrl; 
}

function refreshRVPortalPage()
{
    //iAdmin.window.location.href = iAdmin.window.location.href;
    window.top.frames[0].location.reload(true); 
}


function ShowAlert(msg)
{
    alert(msg);
}


/* Main CMS Page Javascript Ends here */


/* Menu Related Scripts */
var timeoutid;
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) {
v=args[i+2];
    if (obj.style) { obj=obj.style;
    if (v=='show'){
    obj.top=findPosY("img"+args[i])+21+"px";

    obj.left=findPosX("img"+args[i])+"px";  
//	alert(obj.left);
    }
v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; 
    }
}


function CustomShowHide(menuname)
{
var currentmenu;
currentmenu = MM_findObj(menuname);

if (currentmenu.style.display == "none")
{
    MM_showHideLayers(menuname,'','show');
	
}
else
{
    timeoutid = setTimeout("myTimeout('" + menuname +"');", 500);
}

}


function myTimeout(mnu)
{
// alert(showmenu);
MM_showHideLayers(mnu,'','hide');
}


function Stickit()
{  
	clearTimeout(timeoutid);
}

function findPosX(imgtext)
{
	var obj = window.document.getElementById(imgtext);
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	//alert(curleft + " ");	
	return curleft;
	
	//return 300;
}
function findPosY(imgtext)
{
	var obj = window.document.getElementById(imgtext);
	var curtop = 0;
	if (imgtext == "imgdivMenu")
	{
	    var curtop = 20;
	   
	}
	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
    
	return curtop;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

/* Menu Commands End Here */

/* RV Page Commands */

function ToggleShowInAllpage(mid)
{
       //Old Code Commented By Nimesh 31 Mar 08       
//       $get('adminBar_ajaxCommandName').value = 'togshowInAll';
//       $get('adminBar_ajaxCommandArgs').value = mid;

       //Newly added code By Nimesh 31 Mar 08
       $get('ajaxCommandName').value = 'togshowInAll';
       $get('ajaxCommandArgs').value = mid;

       window.setTimeout(postAjaxCommandToPage,500);
}

function PubModule(mid)
{
       //Old Code Commented By nimesh 31 Mar 08
       //$get('adminBar_ajaxCommandName').value = 'pubModule';
       //$get('adminBar_ajaxCommandArgs').value = mid;
       
       //Newly Added code By Nimesh 31 Mar 08
       $get('ajaxCommandName').value = 'pubModule';
       $get('ajaxCommandArgs').value = mid;
       
       window.setTimeout(postAjaxCommandToPage,500);
}

function HideModule(mid)
{
       //Old Code Commented By nimesh 31 Mar 08
       //$get('adminBar_ajaxCommandName').value = 'hideModule';
       //$get('adminBar_ajaxCommandArgs').value = mid;
       
       //Newly added code By Nimesh 31 Mar 08
       $get('ajaxCommandName').value = 'hideModule';
       $get('ajaxCommandArgs').value = mid;
       
       window.setTimeout(postAjaxCommandToPage,500);
}

function DelModule(mid)
{
       var conf = confirm("Are you sure you want to delete this Module ?");
       if(conf)
       {
            //Old code commented by Nimesh 31 Mar 08            
            //$get('adminBar_ajaxCommandName').value = 'delModule';
            //$get('adminBar_ajaxCommandArgs').value = mid;
            
            //Newly added code By Nimesh 31 Mar 08
            $get('ajaxCommandName').value = 'delModule';
            $get('ajaxCommandArgs').value = mid;
            
            window.setTimeout(postAjaxCommandToPage,500);
       }
}

function popupSSL()
{
    //Old code commented by Nimesh 31 Mar 08
    //var wndHandle = $find('adminBar_dialogMain');
    
    //Newly added code By Nimesh 31 Mar 08
    var wndHandle = window.top.$find('dialogMain');
    
    wndHandle.setUrl("/sys/SSLConfirmation.aspx?mode=direct");  
    wndHandle.set_Title("Please wait Loading...");  
    wndHandle.setSize(350,200);
    wndHandle.center();
    wndHandle.show();
    return false;
}

/* RV Page Command Ends */

// Modal Dialog Box
function pageWidth()
{
    return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}
function pageHeight() 
{
    return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}

function posLeft() 
{
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}

function posTop() 
{
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}

function $(x)
{
    return document.getElementById(x);
}

function scrollFix()
{
    var obol=$('ol');obol.style.top=posTop()+'px';
    obol.style.left=posLeft()+'px'
}

function sizeFix()
{
    
    var obol=$('ol');
    obol.style.height=pageHeight()+'px';
    obol.style.width=pageWidth()+'px';
}

function kp(e)
{
    ky=e?e.which:event.keyCode;
    if(ky==88||ky==120)hm();
    return false
}

function inf(h)
{
    tag=document.getElementsByTagName('select');
    for(i=tag.length-1;i>=0;i--)
        tag[i].style.visibility=h;
    tag=document.getElementsByTagName('iframe');
    for(i=tag.length-1;i>=0;i--)
        tag[i].style.visibility=h;
    tag=document.getElementsByTagName('object');
    for(i=tag.length-1;i>=0;i--)
        tag[i].style.visibility=h;
}

function sm(obl, wd, ht)
{
    var h='hidden';
    var b='block';
    var p='px';
    var obol=$('ol'); 
    var obbxd = $('mbd');
    obbxd.innerHTML = $(obl).innerHTML;
    obol.style.height=pageHeight()+p;
    obol.style.width=pageWidth()+p;
    obol.style.top=posTop()+p;
    obol.style.left=posLeft()+p;
    obol.style.display=b;
    var tp=posTop()+((pageHeight()-ht)/2)-12;
    var lt=posLeft()+((pageWidth()-wd)/2)-12;
    var obbx=$('mbox');
    obbx.style.top=(tp<0?0:tp)+p;
    obbx.style.left=(lt<0?0:lt)+p;
    obbx.style.width=wd+p;
    obbx.style.height=ht+p;
    inf(h);
    obbx.style.display=b;
    return false;
}
    
function hm()
{
    if($('ol'))
    {
        var v='visible';var n='none';
        $('ol').style.display=n;
        $('mbox').style.display=n;
        inf(v);
        document.onkeypress=''
    }
}

function initmb()
{
    var ab='absolute';var n='none';
    var obody=document.getElementsByTagName('body')[0];
    var frag=document.createDocumentFragment();
    var obol=document.createElement('div');
    obol.setAttribute('id','ol');
    obol.style.display=n;
    obol.style.position=ab;
    obol.style.top=0;
    obol.style.left=0;
    obol.style.zIndex=998;
    obol.style.width='100%';
    frag.appendChild(obol);
    var obbx=document.createElement('div');
    obbx.setAttribute('id','mbox');
    obbx.style.display=n;
    obbx.style.position=ab;
    obbx.style.zIndex=999;
    var obl=document.createElement('span');
    obbx.appendChild(obl);
    var obbxd=document.createElement('div');
    obbxd.setAttribute('id','mbd');
    obl.appendChild(obbxd);
    frag.insertBefore(obbx,obol.nextSibling);
    obody.insertBefore(frag,obody.firstChild);
    window.onscroll = scrollFix; window.onresize = sizeFix;
}
window.onload = initmb;

function cshowDialog()
{
    if (typeof(ValidatorOnSubmit) == "function")
    {
        if(Page_IsValid==true)
            sm('box',20,20);
        else
            return false;
    }
    else
    {
        sm('box',20,20);
        return true;
    }
}


function hookAjax()
{
    try
    {
        var orq = Sys.WebForms.PageRequestManager.getInstance();
        if(orq)
            orq.add_endRequest(EndRequestHandler);
    }
    catch(obj)
    {}
}

function EndRequestHandler(sender,args)
{
    hideDialog();
}
    
function hideDialog()
{
    hm('box');
}
                      
//Common Javascript Ends here


