	/*
	 *	Captionier popup
	 */
	function ce( t ) { return document.createElement( t ); }
	function ge( t ) { return document.getElementById( t ); }
	function insertAfter(node, referenceNode) {
	  referenceNode.parentNode.insertBefore(node, referenceNode.nextSibling);
	}
	function isdefined( variable) {
		return (typeof(variable) == "undefined")?  false: true;
	}
	function isnumber( variable) {
		return (typeof(variable) == "number")?  false: true;
	}
	
	function detect() {
		var agent 	= navigator.userAgent.toLowerCase();
		// detect platform
		this.isMac		= (agent.indexOf('mac') != -1);
		this.isWin		= (agent.indexOf('win') != -1);
		this.isWin2k	= (this.isWin && (
				agent.indexOf('nt 5') != -1));
		this.isWinSP2	= (this.isWin && (
				agent.indexOf('xp') != -1 || 
				agent.indexOf('sv1') != -1));
		this.isOther	= (
				agent.indexOf('unix') != -1 || 
				agent.indexOf('sunos') != -1 || 
				agent.indexOf('bsd') != -1 ||
				agent.indexOf('x11') != -1 || 
				agent.indexOf('linux') != -1);
		
		// detect browser
		this.isSafari	= (agent.indexOf('safari') != -1);
		this.isSafari2 = (this.isSafari && (parseFloat(agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).substring(0,agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).indexOf(' '))) >=  300));
		this.isOpera	= (agent.indexOf('opera') != -1);
		this.isNN		= (agent.indexOf('netscape') != -1);
		this.isIE		= (agent.indexOf('msie') != -1);
		this.isFirefox	= (agent.indexOf('firefox') != -1);
		
		// itunes compabibility
		this.isiTunesOK	= this.isMac || this.isWin2k;
		
		this.getClientWidth = function() {
			return(window.innerWidth||
				  (document.documentElement && document.documentElement.clientWidth)||
				  (document.body && document.body.clientWidth)||
				  0);
		}
	}
	browser = new detect();	
	browser.getClientHeight = function() {
		return(window.innerHeight||
			  (document.documentElement && document.documentElement.clientHeight)||
			  (document.body && document.body.clientHeight)||
			  0);
	}
	browser.getPageScrollTop = function() {
		return(document.documentElement && document.documentElement.scrollTop)||
			  (document.body && document.body.scrollTop)||
			  0;
	}
	browser.getPageScrollLeft = function() {
		return(document.documentElement && document.documentElement.scrollLeft)||
			  (document.body && document.body.scrollLeft)||
			  0;
	}
	browser.getPageSize = function() {
		var xScroll,yScroll;
		if(window.innerHeight && window.scrollMaxY)	{
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		}	else if(document.body.scrollHeight > document.body.offsetHeight)	{
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}	else	{
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth,windowHeight;
		if(self.innerHeight)	{
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if(document.documentElement && document.documentElement.clientHeight) {
			windowWidth  = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if(document.body) {
			windowWidth  = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		var pageHeight,pageWidth;
		
		if(yScroll < windowHeight) pageHeight = windowHeight;
		else pageHeight = yScroll;
		
		if(xScroll < windowWidth) pageWidth = windowWidth;
		else pageWidth = xScroll;
		
		scrollleft = browser.getPageScrollLeft();
		scrolltop = browser.getPageScrollTop();
		return { pageWidth:pageWidth, pageHeight:pageHeight, 
				 windowWidth:windowWidth, windowHeight:windowHeight, 
				 scrollLeft:scrollleft, scrollTop:scrolltop};
	}
	browser.getPosition = function( element ) 	{
		var l = t = 0;		
		while( element != null ) {
			l += element.offsetLeft;
			t += element.offsetTop;			
			//Added by Velmurugan On 11th June for Fixing the Bug of Arrow position misplaced when scrolled div						
			if ( element.nodeName != 'BODY' ){ 				
				l -= element.scrollLeft;
				t -= element.scrollTop;
			}//end
			element = element.offsetParent;
		}
		return {left:l, top:t};
	};

function hideShowCovered (el) 
{
	var tags = new Array("applet", "iframe", "select");
	var p = getAbsolutePos(el);
	var EX1 = p.x;
	var EX2 = el.offsetWidth + EX1;
	var EY1 = p.y;
	var EY2 = el.offsetHeight + EY1;

	for (var k = tags.length; k > 0; ) {
		var ar = document.getElementsByTagName(tags[--k]);
		var cc = null;

		for (var i = ar.length; i > 0;) {
			cc = ar[--i];

			p = getAbsolutePos(cc);
			var CX1 = p.x;
			var CX2 = cc.offsetWidth + CX1;
			var CY1 = p.y;
			var CY2 = cc.offsetHeight + CY1;
			if ((CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
					cc.style.visibility = "visible";
			} else {
					cc.style.visibility = "hidden";
			}
		}
	}
}
function showalltag()
{
	var tags = new Array("applet", "iframe", "select");
	for (var k = tags.length; k > 0; ) {
		var ar = document.getElementsByTagName(tags[--k]);
		var cc = null;

		for (var i = ar.length; i > 0;) {
			cc = ar[--i];
			if(cc.style.visibility = "hidden")
				cc.style.visibility = "visible";
		}
	}
}
function getAbsolutePos(el) {
	var SL = 0, ST = 0;
	if (el.scrollLeft)
		SL = el.scrollLeft;
	if (el.scrollTop)
		ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

	var popupwin = null;
	var s = d = t = 0;
	var target,evt_type, callback;
	var agent 	= navigator.userAgent.toLowerCase();
	var	isIE		= (agent.indexOf('msie') != -1);
	function captionierpopup( o ) {
		o = o || {};	
		if ( o.event == null )  var e = window.event; else var e = o.event;
		//var target = e.target != null ? e.target : e.srcElement; //Commented by Velmurugan on 4th June Eliminate JS Error in IE Member Not Found
		if ( o.sleep != true || !isdefined(o.sleep) ){
			target   = e.target != null ? e.target : e.srcElement;
			evt_type = e.type;
			
		}
		if( evt_type != "click" && (!isdefined( o.shownow ) || o.shownow == false) ) {
			if ( !s )	s = new Date();				
			var n  = new Date();
			d = n.getTime() - s.getTime();			
			if ( d <= 1000 ){				
				if( o.sleep != true || !isdefined(o.sleep) ) 
					if(browser.isIE) target.attachEvent("onmouseout", function() { if( t ) clearTimeout( t ); s = d = t = 0; } );
					else target.addEventListener("mouseout", function() { if( t ) clearTimeout( t ); s = d = t = 0; }, false);
					//$(target).bind('mouseout',function() { if( t ) clearTimeout( t ); s = d = t = 0; } );
				o.sleep = true;
				t = setTimeout( function(){ captionierpopup(o) }, 1 );
			}
			else {
				o.shownow = true;
				captionierpopup( o );
				s = d = t = 0;
			}
		}else{
			var pos = browser.getPosition( target );	
			var left = pos.left;
			var top = pos.top;
			var width = o.width || 400;
			var url = o.url || '';
			var data = o.data || '';
			var content = o.content || '<span class="loading" style="height:150px;">Loading...</span>';
			callback = o.callback; 
			if( target.offsetWidth ) left += Math.floor(target.offsetWidth);
			if( target.offsetHeight ) top += Math.floor(target.offsetHeight / 2);
			if( isdefined( o.offsettop ) != undefined && parseInt( o.offsettop ) > 0 ) top += o.offsettop;
			//if( isdefined( o.offsetleft ) != undefined && parseInt( o.offsetleft ) > 0 ) left += o.offsetleft;
			
			var pop = ce('div');
			pop.forcedisplay = false;
			nopopup();
			//pop.onresize = function() { popupresize() };
			pop.className = 'popup';
			pop.style.position="absolute";
			pop.style.width = width;
			pop.postop = top;
			pop.posofftop = 25;
			pop.posoffleft = 43;
			pop.posleft = left;
			pop.style.width = width+"px";
			pop.style.top = (top+7)+"px";
			pop.style.left = ((left-width))+"px";
			pop.poshoriz = top - document.body.scrollTop > document.body.scrollTop + document.body.clientHeight - top ? 'd' : 'u';
			pop.posvert = left > width+50 ? 'r' : 'l';
			pop.innerHTML = '<div id="mian" style="width:'+width+'px; top:'+pop.postop+'px; left:'+pop.posleft+'px; border-spacing:3" align="center"><div id=popupcanvas class="popuppanelbg">'+content+'</div></div>';
			popupwin = pop;
			document.body.appendChild( pop );
			//ge('popupcanvas').onchange = function() { popupresize(); }
			if( url ) {
				//ajaxrequest(url+'?'+data, "setpopup", ge("popupcanvas"), 0 );
				
				$.ajax( {type : "POST",
					   url : url, 
					   data : data, 
					   success: function( html ){
								$('#popupcanvas').html( html ); 
								//popupresize();
								if( isdefined( o.autoclose ) && o.autoclose == true ) {
									var dely = ( isdefined( o.closedelay ) ) ? o.closedelay : 2000;
									setTimeout('nopopup()', dely);
								}
							}
						});
			}
			//popupresize();
			if(isIE)
				hideShowCovered (pop)
			return pop;
		}
	}
	function setpopup( html, ele ) {				
		if ( ele.element ){
			if( ele.element ) ele.element.innerHTML = html;
		}else{
			if( ele ) ele.innerHTML = html;
		}
		
		if(callback) eval(callback);
		//popupresize();
		//setTimeout('popupresize()',1000);
		
		if ( ele.popupobj ){
			if( isdefined( ele.popupobj.autoclose ) && ele.popupobj.autoclose == true ) {
				var dely = ( isdefined( ele.popupobj.closedelay ) ) ? ele.popupobj.closedelay : 2000;
				setTimeout('nopopup()', dely);
			}
		}
		return;
	}
	function popupresize() {
		var pop = popupwin;
		var vtop;
		if( pop == null ) return;
		if(ge('mian')) {			
			ge('mian').style.height = ge('popupbackground').style.height = pop.clientHeight + 'px'; 
			ge('mian').style.width = ge('popupbackground').style.width = pop.clientWidth + 'px';
			if( browser.isIE )	{
				//ge('mian').style.top = ge('popupshadow').style.left = '3px';
			}
			if( pop.poshoriz == 'd' )	{
				pop.style.top = vtop = pop.postop - (pop.clientHeight + pop.posofftop) + 'px';
				//ge('mian').style.top = browser.isIE ? pop.clientHeight -1 + 'px': pop.clientHeight + 1 + 'px';
			}
			else if( pop.poshoriz == 'u' ) {
				pop.style.top = vtop = pop.postop + (pop.posofftop) + 'px';
				//ge('mian').style.top = browser.isIE ? -pop.posofftop + 1 + 'px' : -pop.posofftop + 1 + 'px';
	
			}
			if( vtop < 0 && !pop.forcedisplay )	{
				pop.forcedisplay = true;
				pop.poshoriz = 'u';
				//popupresize();
				//ge('mian').innerHTML = png( g_template_img + 'c_arrow_' + pop.poshoriz + pop.posvert + '.png', 43, 25 );
				return;
			}
			pop.style.left = pop.posvert == 'l' ? pop.posleft + 'px' : pop.posleft - pop.clientWidth + 'px';
			//ge('mian').style.left = pop.posvert == 'l' ? 0 + 'px' : pop.clientWidth - pop.posoffleft + 'px';
			//ge('popupclose').style.left = pop.clientWidth - 28 + 'px';
		}
		// scroll window to fit popup
		if( vtop < document.body.scrollTop )	{
			window.scrollBy( 0, vtop-(document.body.scrollTop+4) );
		}
		if( (vtop + pop.clientHeight) > (document.body.scrollTop + document.body.clientHeight) )	{
			window.scrollBy( 0, (vtop + pop.clientHeight)-(document.body.scrollTop + document.body.clientHeight - 4) );
		}
	}
	function reloadpopup(o){
		var url = o.url || '';
		var data = o.data || '';
		var content = o.content || '<span class="loading" >Loading...</span>';
		callback = o.callback; 
		ge('popupcanvas').innerHTML = content;//popupresize();
		if( url ) {		
			//ajaxrequest(url+'?'+data, "setpopup", {element:ge("popupcanvas"),popupobj:o}, 0 );
			
			$.ajax( {type : "POST",
				   url : url, 
				   data : data, 
				   success: function( html ){
							$('#popupcanvas').html( html ); //popupresize();
							if( isdefined( o.autoclose ) && o.autoclose == true ) {
								var dely = ( isdefined( o.closedelay ) ) ? o.closedelay : 2000;
								setTimeout('nopopup()', dely);
							}
						}
					});	
		}
	}
	function nopopup() {
		if( popupwin != null ){ 
			showalltag();
			document.body.removeChild( popupwin );
		}
		popupwin = null;
	}
	function png( src, w, h, s ) {
		//if( browser.isNN )
			return '<img src="' + src + '" width=' + w + ' height=' + h + ' border=0 alt="" style="' + s + '">';
		//else
			return '<div style="' + s + ';width:' + w + ';height:' + h + ";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')" + '"></div>';
	}
	var vType=0;
	function showPopup( e,vWidth,vUrl,pmData) {
	//alert('action=getUserProfile&userid='+option.userid+'&type='+option.type+'&lid='+option.lid+'&'+Math.random())
		if(vType == 0)
		{
			captionierpopup( {event:e, width:vWidth, url:vUrl, data:pmData } );
			vType=1;
		}
		else
		{
			nopopup();
			vType=0;
		}
	}
function deleteCartPopup(pmProdId,pmPath,e)
{
	$.ajax({
			type : "POST",
			url	 : pmPath+'/cart/delete',
			data : "prodid="+pmProdId,
			dataType: "html",
			success: function(html){
				if(html ==1)
				{
					reloadCartPopup(pmPath)
				}
			}
		});
}
function reloadCartPopup(pmPath)
{
	$.ajax( {	
		   	type : "POST",
			url : pmPath+'/cartlisting', 
			data : '', 
			success: function( html ){
				$('#popupcanvas').html( html ); 
			}
		});
}