var sCurrentNewsID = "";

function xp(source)
{
	var divid = source.getAttribute("tgt");
	var catid = source.getAttribute("catid");
	
	if ((divid == null) || (divid == undefined) || (divid== "")) return;
	
	source.className = (source.className == "ctsup") ? "ctsupcollapse" : "ctsup";
	
	var div = document.getElementById(divid);
	div.className = (div.className == "subexpanded") ? "subcollapse" : "subexpanded";	
	
	
	var s = div.getAttribute("txt");
	if ((s == null) || (s == undefined) || (s == ""))
	{
		var sURL = "callbacks.aspx?callback=1&type=subcat&id=" +catid;
		var s = sendXMLRequest( sURL, "" );
	
		div.innerHTML = s;
		div.setAttribute("txt", "1");	
	}
	

}

function getNewsText(sNewsID)
{
	if (!newsIsFetched(sNewsID))
	{
		var sURL = "callbacks.aspx?callback=1&type=news&id=" +sNewsID;
		var s = sendXMLRequest( sURL, "" );
	
		var div = document.createElement("div");
		div.innerHTML = s;
		document.getElementById("itemdiv").appendChild(div);
	}
	ss(sNewsID);
}

function newsIsFetched(sNewsID)
{
 var allLinks = document.getElementsByTagName('a');
 var destinationLink = null;
 for (var i=0;i<allLinks.length;i++) 
 {
   var lnk = allLinks[i];
   if (lnk.name && (lnk.name == sNewsID)) 
   {
     return true;
     break;
   }
 }

 return false;
}


//----------------------------- BEGIN Advanced search js functions --------------------------------//

var srch_selectedid = "";

function getsubcategories()
{

	//debugger;
	var list = document.getElementById("lbCat");
	
	
	
	var sID = list.options[list.selectedIndex].value;
	
	var temp = new Array();
	
	temp = sID.split("~");
	
	if( temp[1] == "0" ) 
	{
		document.getElementById("divsubcat").innerHTML = "<div>Δεν υπάρχουν υποκατηγορίες</div>";
		srch_selectedid = "";
		return;
	}
	
	if( srch_selectedid == temp[0] ) return;
	
		
	
	srch_selectedid = temp[0];
	
	var sURL = "callbacks.aspx?callback=1&type=getsubcat&id=" + temp[0];
	var s = sendXMLRequest( sURL, "" );
	
	document.getElementById("divsubcat").innerHTML = s;
}

function addSelectedCategories()
{
	// 1. Build the selected IDs
	
	var lstSub = document.getElementById("lbSub");
	var lstCat = document.getElementById("lbCat");
	
	if (lstCat.selectedIndex == -1) return;
	
	var sMasterID = lstCat[lstCat.selectedIndex].value;
	var temp = new Array();
	temp = sMasterID.split("~");
	sMasterID = temp[0];
	
	var sSubCatID = "";
	var selectedIDs = new Array();
	
	var n=0;
	
	if (lstSub != null)
	{
		for(i=0; i<lstSub.length; i++)
		{
			if(lstSub[i].selected)
			{
				//selectedIDs[selectedIDs.length] = sMasterID + "~" + lstSub[i].value;
				selectedIDs[n++] = lstCat.selectedIndex + "~" + i;
			}
		}
	
	}
	else
	{
		selectedIDs[0] = "" + lstCat.selectedIndex;
	}
	
	var sDescr, sCatID, sID = "";
	
		
	for(var i=0;i<selectedIDs.length;i++)
	{
		sID = selectedIDs[i];
		temp = selectedIDs[i].split("~");
		sCatID = lstCat[temp[0]].value;
		sCatID = sCatID.split("~")[0];
		
		if(temp.length == 1)
		{
			sDescr = lstCat[temp[0]].text; 
		}
		else
		{
			sCatID += "~" + lstSub[temp[1]].value;
			sDescr = lstCat[temp[0]].text + " -> " + lstSub[temp[1]].text;
		}
		
		
		if (!CategoryIsSelected(sCatID))
		{
			addCategory(sDescr, sCatID); 
		}
		
	}
	
	SetSelectedCategoryValues();
}

function addCategory( sText, sValue )
{
	var list = getSelectedListbox();
	list.options[list.options.length] = new Option( sText, sValue );
}

function getSelectedListbox()
{
	return document.getElementById("lbSelected");
}

function ClearSelectedCategories()
{

	var list = getSelectedListbox();
	
	var sel = new Array();
	var n=0;
	
	for(var i=0; i<list.length; i++)
	{
		if(list[i].selected) sel[n++] = list[i].value;
	}
	
	for(var i=0;i<sel.length;i++)
	{
		for(var j=0;j<list.length;j++)
		{
			if(list[j].value == sel[i]) list[j] = null;
		}
	}
	
	SetSelectedCategoryValues();
}

function ClearAllSelectedCategories()
{
	var list = getSelectedListbox();
	list.options.length = 0;
	var hf = document.getElementById("hfCategories");
	hf.value = "";
	
}

function CategoryIsSelected(sIDs)
{
	var list = getSelectedListbox();
	for(var i=0;i<list.length;i++)
	{
		if( list[i].value == sIDs) return true;
	}
	return false;
}

function GetSelectedCategoryValues()
{
	var hf = document.getElementById("hfCategories");
	return hf.value;
}

function NoCategoriesSelected() 
{
	return (GetSelectedCategoryValues() == "")
}

function SetSelectedCategoryValues()
{
	var hf = document.getElementById("hfCategories");
	hf.value = "";
	var list = getSelectedListbox();
	
	if (list.length == 0) return;
	
	for(var i=0;i<list.length;i++)
	{
		hf.value += list[i].value + ",";
	}
	
}


function advsearch()
{
 document.location.href = "AdvancedSearch.aspx";
}

function ClearAdvSearchForm()
{
	document.getElementById("txtTitleYes").value = "";
	document.getElementById("txtTitleNo").value = "";
	document.getElementById("txtAuthorNo").value = "";
	document.getElementById("txtAuthorYes").value = "";
	document.getElementById("txtISBN").value = "";
	
	document.getElementById("ddlPrice").selectedIndex = 0;
	
	ClearAllSelectedCategories();
	

}

function FldIsEmpty(ctl)
{
	var s = document.getElementById(ctl).value;
	return (Trim(s) == "");
}


function doSearch(ctltxt,ctl_list)
{
	
	var sSearch = document.getElementById(ctltxt);
	var sType = "";
	
	//var list = document.Form1(ctl_list);
	var list = document.getElementById(ctl_list);
	
	
	sType = list.selectedIndex;
	
	if( sSearch.value == "" )
	{
		return;
	}
	
	var sURL = "SearchResults.aspx?search=";
	
	sURL = sURL + encodeURIComponent( sSearch.value ) + "&type=" + sType;
	document.location.href = sURL;	
}

function navigate( type, searchText, page )
{
	var sURL = "SearchResults.aspx?search=" + encodeURIComponent(searchText) + "&type=" + type + "&page=" + page;
	document.location.href = sURL;	
}

function gotoPage( type, page )
{

	var sURL = "";
	
	switch( type )
	{
		case "pr":
			sURL = "Prosfores.aspx?page=" + page;
			break;		
	}
	
	document.location.href = sURL;
}

function s(id)
{
	var sURL = "SearchResults.aspx?search=" + id + "&type=3";
	document.location.href = sURL;
}

function ShowBib( ctl, authorid )
{
	
	var s = ctl.innerText;
	if(s == undefined)
	{
		s = ctl.value;
	}
	
	var sURL = "AuthorList.aspx?id=" + authorid + "&name=" + encodeURIComponent(ctl.innerText);
	document.location.href = sURL;
}

var MSG_NOQTY = "Δεν έχετε εισάγει ποσότητα";
var MSG_QTY_INVALID = "H ποσότητα πρέπει να είναι ακέραιος μεταξύ 1 και 999";

function AddToCart( id )
{
	var s = document.getElementById("qty").value;
	if( IsEmpty(s) )
	{
		alert(MSG_NOQTY);
		return;
	}
	
	if( !IsValidQuantity(s) )
	{
		alert(MSG_QTY_INVALID);
		return;
	}

	
	var sURL = "callbacks.aspx?callback=1&type=add2cart&id=" + id + "&qty=" + s;
	var s = sendXMLRequest( sURL, "" );
	alert(s); 
}

function IsValidQuantity( s )
{
	if( !IsInteger(s) )
	{
		return false;
	}
	
	if( (s<=0) || (s>999) )
	{
		return false;
	}
	
	return true; 
}


function UpdateCartItem( sItemID, ctlQty, bIsOrderConfirm )
{
	
	var s = document.getElementById(ctlQty).value;
	if( IsEmpty(s) )
	{
		alert(MSG_NOQTY);
		return;
	}
	
	if( !IsValidQuantity(s) )
	{
		alert(MSG_QTY_INVALID);
		return;
	}
	
	
	
	
	var sURL = "callbacks.aspx?callback=1&type=updcartitem&id=" + sItemID + "&qty=" + s;
	
	if(bIsOrderConfirm)
	{
		sURL += "&order=1";
	}
	
	var s = sendXMLRequest( sURL, "" );
	
	document.getElementById("divcart").innerHTML = s;

}

function DelCartItem( sItemID, bIsOrderConfirm )
{
	if( confirm("Θέλετε να διαγράψετε το συγκεκριμένο τίτλο από τα καλάθι σας?") == false )
	{
		return;
	}
	var sURL = "callbacks.aspx?callback=1&type=delcartitem&id=" + sItemID;
	
	if(bIsOrderConfirm)
	{
		sURL += "&order=1";
	}
	
	var s = sendXMLRequest( sURL, "" );
	
	document.getElementById("divcart").innerHTML = s;
}

function emptycart()
{
	if( confirm("Είσθε σίγουρος/σίγουρη ότι θέλετε να αδειάσετε το καλάθι σας?") == false )
	{
		return;
	}
	var sURL = "callbacks.aspx?callback=1&type=emptycart";
	var s = sendXMLRequest( sURL, "" );
	
	document.getElementById("divcart").innerHTML = s;
}

function sendXMLRequest( pageURL, sFORMData )
{
	window.status = "Processing...";
	document.body.style.cursor = 'wait';
	try
	{
		var xmlRequest = new getXMLRequestObject();
		xmlRequest.open("POST", pageURL, false);
		xmlRequest.setRequestHeader("Content-Type",  "application/x-www-form-urlencoded");
		xmlRequest.send(sFORMData);
		return xmlRequest.responseText;
	}
	finally
	{
		window.status = "";
		document.body.style.cursor = 'auto';
	}
}

function IsIE()
{
	if (window.ActiveXObject)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function getXMLRequestObject()
{
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
		return xmlhttp;
	}
	
	if(window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		return xmlhttp;
	}
}

function IsEmpty(s)	
{   
   return ((s == null) || (s.length == 0) || s=="");
}

function IsInteger(theData) 
{ 
  return (theData.search(/^\d+$/) != -1); 
}


function ExpanderPanel_Toggle( targetID, buttonID, trackerID, imageUrl, collapsedImageUrl ) 
{
	if ( document.getElementById ) 
	{
		var target = document.getElementById( targetID );
		if ( target != null ) 
		{
			target.style.display = ( target.style.display != "none" ) ? "none" : "";
		}
		if ( collapsedImageUrl != "" ) 
		{
			var imageButton = document.getElementById( buttonID );
			if ( imageButton != null ) 
			{
				imageButton.src = ( target.style.display != "none" ) ? collapsedImageUrl : imageUrl;
			}
		}
		var tracker = document.getElementById( trackerID );
		if ( tracker != null ) 
		{
			tracker.value = ( target.style.display == "none" ) ? "True" : "False";
		}
		return false;
	}
	return true;
}

function Trim(s) 
{
   	
   	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
   	 { s = s.substring(1,s.length); }
     
   	// Remove trailing spaces and carriage returns
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
   	 { s = s.substring(0,s.length-1); }
     
   	return s;
}

/********************* BEGIN Functions for smooth scrolling *************************/

function ss(anchor) 
{

 // Now loop all A tags until we find one with that name
 var allLinks = document.getElementsByTagName('a');
 var destinationLink = null;
 for (var i=0;i<allLinks.length;i++) 
 {
   var lnk = allLinks[i];
   if (lnk.name && (lnk.name == anchor)) 
   {
     destinationLink = lnk;
     break;
   }
 }
 
 // If we didn't find a destination, give up and let the browser do
 // its thing
 if (!destinationLink) return true;
 
 // Find the destination's position
 var destx = destinationLink.offsetLeft;  
 var desty = destinationLink.offsetTop;
 var thisNode = destinationLink;
 while (thisNode.offsetParent && (thisNode.offsetParent != document.body)) 
 {
   thisNode = thisNode.offsetParent;
   destx += thisNode.offsetLeft;
   desty += thisNode.offsetTop;
 }
 
 // Stop any current scrolling
 clearInterval(ss_INTERVAL);
 
 cypos = ss_getCurrentYPos();
 
 ss_stepsize = parseInt((desty-cypos)/ss_STEPS);
 ss_INTERVAL = setInterval('ss_scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
 
 // And stop the actual click happening
 if (window.event) 
 {
   window.event.cancelBubble = true;
   window.event.returnValue = false;
 }
 else
 {
	return false;
 }
 /*
 if (e && e.preventDefault && e.stopPropagation) 
 {
   e.preventDefault();
   e.stopPropagation();
 }
 */
}

function ss_scrollWindow(scramount,dest,anchor) 
{
 wascypos = ss_getCurrentYPos();
 isAbove = (wascypos < dest);
 window.scrollTo(0,wascypos + scramount);
 iscypos = ss_getCurrentYPos();
 isAboveNow = (iscypos < dest);
 if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
   // if we've just scrolled past the destination, or
   // we haven't moved from the last scroll (i.e., we're at the
   // bottom of the page) then scroll exactly to the link
   window.scrollTo(0,dest);
   // cancel the repeating timer
   clearInterval(ss_INTERVAL);
   // and jump to the link directly so the URL's right
   location.hash = anchor;
 }
}

function ss_getCurrentYPos() 
{
 if (document.body && document.body.scrollTop)
   return document.body.scrollTop;
 if (document.documentElement && document.documentElement.scrollTop)
   return document.documentElement.scrollTop;
 if (window.pageYOffset)
   return window.pageYOffset;
 return 0;
}

var ss_INTERVAL;
var ss_STEPS = 25;

/********************* END   Functions for smooth scrolling *************************/

/********************* BEGIN drop shadow functions **********************************/

var gradientshadow={}
gradientshadow.depth=6 //Depth of shadow in pixels
gradientshadow.containers=[]

gradientshadow.create=function(){
var a = document.all ? document.all : document.getElementsByTagName('*')
for (var i = 0;i < a.length;i++) {
	if (a[i].className == "shadow") {
		for (var x=0; x<gradientshadow.depth; x++){
			var newSd = document.createElement("DIV")
			newSd.className = "shadow_inner"
			newSd.id="shadow"+gradientshadow.containers.length+"_"+x //Each shadow DIV has an id of "shadowL_X" (L=index of target element, X=index of shadow (depth) 
			if (a[i].getAttribute("rel"))
				newSd.style.background = a[i].getAttribute("rel")
			else
				newSd.style.background = "black" //default shadow color if none specified
			document.body.appendChild(newSd)
		}
	gradientshadow.containers[gradientshadow.containers.length]=a[i]
	}
}
gradientshadow.position()
window.onresize=function(){
	gradientshadow.position()
}
}

gradientshadow.position=function(){
if (gradientshadow.containers.length>0){
	for (var i=0; i<gradientshadow.containers.length; i++){
		for (var x=0; x<gradientshadow.depth; x++){
  		var shadowdiv=document.getElementById("shadow"+i+"_"+x)
			shadowdiv.style.width = gradientshadow.containers[i].offsetWidth + "px"
			shadowdiv.style.height = gradientshadow.containers[i].offsetHeight + "px"
			shadowdiv.style.left = gradientshadow.containers[i].offsetLeft + x + "px"
			shadowdiv.style.top = gradientshadow.containers[i].offsetTop + x + "px"
		}
	}
}
}



if (window.addEventListener)
window.addEventListener("load", gradientshadow.create, false)
else if (window.attachEvent)
window.attachEvent("onload", gradientshadow.create)
else if (document.getElementById)
window.onload=gradientshadow.create



/********************* END drop shadow functions **********************************/