function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
	var queryString = url.replace(/^[^\?]+\??/,'');
	var w = ((m = queryString.match(/width=(\d+)/)) ? ((m[1]*1) + 30) : 800);
	var h = ((m = queryString.match(/height=(\d+)/)) ? ((m[1]*1) + 40) : 600);
	if(queryString.match(/height=max/)) { h = screen.height-60; }
	if(url.match(/\.jpg$/)) {
		var win = window.open('about:blank', '_blank', 'height=10px,width=10px,resizable,scrollbars');
		setTimeout(function() {
			// alert(url);
			var img = new Image();
			img.onload = function() {
				win.location = url;
				win.resizeTo(img.width,img.height);
				win.focus();
			};
			img.src = url;
		}, 1);
	} else {
		url += (url.match(/\?/) ? '&' : '?') + 'layout=popup';
		NewWindow(url, '_blank', w, h);
	}
}
function NewWindow(mypage, myname, w, h, scroll) {
	if(myname=='studio' && w==580) w=740;
	if (h>(screen.height-60)) { h = screen.height-60; }
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2-60;
	if (wint<0) { wint = 0; }
	var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',resizable,'+((scroll == 'no') ? '' : 'scrollbars');
	var win;
	if(myname=='opener' && window.opener){
		win = window.opener;
	}else{
		if(myname=='opener'){ myname='_blank'; }
		win = window.open('about:blank', myname, winprops);
		try{
			win.document.open();
			win.document.writeln("\n<html><head><style>body { color: gray; } div#rotate { position:absolute; top:0px; left:0px;} div#rotate span { position:absolute; } h1 { text-align:center; position:relative; top:0; left:0; font-family:Times;}</style>\n<scr"+"ipt>//<!--\nvar c = 0;\nfunction rotate() {\nvar t = document.getElementById('rotate').getElementsByTagName('span');\nfor(var i=0; i < t.length; i++) {\nif ((i % 4) == c) {\nt[i].style.visibility = 'visible';\n} else {\nt[i].style.visibility = 'hidden';\n}\n}\nc = (c + 1) % 4;\nsetTimeout('rotate()', 300);\n}\nfunction draw() {\nvar t = document.getElementById('rotate');\nvar a = Math.PI / 24;\nvar r = 50;\nvar s = '';\nvar w = (document.body.clientWidth / 2);\nvar h = (document.body.clientHeight / 2);\nfor(i=0;i<=48;i++) {\nvar b = document.createElement('span');\nb.style.top = Math.round(Math.sin(i * a) * r) + h;\nb.style.left = Math.round(Math.cos(i * a) * r) + w;\nb.innerHTML = '&middot;';\nt.appendChild(b);\n}\nt = document.getElementsByTagName('h1');\nt[0].style.top = ((document.body.clientHeight / 2) - (2 * r));\n}\n//-->\n</scr"+"ipt>\n</head>\n<body>\n<h1>Loading ....</h1>\n<div id='rotate'>\n</div>\n</body>\n</html>\n");
			win.document.close();
			win.draw();
			win.rotate();
		}catch(e){}
	}
	if (mypage != '' && mypage != 'about:blank') win.location = mypage;
	win.focus();
}

if(typeof(setLoading)!='function') {
	function setLoading(a) {
		var div = $('div#middle div#middle1');
		var height = div.height();
		if(height<400) height=400;
		var rw = $('div#middle div#rotateWindow');
		if(!rw[0]) {
			$('div#middle').append('<div id="rotateWindow" class="rw1" style="text-align:center;width:'+div.width()+'px;height:'+height+'px;"><div style="padding-top:40px;font-size:30px; color:#2c9264;">Loading<br><img src="/images/loadingAnimation.gif" width="160" height="20" border="0" alt="...." style="margin:1em 0;" /></div>');
			rw = $('div#middle div#rotateWindow');
		} else {
			rw.css({ width: div.width(), height: height });
		}
		if(a && a.tagName && a.tagName=='A') {
			var txt = $(a).text();
			if(!txt || txt=='') { var img = $(a).find('img'); if(img) txt = img.attr('alt'); }
			if(txt && txt!='') $('div#middle div#rotateWindow div:first').html('Loading "'+txt+'"');
		}
		document.getElementById('middle').className = 'showrw';
	}

	function hideLoading() {
		$('div#middle').removeClass('showrw').removeClass('showrw2');
		$('div#middle div#rotateWindow').hide();
	}
}

function onChangeCatSel1(sel) {
	if(sel.selectedIndex>0) {
		$('#cat_sel_2').html('<option>Select Sub-Category ....</option>' + $(sel).find('option:selected').attr('rel'));
	}
}
function onChangeCatSel2(sel) {
	if(sel.selectedIndex>0){
		var table = sel.getAttribute('rel'); if(!table || table=='') table='product';
		var id=sel.options[sel.selectedIndex].value;
		var txt=$('#cat_sel_1 option:selected').text()+' -- '+$(sel).find(':selected').text();
		$('#category_list').append('<div>'+txt+'<input type="hidden" name="'+table+'[all_category_id][]" value="'+id+'" /> <a href="#" onclick="$(this).parents(\'div:first\').remove(); return false;">Remove</a></div>');
		sel.selectedIndex=0;
		$('#cat_sel_1')[0].selectedIndex=0;
		$(sel).html('<option>Select Sub-Category ....</option>');
	}
}
function addStarSelect(txt, id) {
	if(txt && id) {
		// alert(id + ' : ' + txt);
		$('#star_list').append('<div>'+txt+'<input type="hidden" name="product[all_star_id][]" value="'+id+'" /> <a href="#" onclick="this.parentNode.parentNode.removeChild(this.parentNode); return false;">Remove</a></div>');

		var addStarInp = $('#new_star_name');
		addStarInp.lastSelected = '';
		addStarInp.val("");
	}
}
function addStarFormatItem(row) {
	return row[1];
}

