var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (!document.getElementById) {
	if (document.all)
		document.getElementById = function() {
			if(typeof document.all[arguments[0]]!="undefined")
				return document.all[arguments[0]]
			else
				return null
		} // end function
	else if (document.layers)
		document.getElementById = function() {
			if (typeof document[arguments[0]]!="undefined")
				return document[arguments[0]]
			else
				return null
			} // end function
} // end if

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
} // end function

function rcnmap(page) {	
	w = 444;
	h = screen.height-110;
	if (h > 565) h = 565; 
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - 115 - h) / 2;
	
	rcnmap=window.open(page, "rcnmap", "width="+w+",height="+h+",top="+wint+",left="+winl+',status=no,scrollbars=yes,resize=yes,menubar=no');
	rcnmap.focus();
	return false;
} // end function editComment

function viewSpotlight(page) {
	w = 680;
	h = screen.height-110;
	if (h > 600) h = 600; 
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - 115 - h) / 2;
	
	rcnspotlight=window.open(page, "rcnspotlight", "width="+w+",height="+h+",top="+wint+",left="+winl+',status=no,scrollbars=yes,resize=yes,menubar=no');
	rcnspotlight.focus();
	return false;
} // end function editComment

function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

function login (page) {
	var w = 360;
	var h = 300;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	login_win=window.open(page, "login_win", "toolbar=no,width="+w+",height="+h+",top="+wint+",left="+winl+",status=no, scrollbars=yes,resize=yes,menubar=no");
	login_win.focus();
	return false;
} // end function login

function windowunload() {
	
} // end if


function editPSpic(page,type) {
	w = 500;
	h = screen.height-110;
	if (h > 700) h = 700; 
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - 115 - h) / 2;
	pswin = window.open(page, "ps_win"+type, "toolbar=no,width="+w+",height="+h+",top="+wint+",left="+winl+",status=no,scrollbars=yes,resizable=yes,menubar=no,dependent=yes");
	pswin.focus();
} // end function

function showPSForm () {
	if(xmlHttp.readyState==4) {
        $('prodBasket').update(xmlHttp.responseText);
    }
}

/* ------------------------------------------------------------------------
	Pretty Comments
	
	Developped By: Stephane Caron (http://www.no-margin-for-errors.com)
	Inspired By: The facebook textarea :)
	Version: 1.1
	
	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top, w00t
------------------------------------------------------------------------- */
var prettyComments = {
	version : '1.1',
	options : {
		'animate' : true,
		'animationSpeed' : 'normal', /* fast/slow/normal */
		'alreadyAnimed' : false,
		'padding' : 30,
		'init' : true /* DONT CHANGE */
	},
	init : function(which){
		// IE doubles the padding value 
		if($.browser.msie && parseFloat($.browser.version) < 7) this.options['padding'] = this.options['padding']/2;
		
		prettyComments.theTextarea = $('#' + which);
		
		// Create the div in which the content will be copied
		$('body').append('<div id="hidden_'+ this.theTextarea.attr('id') +'"></div>');
		
		prettyComments.theHiddenDiv = $('#hidden_' + this.theTextarea.attr('id'));
		
		// Now set the hiden div dimensions the same as the textarea (min-height is set differently in IE/Firefox, YAY for shitty browsers);
		this.theHiddenDiv.css({
			'display' : 'none',
			'width' : this.theTextarea.width() + 'px',
			'font-family' : this.theTextarea.css('font-family'),
			'font-size' : this.theTextarea.css('font-size'),
			'line-height' : this.theTextarea.css('line-height')
		});
		
		this.theTextarea.css({'overflow':'hidden','display':'inline'});

		if($.browser.msie && parseFloat($.browser.version) < 7){
			this.theHiddenDiv.css('height',this.theTextarea.height() + 'px');
		}else{
			this.theHiddenDiv.css('min-height',this.theTextarea.height() + 'px');
		};
		
		this.options['initialHeight'] = this.theTextarea.height();
		
		this.theTextarea.bind('keyup',function(){
			prettyComments.copyContent();
		});
		
		// On the init, make sure the textarea has the right dimensions
		this.copyContent();
	},
	copyContent : function(){
		// Convert the line feeds into BRs
		theValue = "";
		theValue += this.theTextarea.attr('value');
		theValue = theValue.replace(new RegExp( "\\n", "g" ),'<br />');
		
		this.theHiddenDiv.html(theValue);
		
		if(this.theHiddenDiv.height() > this.theTextarea.height() - this.options['padding']){
			this.expand();
		}else if(this.theHiddenDiv.height() < this.theTextarea.height() - this.options['padding']){
			this.shrink();
		};
	},
	expand : function(){			
		if(this.options['animate'] && !this.options['alreadyAnimed'] && !this.options['init']){
			this.options['alreadyAnimed'] = true;
			this.theTextarea.animate({'height':this.theHiddenDiv.height() + this.options['padding']},this.options['animationSpeed'],function(){
				prettyComments.options['alreadyAnimed'] = false;
			});
		}else if(!this.options['animate'] && !this.options['alreadyAnimed'] && !this.options['init']){
			this.theTextarea.height(this.theHiddenDiv.height() + this.options['padding']);
		}else if(this.options['init']){
			this.theTextarea.height(this.theHiddenDiv.height());
			this.options['init'] = false;
		};
	},
	shrink : function(){
		this.options['alreadyAnimed'] = true;
		this.theTextarea.animate({'height':this.theHiddenDiv.height() + this.options['padding']},this.options['animationSpeed'],function(){
			prettyComments.options['alreadyAnimed'] = false;
		});
	}
};