// JavaScript Document
	function open_window(link,w,h)
	{
		var win = "width="+w+",height="+h+",'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,screenX=150,screenY=150,top=300,left=300";
		newWin = window.open(link,'newWin',win);
	}

window.addEvent('domready', function(){
	var divs = $$(['docs', 'js', 'html', 'css']);
	divs.each(function(div){
		var link = $(div.id + 'code');
		div.setStyle('display', 'none');
		link.addEvent('click', function(e){
			e = new Event(e);
			divs.each(function(other){
				if (other != div) other.setStyle('display', 'none');
			});
			div.setStyle('display', (div.getStyle('display') == 'block') ? 'none' : 'block');
			e.stop();
		});
	});
});
	window.addEvent('domready', function(){
		var Tips1 = new Tips($$('.Tips1'), {
		
			showDelay: 100,
			hideDelay: 100,
			fixed: true
		});


	}); 

function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		document.getElementById('report_error').innerHTML = 'Status: Cound not create XmlHttpRequest Object.  Consider upgrading your browser.';
	}
}
/* ----------------- ----------------------------------------- */
var addcartReq = getXmlHttpRequestObject();
var product_id;
function AddToCart(pid){
	product_id = pid
	var p_qty = document.getElementById('plist['+pid+']').value;
	if(p_qty == ''){
		p_qty = 1;
	}
	if(p_qty != '') {
		if (addcartReq.readyState == 4 || addcartReq.readyState == 0) {
		url = window.location.href;
		var urlses = "";
		if(url.indexOf("osCsid=") != -1){
			var urlpart = url.split("osCsid=");
			if(urlpart[1] != "undefined" || urlpart[1] != ""){
				urlses = "&osCsid="+urlpart[1]; 
			}else{
				urlses = ""; 
			}
		}
			addcartReq.open("GET", 'add_product.php?pid=' + product_id+ '&p_qty='+p_qty+urlses, true);
			addcartReq.onreadystatechange = handleaddcart;
			addcartReq.send(null);
		}		
	}	
}
function handleaddcart(){
	if(addcartReq.readyState == 4){
		
		if(addcartReq.responseText != ''){
			var  res = addcartReq.responseText
			if(res == '1'){
				/*document.getElementById('report').innerHTML = 'Add products Complete.';*/
				document.getElementById('plist['+product_id+']').value = '';
				window.location.reload();
			}else{
				document.getElementById('report').innerHTML = addcartReq.responseText;
				document.getElementById('plist['+product_id+']').value = '';
			}
			
			return false;
		}
	
		
	}
}
var products_array = new Array();
var products_qty = new Array();
var addmulReq = getXmlHttpRequestObject();
function add_multi_products(){
	var product_qty;
	p_num = document.getElementById('p_num').value;
	if(p_num > 0){
		for(i=1; i<=p_num; i++){
			pid = document.getElementById('product_list['+i+']').value;
			products_array[i] = pid;
			products_qty[pid] = document.getElementById('plist['+pid+']').value;
		}
		send = array_to_get(products_array, products_qty)
		if(send != ''){
			if (addmulReq.readyState == 4 || addmulReq.readyState == 0) {
					url = window.location.href;
					var urlses = "";
					if(url.indexOf("osCsid=") != -1){
						var urlpart = url.split("osCsid=");
						if(urlpart[1] != "undefined" || urlpart[1] != ""){
							urlses = "&osCsid="+urlpart[1]; 
						}else{
							urlses = ""; 
						}
					}
					addmulReq.open("GET", 'add_multi_product.php'+send+urlses, true);
					addmulReq.onreadystatechange = handle_add_multi_product;
					addmulReq.send(null);
			}
		}else{
			document.getElementById('report').innerHTML = 'Please enter products qty';
		}
	}
	return false;
}
function handle_add_multi_product(){
	if(addmulReq.readyState == 4){
	
	var res_multi = addmulReq.responseText;
			if(res_multi == '1'){
				/*document.getElementById('report').innerHTML = 'Add products Complete.';*/
				window.location.reload();
			}else{
				document.getElementById('report').innerHTML = addmulReq.responseText;
			}
			return false;
	}	
}
function array_to_get(theindex, theArray){
	output = '';
	index = 0;
	for(i=1;i<theindex.length;i++){
		if(theArray[theindex[i]] != '' && theArray[theindex[i]] != '0'){
			index++;
			if(index == 1){
				glue = '?';
			}else{
				glue = '&';
			}
			output += glue+'product['+theindex[i]+']='+theArray[theindex[i]];
		}
	}
	return output;
}
function rowOverEffect(object) {
  if (object.className == 'productListing-data') object.className = 'productListing-data-over';
}

function rowOutEffect(object) {
  if (object.className == 'productListing-data-over') object.className = 'productListing-data';
}
