var dragImgId = "";
var dragImageId = "";
var mousePosition = "";
var mouseStatus ="";
var dragStatus = "drop";
var imgOut="";
var detOut="";
var popOpen = 'closed';
var k=0;
var imgItemId="";
var popPopWidth = '400px';
var popImgWidth = '';
var loading='';
var latestPop = '';
var basket_images = new Array();
var navigateBrowser = navigator.appName;
var myLoc = document.location.pathname;
var clicked = '0';
var dragging = '';
var ghosting_var = '';
var dragImageParent = '';
var basket_count = '';

var Ele = {
	changeClass: function(id, name) {
		if($(id))
			$(id).className = name;
	},
	remove: function(parent, id) {
		if($(id) && $(parent))
			$(parent).removeChild($(id));
	},
	append: function(parent, id) {
		if($(id) && $(parent))
			$(parent).appendChild($(id));
	},
	insert: function(parent, id, obj) {
		if($(id) && $(parent) && obj)
			$(parent).insertBefore(obj, $(id));
	},
	copy: function(id) {
		if($(id))	
			return $(id).cloneNode(true);
		else
			return null;
	},
	parent: function(id) {
		if($(id))
			return $(id).parentNode.id;
	},
	ajax: function(url, method, async)
	{
		new Ajax.Request(url, {
			method: method,
			asynchronous: async
		});
	}
};


function basket_lists() {
	for (b = 0; b < basket_images.length; b++) {
			//alert(basket_images[b]);
			var moveTo = document.getElementById(basket_images[b] + '_filter');
			var moveFrom = document.getElementById(basket_images[b] + '_select');
			moveFrom.name = basket_images[b] + "_org";
			var priceSelect = document.createElement("select");
			priceSelect.name = "format[" + basket_images[b] + "]";
			priceSelect.id = "format[" + basket_images[b] + "]";
			priceSelect.className = "wide";
			var deliverOptions = moveFrom.innerHTML + "";
			if (navigateBrowser == "Microsoft Internet Explorer") {
				for (c = 1; c < moveFrom.childNodes.length; c++) {
					var priceOption = document.createElement("option");
					priceOption.value = moveFrom.childNodes[c].value;
					priceOption.label = moveFrom.childNodes[c].label;
					priceOption.innerText = moveFrom.childNodes[c].innerText;
					priceSelect.appendChild(priceOption);
					c++;
				}
			}
			else {
				BetterInnerHTML(priceSelect, moveFrom.innerHTML);
			}
			//alert(deliverOptions);
			priceSelect.style.width = "150px";
			priceSelect.style.marginLeft = "0px";
			var img_id = basket_images[b];
			priceSelect.onchange = function(){
				get_extras(img_id, document.reg);
				update_prices(document.reg)
			};
			moveTo.appendChild(priceSelect);
			moveFrom.parentNode.removeChild(moveFrom);
		}
}

function order_details(btnId) {
	Effect.BlindUp('search-results');
	
	BetterInnerHTML(document.getElementById('orderActions'),"<a href='/basket/list.me'>Modify basket</a>");
	BetterInnerHTML(document.getElementById('submit_actions'),"<input type='submit' name='submit' id='submit_button' value='Submit order' style='float: right;'></input>");
	document.getElementById('submit_actions').style.textAlign = "right";
	document.getElementById('submit_button').style.marginTop = "-5px";
	BetterInnerHTML(document.getElementById('submit_actions_bottom'),"<input type='submit' name='submit' id='submit_button' value='Submit order' style='float: right;'></input>");
	setTimeout(function(){
		Effect.BlindDown("order_images");
	},700);
}

function chk_form(form_to_chk){
	prj_form = document.getElementById(form_to_chk);
	if (prj_form.action.indexOf('order/enter_details.me') > -1) {
		if (document.getElementById('project_details[65]').value == '') {
			alert("Please enter the project name");
			/*animatedcollapse.show('order_slide');
			document.getElementById('order_hideActions').style.display = 'block';
			document.getElementById('order_showActions').style.display = 'none';
			*/
			return false;
		}
		if (document.getElementsByName('project_details[64]')[0].selectedIndex == 0) {
			alert("Please select the client type");
			return false;
		}
		if (document.getElementsByName('project_details[70]')[0].selectedIndex == 0) {
			alert("Please select the purpose of the project");
			return false;
		}
		if (document.getElementById('project_details[72]').value == '') {
			alert("Please enter the publication name");
			return false;
		}
		
		return true;
	}

}

var imageDrag = null;
var hasDragged = false;
var dragImageParent = '';
var timeout = null;

function wedge(event)
{
	Event.stop(event);
	return false;
}

function makeImageDraggable(oid, pid)
{
	new Draggable(oid, {
		revert: false,
		onStart: function(){
			dragImageId = oid;
			hasDragged = false;
			imageDrag = oid;
			
			if(Prototype.Browser.WebKit || Prototype.Browser.IE){
				$(oid).style.top='-1000px';
				$(oid).style.bottom='200px';
				$(oid).style.zIndex = '100';
			}
			timeout = setTimeout(function(){imageDrag = oid;hasDragged = true},250);
			if (document.all && Prototype.Browser.IE){ 
				Event.observe(document.body, "drag", wedge, false); 
				Event.observe(document.body, "selectstart", wedge, false);
			}
		},
		onEnd: function(){
			clearTimeout(timeout);
			Effect.Fade(oid,{ duration:1.0});
			setTimeout(function(){
				$(oid).style.display='none';
				$(oid).style.top='';
				$(oid).style.bottom='';
				$(oid).style.left='';
				Effect.Appear(oid,{ duration: 1.0 });
			}, 1000);
			
			$(oid).zIndex = '1';
			imageDrag = null;
			hasDragged = false;
		},
		scroll: window,
		zindex: 1000,
		ghosting: false,
		opacity: 1.0
	});
	
	$(oid).observe('mouseup', function()
	{
		if(!hasDragged) {
			if(oid.indexOf('thumb_') > -1)
				window.location = "http://" + document.location.host + "/item/details.me?item=" + oid.replace('thumb_','') + '&panel=' + pid;
			if(oid.indexOf('detail_') > -1)
				popupwin(www_root + '/item/preview.me?item=' + oid.replace('detail_',''),'preview', 670, 650, 0);
		}
		hasDragged = false;
		imageDrag = null;
	});
	
	$(oid).observe('mouseenter', function()
	{
		this.style.cursor = 'pointer';
	});
}

function makeSidebarImageDraggable(oid, pid, replace, drop)
{
	var parent = null;
	var clone = null;
	var hovering = null;
	var imageDrag = null;
	var hasDragged = false;
	var timeout = null;
	
	var Lightbox = {
		dx: $('light_images').offsetLeft,
		dy: $('light_images').offsetTop,
		dw: $('light_images').offsetWidth,
		dh: $('light_images').offsetHeight,
		active: false,
		inBounds: function(x, y)
		{
			if(this.inX(x) && this.inY(y))
			{
				Ele.changeClass('light_images', 'hover');
				this.active = true;
			}
			else
			{
				Ele.changeClass('light_images', '');
				this.active = false;
			}
		},
		inX: function(x) {
			if(x >= this.dx && x <= (this.dx + this.dw))
				return true;
			else
				return false;
		},
		inY: function(y) {
			if(y >= this.dy && y <= (this.dy + this.dh))
				return true;
			else
				return false;
		}
	};
	
	var Basket = {
		dx: $('basket_images').offsetLeft,
		dy: $('basket_images').offsetTop,
		dw: $('basket_images').offsetWidth,
		dh: $('basket_images').offsetHeight,
		active: false,
		inBounds: function(x, y)
		{
			if(this.inX(x) && this.inY(y))
			{
				Ele.changeClass('basket_images', 'hover');
				this.active = true;
			}
			else
			{
				Ele.changeClass('basket_images', '');
				this.active = false;
			}
		},
		inX: function(x) {
			if(x >= this.dx && x <= (this.dx + this.dw))
				return true;
			else
				return false;
		},
		inY: function(y) {
			if(y >= this.dy && y <= (this.dy + this.dh))
				return true;
			else
				return false;
		}
	};
	
	var Search = {
		dx: $('search_images').offsetLeft,
		dy: $('search_images').offsetTop,
		dw: $('search_images').offsetWidth,
		dh: $('search_images').offsetHeight,
		active: false,
		inBounds: function(x, y)
		{
			if(this.inX(x) && this.inY(y))
			{
				Ele.changeClass('search_images', 'hover');
				this.active = true;
			}
			else
			{
				Ele.changeClass('search_images', '');
				this.active = false;
			}
		},
		inX: function(x) {
			if(x >= this.dx && x <= (this.dx + this.dw))
				return true;
			else
				return false;
		},
		inY: function(y) {
			if(y >= this.dy && y <= (this.dy + this.dh))
				return true;
			else
				return false;
		}
	};
	
	var t = new Draggable(oid, {
		revert: false,
		onStart: function() {
			dragImageParent = pid;
			dragImageId = oid;
			
			parent = Ele.parent(oid);
			$(oid).style.position = 'absolute';
			hasDragged = false;
			dragImage = oid;
			
			clone = $(oid).cloneNode(true);
			clone.id = oid+'_clone';
			clone.style.opacity = '0.08';
			$(oid).parentNode.insertBefore(clone, $(oid));
			
			$('main_content').appendChild($(oid));
			timeout = setTimeout(function(){imageDrag = oid;hasDragged = true},250);
		},
		onDrag: function(event) {
			if(dragImageParent == '')
				dragImageParent = pid;
			else
				dragImageParent = '';
			
			delta = t.currentDelta();
			dx = delta[0];
			dy = delta[1];
			
			Lightbox.inBounds(dx, dy);
			Basket.inBounds(dx, dy);
			Search.inBounds(dx, dy);
				
		},
		onEnd: function(event) {
			clearTimeout(timeout);
			imageDrag = null;
			hasDragged = false;
			$(oid).style.display = 'none';
			
			activeArea = null;
			if(Lightbox.active)
			{
				activeArea = 'lightbox';
				Ele.changeClass('light_images', '');
			}
			else if(Basket.active)
			{
				activeArea = 'basket';
				Ele.changeClass('basket_images', '');
			}
			else if(Search.active)
			{
				activeArea = 'search';
				Ele.changeClass('search_images', '');
			}
			
			switch(activeArea)
			{
				case 'lightbox':
					Ele.remove(parent, clone.id);
					Ele.append(parent, oid);
					
					$(oid).style.opacity = '0';
					$(oid).style.top = '';
					$(oid).style.left = '';
					Effect.Appear(oid,{ duration: 2.0 });
					
					switch(pid)
					{
						case 'basket':
							url = 'http://' + document.location.host + '/lightbox/add.me?item=' + oid.replace(replace,'');
							//Ele.ajax(url, 'post', true);
							//get_box('lightbox');
							ajaxFunction(dragImageId, 'light_images', url);
							new Effect.Pulsate('light_images', {pulses:1, duration:1.5});
						break;
					}
					
				break;
				
				case 'basket':
					Ele.remove(parent, clone.id);
					Ele.append(parent, oid);
					
					$(oid).style.opacity = '0';
					$(oid).style.top = '';
					$(oid).style.left = '';
					Effect.Appear(oid,{ duration: 2.0 });
					
					switch(pid)
					{						
						case 'lightbox':
							url = 'http://' + document.location.host + '/basket/add.me?item=' + oid.replace(replace,'');
							//Ele.ajax(url, 'post', true);
							//get_box('basket');
							ajaxFunction(dragImageId, 'basket_images', url);
							new Effect.Pulsate('basket_images', {pulses:1, duration:1.5});
						break;
					}
				break;
				
				case 'search':
					Ele.remove(parent, clone.id);
					Ele.append(parent, oid);
					
					$(oid).style.opacity = '0';
					$(oid).style.top = '';
					$(oid).style.left = '';
					Effect.Appear(oid,{ duration: 2.0 });
				break;
				
				case null:
					url = 'http://' + document.location.host + '/'+pid+'/remove.me?item=' + oid.replace(replace,'');
					if(!Prototype.Browser.IE)
					{
						Ele.remove(Ele.parent(parent), parent);
						Ele.remove('main_content', oid);
						
						
						new Effect.Pulsate(drop+'_images', {pulses:1, duration:1.0});
						Ele.ajax(url, 'post', true);
					}
					else
					{
						Ele.remove(parent, clone.id);
						Ele.append(parent, oid);
						
						$(oid).style.opacity = '0';
						$(oid).style.top = '';
						$(oid).style.left = '';

						Effect.Pulsate(drop+'_images', {pulses:1, duration:1.0});
						new Ajax.Request(url,
						{
						  method:'get',
						  onSuccess: function(transport){
							 var response = "Success";
							 //alert("Success! \n\n" + response);
						  },
						  onFailure: function(){ var response = "Failed"; }
						});
					}
				break;
			}
		},
		zindex: 1000,
		ghosting: false,
		opacity: 1.0
	});
	
	$(oid).observe('mouseup', function()
	{
		if(!hasDragged)
			window.location = "http://" + document.location.host + "/item/details.me?item=" + oid.replace(replace,'') + '&panel=' + pid;

		hasDragged = false;
		imageDrag = null;
			
	});
	
	$(oid).observe('mouseenter', function()
	{
		this.style.cursor = 'pointer';
	});
}

function makeDroppable(oid, pname, url, className)
{
	Droppables.add(oid, {
		accept: className,
		hoverclass: 'hover',
		onDrop: function()
		{
			id = 0;
			if(document.getElementById('thumb_'+dragImageId))
			{
				receivedObject = document.getElementById('thumb_'+dragImageId);
				id = dragImageId;
			}
			else
			{
				receivedObject = document.getElementById(dragImageId);
				id = dragImageId.replace('thumb_', '');
				if(dragImageId.indexOf('detail_') > -1)
					id = dragImageId.replace('detail_', '');
				if(dragImageId.indexOf('video_') > -1)
					id = dragImageId.replace('video_', '');
			}
			
			receivedObject.style.display = 'none';
			addNavUrl = url + id;
			
			if(dragImageId.length > 0 && url.length > 0)
			{
				ajaxFunction(dragImageId, oid, addNavUrl);
				new Effect.Pulsate(oid, {pulses:1, duration:1.0});
			}
			
			Effect.Appear(receivedObject.id,{ duration: 3.0 });
		}
	});
}

function getResultId(searchImageId) {
	dragImageId = searchImageId + "";
}

function bodyMovement(){
	var popPreviews1 = document.getElementsByClassName("popPreview");
	var popPreviews_id1 = "";
	
	for (p = 0; p < popPreviews1.length; p++) {
		popPreviews_id1 = popPreviews1[p].id.substring(4, popPreviews1[p].id.length);
		if (dragImageId == popPreviews_id1) {
			if (!document.getElementById(popPreviews_id1).onmouseover) {
				//document.getElementById('alerter').innerHTML = dragImageId;
				//alert(popPreviews1.length + ', ' + popPreviews1[p].id);
				//$(popPreviews_id).fade({duration: 0.5});
				popPreviews1[p].style.display = 'block';
			}
			else
				popPreviews1[p].style.display = 'none';
		}
	}
}

function removePop(popImgObj) {
var popRemove = setTimeout(function(){
//alert(dragImageId+', '+popImgObj);
if (dragImageId != popImgObj.substring(4, popImgObj.length)) {
		if (dragStatus == 'drop') {
				document.getElementById(popImgObj).style.display = 'none';
				imgOut - 'false';
			}
		}
}, 200);
k=k+1;
//document.getElementById('alerter').innerHTML = 'remove' + k +', '+dragImageId;
}



function popit(detailUrl, popImageName) {
	setTimeout(function(){
			loading = 'loading';
			latestPop = popImageName; 
			//alert(detailUrl+', '+latestPop)
			showPop(detailUrl, popImageName);		
	},1000);
	//alert(latestPop);
	
	loading='';
}

function closePop(popid) {
	document.getElementById(popid).style.display = 'none';
}

function showPop(detailUrl, popImageName){
imgItemId = popImageName.substring(4, popImageName.length);
	//document.getElementById('alerter').innerHTML = 'show';
	if (loading == 'loading') {
		//alert(latestPop+', '+popImageName);
	
			if (dragStatus == 'drop') {
				imgItemId = popImageName.substring(4, popImageName.length);
				setTimeout(function(){
					ajaxFunction(imgItemId, "detail", detailUrl);
					//alert(detailUrl);
				}, 1005);
				
				dragImageId = imgItemId;
				mouseStatus = 'true_' + imgItemId;
				var popPreviews = document.getElementsByClassName("popPreview");
				var popPreviews_id = "";
				if (popOpen == 'open') {
					for (p = 0; p < popPreviews.length; p++) {
						popPreviews_id = popPreviews[p].id;
						if (popImageName != popPreviews_id) {
							//$(popPreviews_id).fade({duration: 0.5});
							popPreviews[p].style.display = 'none';
						}
					}
					popOpen = 'closed';
				}
				
				var popPreview = setTimeout(function(){
				
					//$(popImageName).appear({duration: 0.5});
					
					if (popImageName != 'mainBody') {
						//document.getElementById('alerter').style.backgroundColor = 'red';
						if (document.getElementById('img_' + imgItemId)) {
							popImgWidth = document.getElementById('img_' + imgItemId).width;
							
							popPopWidth = 390 + (popImgWidth);
							document.getElementById('pop_' + imgItemId).style.width = popPopWidth + 'px';
							var thumbImg_X = document.getElementById(imgItemId).offsetLeft;
							var thumbImg_Y = document.getElementById(imgItemId).offsetTop;
							document.getElementById(popImageName).style.top = thumbImg_Y + 'px';
							document.getElementById(popImageName).style.left = thumbImg_X + 'px';
							popOpen = 'open';
							document.getElementById(popImageName).style.display = 'block';
						}
					}
				}, 500);
			}
		}
	}

function updateBoxState(box_action) {
	//alert('asdfasd fas a');
	new Ajax.Request(box_action, { method:'post' });
}

function ajaxFunction(imgNumber,moduleName, ajaxPageUrl) {
	
	if(moduleName == 'light_images') {
		document.getElementById('dragLightHelp').style.display = 'none';
		document.getElementById('lightbox_thumbnails').innerHTML = "<img src='/images/loader.gif' style='margin-left:-120px'</img>";
	}
	if(moduleName == 'basket_images') {
		document.getElementById('dragBasketHelp').style.display = 'none';
		document.getElementById('basket_thumbnails').innerHTML = "<img src='/images/loader.gif' style='margin-left:-120px'</img>";
	}
	var xmlHttp;
	var xmlText="";
try
  {  // Firefox, Opera 8.0+, Safari  
  xmlHttp=new XMLHttpRequest();  }

catch (e)
  {  // Internet Explorer  
  try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      
	  		 return false;      }    }  }
  xmlHttp.onreadystatechange=function()
    { 
    if (xmlHttp.readyState == 4) {
		
		xmlText = xmlHttp.responseText;
		var startIndex = xmlText.indexOf(moduleName+'_start');
		var endIndex = xmlText.indexOf(moduleName+'_end');
		//alert(moduleName+', '+startIndex+', '+endIndex);
						//alert(xmlText);
						//alert(moduleName+'_start, '+startIndex+', '+endIndex)
		xmlText = xmlText.substring(startIndex, endIndex);
		xmlText = xmlText.replace(/&/ig,"and");

//alert(startIndex + ', ' + endIndex);

		

		if (ajaxPageUrl.indexOf('lightbox/remove.me') > -1 | ajaxPageUrl.indexOf('lightbox/add.me') > -1 | ajaxPageUrl.indexOf('lightbox/list.me') > -1) {
				if($('hook_lightbox_'+imgNumber)) {
					$('hook_lightbox_'+imgNumber).src = "/images/loader.gif";
					$('hook_lightbox_'+imgNumber).style.width = "12px";
				}
			newIndex = xmlText.length - 2;
			lights_number = xmlText.substring(newIndex, xmlText.length);
			increasePanelHeight(lights_number, "lightboxPanel");
			
			if (document.getElementById('lightBoxBody')) {
				document.getElementById('lightBoxBody').innerHTML = '<!--' + xmlText + '-->';

			}
			if (document.getElementById('lightimages_span')) {
				//alert(xmlText);
				
				setTimeout(function(){
					get_box('lightbox');
					
					if($('hook_lightbox_'+imgNumber)) {
						if (navigator.appName.indexOf("Netscape")!=-1
							&&parseInt(navigator.appVersion)>=5)
						  $('hook_lightbox_'+imgNumber).style.opacity = '0.5';
						else if (navigator.appName.indexOf("Microsoft")!= -1 
							&&parseInt(navigator.appVersion)>=4)
						  $('hook_lightbox_'+imgNumber).style.filter = 'alpha(opacity=50)';
						  
						$('hook_lightbox_'+imgNumber).title = 'Already in lightbox';
						$('hook_lightbox_'+imgNumber).alt = 'Already in lightbox';
					}
					
				},100);
				if($('hook_lightbox_'+imgNumber)) {
					$('hook_lightbox_'+imgNumber).src = "/images/icon_sm_lightbox.png";
					$('hook_lightbox_'+imgNumber).style.width = null;
				
				}
			}
			if(document.getElementById('dragLightHelp')) {
				//document.getElementById('dragLightHelp').innerHTML = '';
				document.getElementById('dragLightHelp').style.display = 'none';
			}
			
		}

		if (ajaxPageUrl.indexOf('basket/add.me') > -1 | ajaxPageUrl.indexOf('basket/remove.me') > -1) {
				if($('hook_basket_'+imgNumber)) {
					$('hook_basket_'+imgNumber).src = "/images/loader.gif";
					$('hook_basket_'+imgNumber).style.width = "12px";
				}
			newIndex = xmlText.length - 2;
			basket_number = xmlText.substring(newIndex, xmlText.length);
			increasePanelHeight(basket_number, "basketPanel");
			
			/*
			if (document.getElementById('basketBoxPanel')) {
				document.getElementById('basketBoxPanel').innerHTML = '<!--' + xmlText + '-->';
			}
			*/
			if (document.getElementById('basketimages_span')) {
				//alert(xmlText);
				
				setTimeout(function(){
					get_box('basket');
					if($('hook_basket_'+imgNumber)) {
						if (navigator.appName.indexOf("Netscape")!=-1
							&&parseInt(navigator.appVersion)>=5)
						  $('hook_basket_'+imgNumber).style.opacity = '0.5';
						else if (navigator.appName.indexOf("Microsoft")!= -1 
							&&parseInt(navigator.appVersion)>=4)
						  $('hook_basket_'+imgNumber).style.filter = 'alpha(opacity=50)';
						  
						$('hook_basket_'+imgNumber).title = 'Already in basket';
						$('hook_basket_'+imgNumber).alt = 'Already in basket';
					}
				},100);
				if($('hook_basket_'+imgNumber)) {
					$('hook_basket_'+imgNumber).src = "/images/icon_sm_basket.png";
					$('hook_basket_'+imgNumber).style.width = null;
				
				}
			}
			if(document.getElementById('dragBasketHelp')) {
				//document.getElementById('dragBasketHelp').innerHTML = '';
				document.getElementById('dragBasketHelp').style.display = 'none';
			}
			
		}
	}
    }
		
	if (ajaxPageUrl.indexOf('search.me') <= -1) {
		xmlHttp.open("GET", ajaxPageUrl, true);
		xmlHttp.send(null);
	}
	if (ajaxPageUrl.indexOf('search.me') > -1) {
		var title_to_search = '';	
		if(moduleName.indexOf('basket') > -1) {
			title_to_search = document.getElementById('title_basket_' + dragImgId).value;
		}
		if(moduleName.indexOf('lightbox') > -1) {
			title_to_search = document.getElementById('title_lightbox_' + dragImgId).value;
		}
		if(moduleName.indexOf('search_images') > -1) {
			title_to_search = document.getElementById('title_' + dragImgId).value;
		}
		
		document.getElementById('text').value = title_to_search;
		setTimeout(function(){
			document.forms['show_search_side'].submit();
		},500);
		
	}
  
  }



	function ajaxFunction_original(imgNumber,moduleName, ajaxPageUrl)
{
	imgNumber = imgNumber.substring(4, imgNumber.length);
	var coolIris = "";
	if (moduleName == 'preview') {
		if (document.getElementById('search-results')) {
			if(document.getElementById('cooliris_prompt'))
				coolIris = document.getElementById('cooliris_prompt').innerHTML;
			//document.getElementById('search-results').innerHTML =  "<div id='cooliris_prompt'>" + coolIris + "</div>" + "Loading .. .";
		}
	}
	var xmlHttp;
	var xmlText="";
try
  {  // Firefox, Opera 8.0+, Safari  
  xmlHttp=new XMLHttpRequest();  }

catch (e)
  {  // Internet Explorer  
  try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      
	  		 return false;      }    }  }
  xmlHttp.onreadystatechange=function()
    { 
    if (xmlHttp.readyState == 4) {
		
		xmlText = xmlHttp.responseText;
		var startIndex = xmlText.indexOf(moduleName+'_start');
		var endIndex = xmlText.indexOf(moduleName+'_end');
		//alert(moduleName+', '+startIndex+', '+endIndex);
						//alert(xmlText);
						//alert(moduleName+'_start, '+startIndex+', '+endIndex)
		xmlText = xmlText.substring(startIndex, endIndex);
		xmlText = xmlText.replace(/&/ig,"and");

//alert(startIndex + ', ' + endIndex);

		if (ajaxPageUrl.indexOf('details.me') > -1) {
			setTimeout(function(){
			xmlText = xmlText.replace(/<br\/>/g, "");
			xmlText = xmlText.replace(/<br \/>/g, "");
			//alert(xmlText);
			if (document.getElementById('det_' + imgItemId)) 
				//document.getElementById('det_' + imgItemId).innerHTML = '<!--' + xmlText + '-->';
				
				BetterInnerHTML(document.getElementById('det_' + imgItemId),"<!--" + xmlText + "--></div></div>");
				if (moduleName != 'preview' & document.getElementById('tab1_' + imgNumber)) 
					document.getElementById('tab1_' + imgNumber).style.display = 'none';
				else {
					if (moduleName == 'preview')
						tabs = new TabControl('tab1_' + imgNumber, tabs, imgNumber);
				}
},0);
		}
		
		if (ajaxPageUrl.indexOf('search/results.me') > -1) {

			if (document.getElementById('main')) {
				//setTimeout(function(){
					//alert(xmlText);
					document.getElementById('main').innerHTML = '<!--' + xmlText + '-->';
			//},3000); 
			}
		}
		if (moduleName == 'preview') {
			if (document.getElementById('search-results')) {
				//document.getElementById('search-results').innerHTML = "<div id='cooliris_prompt'>" + coolIris + "</div>" + "<div class='details' id='detail-preview'><!--" + xmlText + "--></div>";
				//document.getElementById('search-results').innerHTML = "<div class='details' id='detail-preview'><!--" + xmlText + "--></div>";
				//document.write("<pre><div class='details' id='detail-preview'><!--" + xmlText + "--></div></pre>");					
			//alert('tab1_'+imgItemId);				
				BetterInnerHTML(document.getElementById('search-results'), "<div class='details' id='detail-preview'><!--" + xmlText + "--></div>");

			}
			if (document.getElementById('detail-preview')) {
				if (!document.getElementById('search-results')) {

					BetterInnerHTML(document.getElementById('detail-preview'), "<div id='cooliris_prompt'>" + coolIris + "</div>" + "<!--" + xmlText + "-->");
					//tabs = new TabControl ('tab1_' + imgNumber, tabs, imgNumber);
				//document.getElementById('detail-preview').innerHTML = "<div id='cooliris_prompt'>" + coolIris + "</div>" + "<!--" + xmlText + "-->";

				}
			}
		}

		if (ajaxPageUrl.indexOf('lightbox/add.me') > -1 | ajaxPageUrl.indexOf('lightbox/list.me') > -1) {

			if (document.getElementById('lightBoxBody')) {
				document.getElementById('lightBoxBody').innerHTML = '<!--' + xmlText + '-->';

			}
			if (document.getElementById('lightboxPanel')) {
				document.getElementById('lightboxPanel').innerHTML = '<!--' + xmlText + '-->';	
			}
			newIndex = xmlText.length - 2;
			lights_number = xmlText.substring(newIndex, xmlText.length);
			increasePanelHeight(lights_number, "lightboxPanel");
		}

		if (ajaxPageUrl.indexOf('basket/add.me') > -1) {
			
			if (document.getElementById('basketBoxPanel')) {
				document.getElementById('basketBoxPanel').innerHTML = '<!--' + xmlText + '-->';
			}
			newIndex = xmlText.indexOf('baskets = ');
			basket_number = xmlText.substring(newIndex, newIndex+16);
			basket_number = basket_number.substring(10, 12);
			increasePanelHeight(basket_number, "basketBoxPanel");
		}
	}
    }
	
	if (ajaxPageUrl.indexOf('search/results.me') > -1) {
		//alert('here');
		  xmlHttp.open("GET",ajaxPageUrl,true);
	}
	else {

		xmlHttp.open("GET",ajaxPageUrl,true);
	}

  xmlHttp.send(null);  
  }
function showAdminDetails(linkId){
	
	if (linkId.indexOf('show') > -1) {
		document.getElementById(linkId).style.display = 'none';
		document.getElementById('admin-details').style.display = 'block';
		document.getElementById('more_details_hide').style.display = 'block';
	}
	else {
		document.getElementById('more_details_show').style.display = 'block';
		document.getElementById('admin-details').style.display = 'none';
		document.getElementById('more_details_hide').style.display = 'none';
	}
}

// this function is needed to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   
  
  
 function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#EFEFEF";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }



