// JavaScript Document
var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}



function submitForm()
{
	document.frmProcessOrder.submit();
}

function validateTermsConditions(objInput, formName, langForm)
{
	var curValue=document.getElementById(objInput).value;
	if(curValue==0)
	{
		if(langForm==1)
		{
			alert("læs og akseptere forretningsbetingelser");
		}
		else if(langForm==2)
		{
			alert("See and accept Terms and Conditions");
		}
		return false;
	}
	if(curValue==1)
	{
		return true;
		formName.submit();
	}
}


function validateTermsConditions_1(objInput, formName)
{
	var curValue=document.getElementById(objInput);
	if(curValue.checked==false)
	{
		alert("læs og akseptere forretningsbetingelser");
		return false;
	}
	if(curValue.checked==true)
	{		
			return true;
			formName.submit();	
	}
}


function validateTermsConditions_2(objInput, formName)
{
	var curValue=document.getElementById(objInput);
	if(curValue.checked==false)
	{
		alert("læs og akseptere forretningsbetingelser");
		return false;
	}
	if(curValue.checked==true)
	{
		var arrForms=new Array();

		arrForms[0]="shopNameSurname";
		arrForms[1]="shopName";	arrForms[2]="shopAddress";	arrForms[3]="shopPostNr";	arrForms[4]="shopTown";	arrForms[5]="shopTel";		
		arrForms[6]="shopMail";	arrForms[7]="shopComment";
		
		var arrLabels = new Array();
		arrLabels[0]="Navn og efternavn";
		arrLabels[1]="Virksomhedsnavn";	arrLabels[2]="Adresse";	arrLabels[3]="Post nr.";	arrLabels[4]="By";	arrLabels[5]="Telefon";		
		arrLabels[6]="Email";	arrLabels[7]="Kommentar";
		
		var arrRequired=new Array(0, 2, 3, 4, 5, 6);
		
		
		var counter=0;
		var counterRealFields=0;
		var errString="Manglende felter:";
		for(var i=0; i<arrForms.length; i++)
		{
			if(document.getElementById(arrForms[arrRequired[i]]))
			{
				var curObj=document.getElementById(arrForms[arrRequired[i]]);
			
				if(curObj.value!="" && curObj.value.length>2)
				{
					counter++;
				}
				else
				{
					errString +="\n" + arrLabels[arrRequired[i]];
				}
				counterRealFields++;
			}
		}
		if(counter<arrRequired.length)
		{
			alert(errString);
			return false;
		}
		if(counter>=arrRequired.length)
		{
			return true;
			formName.submit();
		}
	}
}

function process(objContainer, newsid)
{
	folderpath="fileadmin/template/main/php/";
	xx=document.createElement("div");
	xx.className="ajaxInfoContent";
	objContainer.appendChild(xx);
	if(typeof(interval1)!="undefined") window.clearInterval(interval1);
	 if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	 {
			
		var date = new Date();
		var timestamp = date.getTime();

		xmlHttp.open("GET", folderpath + "showContentAjax_xml.php?newsid=" + newsid + "&time=" + timestamp, true);
		// define the method to handle server responses
		xmlHttp.onreadystatechange = function()
		{
			handleServerResponse(newsid, xx);
		}
		
		// make the server request
		xmlHttp.send(null);
	 }	
}



// executed automatically when a message is received from the server
function handleServerResponse(uid, objContainer) 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4)
  {
	 // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
		
	   // extract the XML retrieved from the server
      var xmlResponse = xmlHttp.responseXML;
	  
	  if(!xmlResponse || !xmlResponse.documentElement)
	  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);  
	  }
	  
	  var rootNodeName=xmlResponse.documentElement.nodeName;
	  
	  if(rootNodeName == "parserror")
	  {
		  throw("Invalid XML structure");
	  }
	  
	  xmlRoot=xmlResponse.documentElement;
	  
	 
	 
      // obtain the document element (the root element) of the XML structure
     
	 	  
	  // get the text message, which is in the first child of
      // the the document element
	 	  
	   			
		var titleArray = xmlRoot.getElementsByTagName("obj1");
		var helloMessage=titleArray.item(0).firstChild.data;
		objContainer.innerHTML = helloMessage;	
		
		var scroller = null;
		var scrollbar = null;
		scroller = new jsScroller(document.getElementById("content-bodyA"), 444, 292);
		scrollbar = new jsScrollbar (document.getElementById("Scrollbar-Container_A"), scroller, true); 
		
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}



function changeOpac(o1, step) 
{
	if(typeof(opacity)=='undefined')
	{
		opacity=0;
	}	
	if(typeof(topDD)=='undefined')
	{
		topDD=o1.offsetTop;
	}
		opacity+=step;
		//topDD = ((o1.offsetTop)/1.5);		
	
	var object = o1.style;
	//object.top = topDD + "px";
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	if(opacity>=100)
	{
		//object.top=0 + "px";
		opacity=100;
		clearInterval(o1.interval1);
	}
	if(opacity<=0)
	{
		//object.top=0 + "px";
		opacity=0;
		clearInterval(o1.interval1);
		document.getElementById('main').removeChild(o1);
	}
	
}


function confirmTermsAndConditions(obj, inputObj)
{
	if(obj.checked==true)
	{
		document.getElementById(inputObj).value=1;
	}
	else if(obj.checked==false)
	{
		document.getElementById(inputObj).value=0;
	}
}


function showInfo(obj, UID, inputObj)
{
	if(typeof(obj.isActive)=="undefined")
	{
		obj.isActive=0;
	}
	if(obj.isActive==1)
	{
		opacity=100;
		x=document.getElementById('divShowInfoHere');
			clearInterval(x.interval1);
			x.interval1=setInterval(function() {changeOpac(x,-10)}, 1);
			obj.isActive=0;
	}	
	else if(obj.isActive==0)
	{
	if(!document.getElementById("divShowInfoHere"))
	{
		opacity=null;
		var c=document.createElement("p");
		c.className="closeInfoDiv";
		c.appendChild(document.createTextNode("x"));
		var x=document.createElement("div");
		x.id="divShowInfoHere";		
		x.appendChild(c);
		document.getElementById('main').appendChild(x);	
		clearInterval(x.interval1);
		x.interval1=setInterval(function() {changeOpac(x,10)}, 1);
		obj.isActive=1;
		process(x, UID);
		c.onmousedown=function()
		{
			opacity=100;
			clearInterval(x.interval1);
			x.interval1=setInterval(function() {changeOpac(x,-10)}, 1);	
			obj.isActive=0;
			document.getElementById(inputObj).value=1;
		}
	}
	}
	
}

function showInfo_1(obj, UID, inputObj)
{
	if(typeof(obj.isActive)=="undefined")
	{
		obj.isActive=0;
	}
	if(obj.isActive==1)
	{
		opacity=100;
		x=document.getElementById('divShowInfoHere_1');
			clearInterval(x.interval1);
			x.interval1=setInterval(function() {changeOpac(x,-10)}, 1);
			obj.isActive=0;
	}	
	else if(obj.isActive==0)
	{
	if(!document.getElementById("divShowInfoHere_1"))
	{
		opacity=null;
		var c=document.createElement("p");
		c.className="closeInfoDiv";
		c.appendChild(document.createTextNode("x"));
		var x=document.createElement("div");
		x.id="divShowInfoHere_1";		
		x.appendChild(c);
		document.getElementById('main').appendChild(x);	
		clearInterval(x.interval1);
		x.interval1=setInterval(function() {changeOpac(x,10)}, 1);
		obj.isActive=1;
		process(x, UID);
		c.onmousedown=function()
		{
			opacity=100;
			clearInterval(x.interval1);
			x.interval1=setInterval(function() {changeOpac(x,-10)}, 1);	
			obj.isActive=0;
			document.getElementById(inputObj).value=1;
		}
	}
	}
	
}

function unableToShop()
{
	alert("Denne bog er ikke på lager.");
}