

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

BrowserDetect.init();
			
function Element_GetXPos(obj)
{
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}
//
function Element_GetYPos(obj)
{
	var curtop = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function ViewSource(objWindow) {
//objWindow.location = "view-source:" + objWindow.location.href 
//window.open("view-source:" + objWindow.location.href );
window.open( '', 'SourceWindow', '' ).document.write( '<textarea cols=80 rows=20>' + objWindow.document.body.parentNode.innerHTML + '</textarea>' )
}

var _flashids = 0;

function SquirtFlash(moviepath, width, height, id, onmouseover, onmouseout, windowobject)
{
	var objectId = "";
	if(windowobject == null)
	{
		var windowobject = window;
	}

	if(id == null || "" == id)
	{
		_flashids ++;
		objectId = "FlashObject_" + _flashids;
	}
	else
	{
		objectId = id;
	}

	if(onmouseover == null) var onmouseover = "";
	if(onmouseout == null) var onmouseout = "";

	windowobject.document.write("<object onmouseout=\"" + onmouseout + "\" onmouseover=\"" + onmouseover + "\" id=\"" + objectId + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"" + width + "\" height=\"" + height + "\"> \n");
	windowobject.document.write("	<param name=\"movie\" value=\"" + moviepath + "\"> \n");
	windowobject.document.write("	<param name=\"quality\" value=\"high\"> \n");
	windowobject.document.write("	<param name=\"wmode\" value=\"transparent\" > \n");
	windowobject.document.write("	<embed wmode=\"transparent\" onmouseout=\"" + onmouseout + "\" onmouseover=\"" + onmouseover + "\" src=\"" + moviepath + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\"></embed> \n");
	windowobject.document.write("</object> \n");
}
function OpinionPoll_ShowFlash(movie, width, height, windowObject)
{
	windowObject.document.write("<" + "html><" + "head><" + "title>Flash video</" + "title><" + "script type=\"text/javascript\" src=\"/common.js\"></" + "script>");
	windowObject.document.write("</" + "head><" + "body style=\"margin:0px;padding:0px;overflow:hidden;background-image:url(" + _sAdminBasePath + "/res/images/processingbar.gif);background-position:center center;background-repeat:no-repeat;\">");
	windowObject.document.write("<" + "script type=\"text/javascript\">SquirtFlash('" + movie + "', " + width + ", " + height + ", 'YouTubeMovie');</" + "script>");
	windowObject.document.write("</" + "body></" + "html>");
}
function OpinionPoll_ShowImage(url, width, height, windowObject)
{
	windowObject.document.write("<" + "html><" + "head><" + "title>Image</" + "title>");
	windowObject.document.write("</" + "head><" + "body style=\"margin:0px;padding:0px;overflow:hidden;\">");
	windowObject.document.write("<" + "img border=\"0\" src=\"" + url + "\">");
	windowObject.document.write("</" + "body></" + "html>");
}
function OpinionPoll_ShowItem(url, width, height, type)
{
	var windowObject = OpenWindow('', width, height, 'PhuseOpinionPollItem', false)
	
	switch(type)
	{
		case "Image":
			OpinionPoll_ShowImage(url, width, height, windowObject);
			break;
		case "YouTube":
		case "Flash":
			OpinionPoll_ShowFlash(url, width, height, windowObject);
		
			break;
	}
}
function SetImage(id, imageFile)
{
	var imgName = _sBasePath + "/res/builtin/" + imageFile;

	var objImage = document.getElementById(id); 
	objImage.src = imgName;

}

function OpenImage(filename, width, height)
{
	var objWindow = OpenWindow(filename, width, height, "ImageWindow");
}

function OpenWindow(url, width, height, name, fullwindow)
{
	var posy = (screen.availHeight / 2) - (height / 2);
	var posx = (screen.availWidth / 2) - (width / 2 ) ;
	var status = "resizable=yes,scrollbars=yes,status=yes";
	
	if(fullwindow)
	{
		status == "";
	}
	return window.open(url, name, "width=" + width + ",height=" + height + "," + status + ",top=" + posy + ",left=" + posx);
}

function SubmitAWeberForm()
{
	var objForm = document.getElementById("AWeberDiv");
	var AWeberForm = document.getElementById("AWeberForm");
	
	//var arrElements = new Array("meta_web_form_id", "meta_split_id", "unit", "meta_adtracking", "meta_message", "meta_required", "meta_forward_vars", "name", "from")
	
	var f = 0;
	
	while(AWeberForm.childNodes.length > 0)
	{
		AWeberForm.removeChild(AWeberForm.childNodes[0]);
	}
	
	recurseNodes(objForm.childNodes, AWeberForm);
	AWeberForm.submit();
}

function recurseNodes(arrNodes, objDest)
{
	var f = 0;
	for(f = 0; f < arrNodes.length; f++)
	{
		var obj = arrNodes[f];
		if((obj.tagName == "INPUT" || obj.tagName == "SELECT") && obj.name != null && obj.name != "submit")
		{
			var newObj = document.createElement("input");
			newObj.setAttribute("type", "hidden");
			
			newObj = objDest.appendChild(newObj);
			
			newObj.id = obj.name;
			newObj.name = obj.name;
			newObj.value = obj.value;
		}
		
		if(arrNodes[f].childNodes.length > 0)
			recurseNodes(arrNodes[f].childNodes, objDest);
		
	}
}

//
// Scroll Handler
//
function _scrollRestore()
{
	try{
		var sScroll = document.getElementById('__scroll').value;

		if(sScroll != "" && sScroll != "0")
		{
			window.scrollTo(0, sScroll);
		}
			
	}
	catch(e){}
}
function _scrollRecorder(e)
{
        var sScroll;

        if (document.documentElement && document.documentElement.scrollTop)
                sScroll = document.documentElement.scrollTop;
        else if (document.body)
                sScroll = document.body.scrollTop;
        else
        {
                sScroll = 0;
        }

        document.getElementById("__scroll").value = sScroll;
}
function _scrollInitiateHandlers()
{
        window.onscroll = _scrollRecorder;
        window.onresize = _scrollRecorder;
        document.body.onscroll = _scrollRecorder;
        _scrollRestore();
}
//
// Search Key up handler
//
function EnterCheck_KeyDownHandler(e, id)
{
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);
	//alert('Character was ' + character);
	if(code == 13){
		__doPostBack(id, '');
		return false;
	}
}


function GetRenderedStyle(oElm, strCssRule)
{
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		try{
			strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
				return p1.toUpperCase();
			});
			strValue = oElm.currentStyle[strCssRule];
		}
		catch(e){
			// Used to prevent an error in IE 5.0
		}
	}
	return strValue;
}
//
// Search
//
var search_oldBackgroundColor= "";
var search_oldBorderStyle= "";
var search_oldBorderColor= "";
var search_oldBorderWidth = "";

var search_flashCount = 0;

function Search_Highlight(control)
{
	var obj = document.getElementById("C" + control);
	if(obj == null)
	{
		control = "Heading_" + control;
		obj = document.getElementById( control );
		
		if(obj == null)
			return;
			
		if(obj.childNodes.length > 0)
			obj = obj.childNodes[0];
			
		search_oldBorderStyle = GetRenderedStyle(obj, "border-style");
		search_oldBorderColor = GetRenderedStyle(obj, "border-color");
		search_oldBorderWidth = GetRenderedStyle(obj, "border-width");
	}
	else
	{
		control = "C" + control;
		search_oldBackgroundColor = GetRenderedStyle(obj, "background-color");
	}
	scrollToElement(obj);
	
	Search_FlashElement(control);
}

function scrollToElement(obj)
{
	// Get the Position of the Element
	var pos = findPos(obj);
	// Just a hardcoded fix, 
        //is written by the COntrol based 
        //on ChildControls
	if (pos[1]>200) pos[1] -= 20;
	
	// Finally --> scroll into Position
	window.scrollTo( pos[0] , pos[1]);
}

function Search_FlashElement(control)
{
	var obj = document.getElementById(control);

	if(control.indexOf("Heading_") > -1)
	{
		if(obj.childNodes.length > 0)
			obj = obj.childNodes[0];
			
		if(obj.style.borderStyle == search_oldBorderStyle 
			&& obj.style.borderColor == search_oldBorderColor
			&& obj.style.borderWidth == search_oldBorderWidth  )
		{
		
			obj.style.borderStyle = "solid";
			obj.style.borderColor = "#cccccc";
			obj.style.borderWidth = "2px"; 
		}
		else
		{

			obj.style.borderStyle = search_oldBorderStyle;
			obj.style.borderColor = search_oldBorderColor;
			obj.style.borderWidth = search_oldBorderWidth; 
			if(search_flashCount > 5)
			{
				return;
			}
		}
	}
	else
	{
		if(obj.style.backgroundColor == search_oldBackgroundColor)
			obj.style.backgroundColor = "#cccccc";
		else
		{
			obj.style.backgroundColor = search_oldBackgroundColor;
			if(search_flashCount > 5)
			{
				return;
			}
		}
	}
	search_flashCount ++;
	
	window.setTimeout("Search_FlashElement('" + control + "');", 500);
}
function ProductChangePreview(contentId, imgPreviewUrl, imgMainUrl, originalWidth, originalHeight)
{
	var objImage = document.getElementById(contentId + "_MainImage");
	var objImageLink = document.getElementById(contentId + "_MainImageLink");
	var objImageViewFullLink = document.getElementById(contentId + "_MainViewImageLink");
	
	if(objImage != null)
	{
		objImage.src = imgPreviewUrl;
	}
	
	if(objImageLink != null)
	{
		objImageLink.href = "javascript:OpenImage('" + imgMainUrl + "'," + originalWidth + "," + originalHeight + ")";
	}
	
	if(objImageViewFullLink != null)
	{
		objImageViewFullLink.href = "javascript:OpenImage('" + imgMainUrl + "'," + originalWidth + "," + originalHeight + ")";
	}
}
    

