
var end_opacity = 50; //end opacity, 25 = 25%, 50 = 50%, 100 = 100%, etc.
var increase_opacity_by = 10; //how much to increase by each time the timeout ends
var timeout = 100; //timeout in miliseconds, 0 = instant fade-out

var winbackground = document.getElementById('thewindowbackground');
var cur_opacity = 0;

var timer = null;




var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d, wd, ht) {
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
		}
	else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
		}
	else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
		}
	if(document.all) {
		cX += rX; 
		cY += rY;
		}
	d.style.left = wd + "px";
	d.style.top = ht + "px";
}

function HideContent(d) {
	
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
	document.getElementById('thewindowbackground').style.display = 'none';
	//window.loation = 'index.php';
}

function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd, 195, 75);
	if(dd.style.display == "none") { dd.style.display = "block"; }
	else { dd.style.display = "none"; }
}



function increase_opacity() {
	cur_opacity += increase_opacity_by;

	winbackground.style.opacity = cur_opacity / 100;
	winbackground.style.filter = "alpha(opacity=" + cur_opacity + ")";
	
	if(cur_opacity < end_opacity) {
		timer = setTimeout("increase_opacity()",timeout);
	}
	else {
		wincontent.style.display = 'block';
	}
}

function ShowContent(d,val,pos) {
		/*if(timeout > 0) {
		cur_opacity = 0;
	
		winbackground.style.opacity = cur_opacity / 100;
		winbackground.style.filter = "alpha(opacity=" + cur_opacity + ")";
		timer = setTimeout("increase_opacity()",timeout);
		document.getElementById('thewindowbackground').style.display = 'block';
		}
		else {
			winbackground.style.opacity = end_opacity / 100;
			winbackground.style.filter = "alpha(opacity=" + end_opacity + ")";
		} */
	document.getElementById('thewindowbackground').style.display = 'block';
	var f=document.getElementById('f1');
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd, 195, 75);
	
	dd.style.display = "block";
	f.src="show_details.php?item_id=" + val + '&p_position=' + pos;
	//alert("sad");
	//window.close();
	//window.location = "show_details.php?id=" + val;
	//top.parent.basefrm.location.href('index.php');
	// window.open("show_details.php?id=" + val,"windowName",  "width=200,height=200,scrollbars=no"); 
}
//-->


      /*function monitorClick(e){
        alert(e)
		var evt = (e)?e:event;
       
        var theElem = (evt.srcElement)?evt.srcElement:evt.target;

        while(theElem!=null){
          if(theElem.id == "details" || theElem.id == "clickclick" && document.getElementById('details').style.display == 'none') {
          document.getElementById('details').style.display = 'block';
          return true;
          }
	 
          theElem = theElem.offsetParent;         
        }
        document.getElementById('details').style.display = 'none';
        return true;
      }

      document.onclick = monitorClick; */
 
function hide_content(page) {
	//alert('df');
	parent.document.getElementById('details').style.display = 'none';
	parent.document.getElementById('thewindowbackground').style.display = 'none';
	//parent.window.location = page + ".php";
	//window.location = 'index.php';
	
}

function login_form(d,page,item_id,total) {

	if(page=='add_to_cart') {
		var used_code="";
		var i=0;
		for(var i=0;i<total;i++) {
			var chk = document.getElementById('chk_used' + i).checked;
			
			if(chk==true) {
				if(used_code=="")
					used_code = document.getElementById('chk_used' + i).value;
				else
					used_code += ',' + document.getElementById('chk_used' + i).value;
			
			}
		}
		//alert(used_code);
		if(used_code=="") {
			alert("Please choose atleast one checkbox.");
			return false;
		}
	}

	
	var dd = document.getElementById(d);
	AssignPosition(dd, 0, 85);
	
	dd.style.display = "block";
	//document.getElementById('login').action = page + '.php';
	
	var f=document.getElementById('f2');
	f.src="login.php?page=" + page + "&item_id=" + item_id + '&u_code=' + used_code;
}

function hide_login() {

	parent.document.getElementById('login_form').style.display = 'none';
}
function hide_content1(page) {
	
	parent.parent.document.getElementById('details').style.display = 'none';
	parent.parent.document.getElementById('thewindowbackground').style.display = 'none';
	//parent.window.location = "index.php";
	parent.parent.window.location = page + '.php';
	
}

function product_price(d, item_id) {

	var dd = document.getElementById(d);
	AssignPosition(dd, 0, 85);
	
	dd.style.display = "block";
	//document.getElementById('login').action = page + '.php';
	
	var f=document.getElementById('f3');
	f.src="product_price.php?item_id=" + item_id;
}

function hide_price() {
	parent.location.reload();
	parent.document.getElementById('product_price').style.display = 'none';
	parent.document.getElementById('login_form').style.display = 'none';
	
}

function add_cart(d, item_id, total) {
	var used_code="";
	var i=0;
	for(var i=0;i<total;i++) {
		var chk = document.getElementById('chk_used' + i).checked;
		
		if(chk==true) {
			if(used_code=="")
				used_code = document.getElementById('chk_used' + i).value;
			else
				used_code += ',' + document.getElementById('chk_used' + i).value;
		
		}
	}
	//alert(used_code);
	if(used_code=="") {
		alert("Please choose one checkbox.");
		return false;
	}
	var dd = document.getElementById(d);
	AssignPosition(dd, 0, 85);
	
	dd.style.display = "block";
	//document.getElementById('login').action = page + '.php';
	
	var f=document.getElementById('f4');
	f.src="add_to_cart.php?item_id=" + item_id + '&u_code=' + used_code;
}

function hide_add_cart() {
	parent.location.reload();
	parent.document.getElementById('add_cart').style.display = 'none';
	parent.document.getElementById('login_form').style.display = 'none';
	
}

function go_view_cart(page,cat_id) {
	parent.document.getElementById('details').style.display = 'none';
	parent.document.getElementById('thewindowbackground').style.display = 'none';
	parent.window.location = page + ".php?cat_id=" + cat_id;
	//window.location = 'index.php';
	
}

function new_window(win_url,win_name,win_width,win_height){
	
	 //window.open(win_url,win_name,'width=' + win_width + ',height=' + win_height + ',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');	
	 window.open(win_url,win_name,'');	
	
}

