var ns = (document.layers) ? 1:0;
var ns6 = (document.sidebar) ? 1:0;
var agt=navigator.userAgent.toLowerCase();
var is_ie=(agt.indexOf("msie")!=-1);
var is_net=(agt.indexOf("mozilla/5")!=-1);
var is_mac = agt.indexOf("mac")>-1;

if(is_ie || is_net) {
	var ie=true;
}   

if (ns) {
	widthCheck = window.innerWidth
	heightCheck = window.innerHeight
	window.onResize = resizeFix
}
function openwin(name,myname,mywidth,myheight,mytool,mydir,mystatus,myscroll,myresize,mymenu) 
{
	mytop=Math.floor((screen.height/2) - (myheight/2));
	myleft=Math.floor((screen.width/2) - (mywidth/2));
	debute =window.open(name,myname,"toolbar="+mytool+",width="+mywidth+",height="+myheight+",directories="+mydir+",status="+mystatus+",scrollbars="+myscroll+",top="+mytop+",left="+myleft+",resizable="+myresize+",menubar="+mymenu)
}


function opnPop(mypage)
{
	if (is_ie && ! is_mac)
        {
		if (typeof win == "undefined")
			window.open(mypage,'','fullscreen=1');
        }
	else
        {
		var win=window.open(mypage,'ahs','width='+screen.width+',height='+screen.height+',top=0,left=0');
        }
}

function resizeFix() {
	if (widthCheck != window.innerWidth || heightCheck != window.innerHeight)
                document.location.href = document.location.href
}

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		this.obj = getObjNN4(document,name);
		this.style = this.obj;
	}
}	

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var thereturn;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	thereturn = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) thereturn = tmp;
	}
	return thereturn;
}

var isfullscreen = false;
var isWin = (navigator.userAgent.indexOf('Win') != -1);
var isWinXP = (navigator.userAgent.indexOf('Windows NT 5.1') != -1);
var isIE = (navigator.userAgent.indexOf('MSIE') != -1);
var isNS = (navigator.userAgent.indexOf('Mozilla') != -1) && (navigator.userAgent.indexOf('Firefox') == -1);
var isFirefox = (navigator.userAgent.indexOf('Firefox') != -1);
var isMAC = (navigator.platform.indexOf('Mac') != -1);
var version = parseInt(navigator.appVersion);
var previousXPosition = 0;
var previousYPosition = 0;
var previousWidth = 0;
var previousHeight = 0;

function openFullscreen(url,newwindow,reload, titlebar) {
	reload = (typeof reload=="undefined") ? true : reload;
	if(isIE) {
		previousXPosition = top.window.screenLeft;
		previousYPosition = top.window.screenTop;
		previousWidth = document.body.clientWidth;
		previousHeight = document.body.clientHeight;
	} else if(self.outerWidth) {
		previousXPosition = self.screenX;
		previousYPosition = self.screenY;
		previousWidth = self.outerWidth;
		previousHeight = self.outerHeight;
	} else {
		previousXPosition = top.window.screenLeft;
		previousYPosition = top.window.screenTop;
		previousWidth = document.body.clientWidth;
		previousHeight = document.body.clientHeight;
	}
	if(isWin && isIE) {
		top.window.resizeTo(screen.width/2,screen.height/2);
		top.window.moveTo(0,0);
		var wleftdiff = top.window.screenLeft;
		var wrightdiff = (screen.width/2) - top.window.document.body.clientWidth - wleftdiff;
		var htopdiff = top.window.screenTop;
		var hbottomdiff = (screen.height/2) - top.window.document.body.clientHeight - htopdiff;
		var newXPosition = -wleftdiff;
		var newYPosition = -htopdiff;
		var newWidth = screen.width+wleftdiff+wrightdiff;
		var newHeight = screen.height+htopdiff+hbottomdiff;
		if((newWidth>screen.width) && (newHeight>screen.height)) {
			previousXPosition -= wleftdiff;
			previousYPosition -= htopdiff;
			previousWidth += wleftdiff+wrightdiff;
			previousHeight += htopdiff+hbottomdiff;
		}
		top.window.resizeTo(previousWidth,previousHeight);
		top.window.moveTo(previousXPosition,previousYPosition);
		parameters = "x="+previousXPosition+"&y="+previousYPosition+"&width="+previousWidth+"&height="+previousHeight;
		if(isWinXP || newwindow) {
			url = (url.indexOf('?') != -1) ? url+"&"+parameters : url+"?"+parameters;

            if(!titlebar)
            {
                arg = 'fullscreen=yes'
            }
            else
            {
                deltaWidth = -8;
                deltaHeight = -30;
                
                newWidth = screen.width + deltaWidth;
                newHeight = screen.height + deltaHeight;

                arg = 'width='+newWidth+',height='+newHeight+',left=0,top=0,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0'                
            }

            
			window.open(url,'chanelfullscreen', arg);
            if(!newwindow)
            {
                top.window.opener = top;
                top.window.close();
            }
		} else {
			top.window.moveTo(newXPosition-2,newYPosition-2);
			top.window.resizeTo(newWidth,newHeight);
			if(reload) {
				top.location.href = (url.indexOf('?') != -1) ? url+"&"+parameters : url+"?"+parameters;
			}
		}
	} else {
		deltaWidth = (isNS) ? ((isMAC) ? -10 : -5) : ((isMAC) ? -5 : 0);
		deltaHeight = (isNS) ? ((isMAC) ? -50 : -50) : ((isMAC) ? -2 : -30);
		deltaLeft = (isNS) ? ((isMAC) ? -6 : -6) : ((isMAC) ? -5 : -5);
		deltaTop = (isNS) ? ((isMAC) ? -30 : -30) : ((isMAC) ? -10 : -30);
		newWidth = screen.width + deltaWidth;
		newHeight = screen.height + deltaHeight;
		parameters = "x="+previousXPosition+"&y="+previousYPosition+"&width="+previousWidth+"&height="+previousHeight;
		url = (url.indexOf('?') != -1) ? url+"&"+parameters : url+"?"+parameters;
		newwin = window.open(url,'chanelfullscreen', 'width='+newWidth+',height='+newHeight+',left=0,top=0,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');
		newwin.resizeTo(newWidth,newHeight);
		newwin.moveTo(0,0);
        if(!newwindow)
        {
            top.window.opener = top;
            top.window.close();
        }
	}
}

function openFullbridalscreen(url,newwindow,reload, titlebar) {
	reload = (typeof reload=="undefined") ? true : reload;
	if(isIE) {
		previousXPosition = top.window.screenLeft;
		previousYPosition = top.window.screenTop;
		previousWidth = document.body.clientWidth;
		previousHeight = document.body.clientHeight;
	} else if(self.outerWidth) {
		previousXPosition = self.screenX;
		previousYPosition = self.screenY;
		previousWidth = self.outerWidth;
		previousHeight = self.outerHeight;
	} else {
		previousXPosition = top.window.screenLeft;
		previousYPosition = top.window.screenTop;
		previousWidth = document.body.clientWidth;
		previousHeight = document.body.clientHeight;
	}
	if(isWin && isIE) {
		top.window.resizeTo(screen.width/2,screen.height/2);
		top.window.moveTo(0,0);
		var wleftdiff = top.window.screenLeft;
		var wrightdiff = (screen.width/2) - top.window.document.body.clientWidth - wleftdiff;
		var htopdiff = top.window.screenTop;
		var hbottomdiff = (screen.height/2) - top.window.document.body.clientHeight - htopdiff;
		var newXPosition = -wleftdiff;
		var newYPosition = -htopdiff;
		var newWidth = screen.width+wleftdiff+wrightdiff;
		var newHeight = screen.height+htopdiff+hbottomdiff;
		if((newWidth>screen.width) && (newHeight>screen.height)) {
			previousXPosition -= wleftdiff;
			previousYPosition -= htopdiff;
			previousWidth += wleftdiff+wrightdiff;
			previousHeight += htopdiff+hbottomdiff;
		}
		top.window.resizeTo(previousWidth,previousHeight);
		top.window.moveTo(previousXPosition,previousYPosition);
		parameters = "x="+previousXPosition+"&y="+previousYPosition+"&width="+previousWidth+"&height="+previousHeight;
		if(isWinXP || newwindow) {
			url = (url.indexOf('?') != -1) ? url+"&"+parameters : url+"?"+parameters;

            if(!titlebar)
            {
                arg = 'fullscreen=yes'
            }
            else
            {
                deltaWidth = -8;
                deltaHeight = -30;
                
                newWidth = screen.width + deltaWidth;
                newHeight = screen.height + deltaHeight;

                arg = 'width='+newWidth+',height='+newHeight+',left=0,top=0,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0'                
            }

            
			window.open(url,'chanelbridalfullscreen', arg);
            if(!newwindow)
            {
                top.window.opener = top;
                top.window.close();
            }
		} else {
			top.window.moveTo(newXPosition-2,newYPosition-2);
			top.window.resizeTo(newWidth,newHeight);
			if(reload) {
				top.location.href = (url.indexOf('?') != -1) ? url+"&"+parameters : url+"?"+parameters;
			}
		}
	} else {
		deltaWidth = (isNS) ? ((isMAC) ? -10 : -5) : ((isMAC) ? -5 : 0);
		deltaHeight = (isNS) ? ((isMAC) ? -50 : -50) : ((isMAC) ? -2 : -30);
		deltaLeft = (isNS) ? ((isMAC) ? -6 : -6) : ((isMAC) ? -5 : -5);
		deltaTop = (isNS) ? ((isMAC) ? -30 : -30) : ((isMAC) ? -10 : -30);
		newWidth = screen.width + deltaWidth;
		newHeight = screen.height + deltaHeight;
		parameters = "x="+previousXPosition+"&y="+previousYPosition+"&width="+previousWidth+"&height="+previousHeight;
		url = (url.indexOf('?') != -1) ? url+"&"+parameters : url+"?"+parameters;
		newwin = window.open(url,'chanelbridalfullscreen', 'width='+newWidth+',height='+newHeight+',left=0,top=0,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');
		newwin.resizeTo(newWidth,newHeight);
		newwin.moveTo(0,0);
        if(!newwindow)
        {
            top.window.opener = top;
            top.window.close();
        }
	}
}




