﻿var is_ie6p=document.compatMode!==undefined && document.all!==undefined && window.opera===undefined;

var is_ie7=document.documentElement!==undefined && document.documentElement.style.maxHeight!==undefined;

var is_ie6=is_ie6p && !is_ie7;

var tc=false;
function setCookie(cname,value,days)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+days);
    document.cookie=escape(cname)+"="+escape(value)+((days==null) ? "" : ";expires="+exdate.toGMTString());
}
function printview()
{
    var loc=location.host;
    if(loc.toString().indexOf('localhost')>-1)
    loc+=location.pathname.substr(0,location.pathname.indexOf('/',1));
    loc=location.protocol+"//"+loc+"/View/Pages/PrintView.aspx";
    var win=window.open(location.protocol+"//"+loc+"/View/Pages/PrintView.aspx","win","toolbar=no,status=no,location=no,scrollbars=yes,scrollable=yes,resizeable=yes,width=400,height=300");

}
function print()
{
    if (window.print) {
        window.print();
    }
}
function getCookie(cookieName)
{
    var cookieValue = null;
    var posName = document.cookie.indexOf(escape(cookieName) + '=');
    if (posName != -1)
    {
    var posValue = posName + (escape(cookieName) + '=').length;
    var endPos = document.cookie.indexOf(';', posValue);
    if (endPos != -1)
    {
        cookieValue = unescape(document.cookie.substring(posValue, endPos));
    }
    else
    {
        cookieValue = unescape(document.cookie.substring(posValue));
    }
    }
    return cookieValue;
}
function agreement()
{
    var loc=location.host;
    if(loc.toString().indexOf('localhost')>-1)
    loc+=location.pathname.substr(0,location.pathname.indexOf('/',1));
    loc=location.protocol+"//"+loc+"/Pages/Account/Agreement.aspx";
    Popup(400,330,loc);
}
function error()
{
    var tr;
    var str="";
    if(document.selection)
    {
        tr=document.selection.createRange();
        str=tr.text;
    }
    else if(document.getSelection)
        str=document.getSelection();
    if(str=="")
        alert("<%= Resources.ProblemReport.Alert %>")
    else
    {
        if(str.length>500)
        {
            alert("<%= Resources.ProblemReport.Alert %>");
            return;
        }
        setCookie("SelectedText",str,1);
                  
        var loc=location.host;
        if(loc.toString().indexOf('localhost')>-1)
        loc+=location.pathname.substr(0,location.pathname.indexOf('/',1));
        loc=location.protocol+"//"+loc+"/View/Pages/ProblemReport.aspx";
        Popup(400,330,loc);
    }
}
function sendsource(query)
{
        var loc=location.host;
        if(loc.toString().indexOf('localhost')>-1)
        loc+=location.pathname.substr(0,location.pathname.indexOf('/',1));
        loc=location.protocol+"//"+loc+"/View/Pages/SendSource.aspx"+query;
        Popup(370,400,loc);
}
function sendmail(w,url)
{
    var loc=location.host;
    if(loc.toString().indexOf('localhost')>-1)
    loc+=location.pathname.substr(0,location.pathname.indexOf('/',1));
    loc=location.protocol+"//"+loc+"/View/Pages/SendMail.aspx?w="+w+"&url="+url;
    Popup(400,380,loc);
}
function article()
{
    var loc=location.host;
    if(loc.toString().indexOf('localhost')>-1)
    loc+=location.pathname.substr(0,location.pathname.indexOf('/',1));
    loc=location.protocol+"//"+loc+"/View/Pages/SendArticle.aspx";
    Popup(700,490,loc);
}
function gb()
{
	return hb('height');
}
function ib()
{
	return hb('width');
}
function hb(jb)
{
	var kb=0,lb=0;
	if(typeof(window.innerWidth)=='number')
	{
		kb=window.innerWidth;
		lb=window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth||document.documentElement.clientHeight))
	{
		kb=document.documentElement.clientWidth;
		lb=document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth||document.body.clientHeight))
	{
		kb=document.body.clientWidth;
		lb=document.body.clientHeight;
	}
	if(jb=='height')
		return lb;
	if(jb=='width')
		return kb;
}
function Popup(w,h,loc)
{
	pb = document.getElementById("ce");
	if(pb!=null)
	{
		var rc="<div><iframe frameborder=\"0\" id=\"Frame\" src=\""+loc+"\" width=\""+w+"\" height=\""+h+"\" class=\"PopupBox\"></iframe><a href=\"#\" class=\"CloseButton\" onClick=\"Close(); return false;\">Close</a></div>";
		pb.innerHTML=rc;
		pb.style.width=w+20;
		pb.style.height=h+20;
	}
	sc();
	if(!is_ie6&&!tc)
		return false;
	else 
		return true;
}
function Close()
{
	pb=document.getElementById("ce");
	if(pb!=null)
	{
		pb.innerHTML='';
		pb.style.display="none";
	}
}
function sc()
{
	var w = ib(), h = gb();
	pb = document.getElementById("ce");
    document.getElementById("ce").style.position='absolute';
    w = (w-parseInt( pb.style.width)) / 2;
    h = (h-parseInt(pb.style.height)) / 2;
    
    pb.style.top = h;
    pb.style.left = w;
    pb.style.display="block";
}

function changeEnable(chk)
{
    var str;
    if(chk.id.indexOf("Mailing")>0)
        str = "Mailing";
    else
        str = "Messaging";
    var len=document.all.length;
    for(i=0;i<len;i++)
    {
        if(document.all[i].id.indexOf(str)>0 && document.all[i]!=chk)
            document.all[i].disabled=(chk.checked?"":"disabled");
    }
}
        
function requireAdvType()
{
    if(document.activeElement.id.indexOf('btnInsert')<0) return;
    var len=document.forms[0].length;
    var chcount=0;
    var el;
    for(i=0;i<len;i++)
    {
        el=document.forms[0].elements[i];
        if(el.type=="checkbox" && !el.checked)
            chcount++;
    }
    if(chcount==3)
    {
        alert("<%= Resources.Message.SelectAdvertiseType %>");
        return false;
    }
        return true;
    
}

function addEvent(obj,e,fn)
{
     if (obj.attachEvent)
        obj.attachEvent("on"+e,fn);                
    else if(obj.addEventListener)
        obj.addEventListener(e,fn,false);
}

function removeEvent(obj,e,fn)
{
    if(obj.removeEventListener)
        obj.addEventListener(e,fn,false);                
    else if (obj.detachEvent)
        obj.attachEvent("on"+e,fn);
}

function ShowImage(url,obj)
{
    var img=document.getElementById(obj);
    if(img)
    {
        img.src = "../Images/" + url;
    }
}
function makehomepage()
{
    if(document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage("http://www.rtpedia.com");
    }
    else if(window.sidebar)
    {
        if(window.netscape)
        {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage','http://www.rtpedia.com');
    }
}
function searchprovider()
{
    if(window.sidebar)
    {
        alert("<%= Resources.View.Alert %>");
    }
    else
    {
        window.external.AddSearchProvider('Provider.xml');
        
    }
}
 function showHideDetails(elId)
 {
    if($(elId).style.display=="none")
        $(elId).style.display=="block";
    else
        $(elId).style.display=="none"
 }