var ROOT_URL = "http://www.kitsch-nitsch.com/";
var xmlHttp;

function openRadio(id)
{
	var WindowObject = window.open(ROOT_URL+'grooveshark.php?id='+id, 'PrintWindow', 'width=265,height=415,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
}

function placeBid()
{
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Error: Browser does not support HTTP Request!");
		return;
	} 
	
	curent_bid = document.getElementById("curent_bid").value;
	bid = document.getElementById("bid").value;
	
	if(isInteger(bid))
	{
	}
	else
	{
		document.getElementById("bidError").innerHTML = "Enter "+(parseInt(curent_bid)+1)+"€ or more";
		return;
	}
	
	if((parseInt(curent_bid) >= parseInt(bid)) || (bid == ""))
	{
		document.getElementById("bidError").innerHTML = "Enter "+(parseInt(curent_bid)+1)+"€ or more";
		return;
	}
	else
	{
		input_id = document.getElementById("input_id").value;
		bid = parseInt(bid);
		
		bids =  document.getElementById("num_bids").innerHTML;
		bids = parseInt(bids);
		
		document.getElementById("num_bids").innerHTML = (bids + 1) + " bids";
		
		document.getElementById("curent_bid").value = bid;
		document.getElementById("curentBidText").innerHTML = "€"+bid;
		
		document.getElementById("bidError").innerHTML = "&nbsp;";
		
		var url=ROOT_URL+"site/ajax/biding.php";bids
		url=url+"?input_id="+input_id;
		url=url+"&bid="+bid;
		url=url+"&action=send_mail";
		
		xmlHttp.onreadystatechange=stateChanged4;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function stateChanged4() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.responseText.length > 0)
		{ 
			document.getElementById("bidingTable").innerHTML = xmlHttp.responseText;
			if(document.getElementById('bidingTable').style.display == "none")
			{
				bidShowHide();
			}
		}
	} 
} 

function isInteger(s)
{
    return Math.ceil(s) == Math.floor(s);
}


function loginSubmit()
{
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Error: Browser does not support HTTP Request!");
		return;
	} 
	
	email = document.getElementById("email").value;
	password = document.getElementById("password").value;
	
	var url=ROOT_URL+"site/ajax/login.php";
	url=url+"?email="+email;
	url=url+"&password="+password;
	url=url+"&action=send_mail";
	
	xmlHttp.onreadystatechange=stateChanged3;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged3() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.responseText.length > 0)
		{ 
			document.getElementById("login").innerHTML = xmlHttp.responseText;
		}
	} 
} 

function registerSubmit()
{
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Error: Browser does not support HTTP Request!");
		return;
	} 
	
	email = document.getElementById("r_email").value;
	password = document.getElementById("r_password").value;
	password2 = document.getElementById("r_password2").value;
	
	var url=ROOT_URL+"site/ajax/register.php";
	url=url+"?email="+email;
	url=url+"&password="+password;
	url=url+"&password2="+password2;
	url=url+"&action=send_mail";
	
	xmlHttp.onreadystatechange=stateChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged2() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.responseText.length > 0)
		{ 
			document.getElementById("register").innerHTML = xmlHttp.responseText;
		}
	} 
} 

function watchItem()
{
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Error: Browser does not support HTTP Request!");
		return;
	} 	
	var url=ROOT_URL+"site/ajax/watch.php";
	url=url+"?action=watch_item";
	
	xmlHttp.onreadystatechange=stateChanged3;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged3() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if (xmlHttp.responseText.length > 0)
		{ 
			document.getElementById("watchItem").innerHTML = xmlHttp.responseText;
			if(document.getElementById('watchItem').style.display == "none")
			{
				watchItemShowHide();
			}
		}
	} 
} 

function watchItemShowHide()
{
	if(document.getElementById('watchItem').style.display == "none")
	{
		$(document.getElementById('watchItem')).fadeIn(500);
	}
	else
	{
		$(document.getElementById('watchItem')).fadeOut(500);
	}
}


function registerShowHide()
{
	if(document.getElementById('register').style.display == "none")
	{
		$(document.getElementById('register')).fadeIn(500);
		$(document.getElementById('login')).fadeOut(500);
	}
	else
	{
		$(document.getElementById('register')).fadeOut(500);
		$(document.getElementById('login')).fadeIn(500);
	}
}

function placeOrderShowHide()
{
	if(document.getElementById('place_order').style.display == "none")
	{
		$(document.getElementById('place_order')).fadeIn(500);
	}
	else
		$(document.getElementById('place_order')).fadeOut(500);
}

function bidShowHide()
{
	if(document.getElementById('bidingTable').style.display == "none")
	{
		$(document.getElementById('bidingTable')).fadeIn(500);
	}
	else
		$(document.getElementById('bidingTable')).fadeOut(500);
}

function loginShowHide()
{
	if(document.getElementById('login').style.display == "none")
	{
		$(document.getElementById('login')).fadeIn(500);
	}
	else
		$(document.getElementById('login')).fadeOut(500);
}

function whiteShowHide()
{
	if(document.getElementById('white').style.width == "0px")
	{
		$(document.getElementById('white')).animate({width: "215px"}, "fast");
		$(document.getElementById('shareLike')).animate({width: "215px"}, "fast");
		document.getElementById('whiteButton').className = "closeWindow";
	}
	else
	{
		$(document.getElementById('white')).animate({width: "0px"}, "fast");
		$(document.getElementById('shareLike')).animate({width: "0px"}, "fast");
		document.getElementById('whiteButton').className = "openWindow";
	}
}

function helpHide()
{
	$(document.getElementById('help')).animate({height: "0px"}, "slow");
}

function helpShow()
{
	if(document.getElementById('help').style.height == "0px")
	{
		$(document.getElementById('concept')).fadeOut(500);
		$(document.getElementById('artInfo')).animate({height: "0px"}, "slow");
		$(document.getElementById('help')).animate({height: "400px"}, "slow");
	}
	else
	{
		$(document.getElementById('help')).animate({height: "0px"}, "slow");
	}
}

function infoHide()
{
	$(document.getElementById('artInfo')).animate({height: "0px"}, "slow");
}

function infoShow()
{
	if(document.getElementById('artInfo').style.height == "0px")
	{
		$(document.getElementById('concept')).fadeOut(500);
		$(document.getElementById('help')).animate({height: "0px"}, "slow");
		$(document.getElementById('artInfo')).animate({height: "400px"}, "slow");
	}
	else
	{
		$(document.getElementById('artInfo')).animate({height: "0px"}, "slow");
	}
}

function conceptShowHide()
{
	if(document.getElementById('concept').style.display == "none")
	{
		$(document.getElementById('artInfo')).animate({height: "0px"}, "slow");
		$(document.getElementById('help')).animate({height: "0px"}, "slow");
		$(document.getElementById('concept')).fadeIn(500);
	}
	else
		$(document.getElementById('concept')).fadeOut(500);
}

function redirect(url) {
	window.location = url;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null

	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
} 

function loginInputKeyPressed(e)
{
	var keynum
	var keychar
	
	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	if (keynum==13){
		loginSubmit();
	}
	return true;
}
