// JavaScript Document

var xmlDoc

function GetXmlHttpObject(handler){ 
    var objXmlHttp=null
    if (navigator.userAgent.indexOf("Opera")>=0){
        alert("This example doesn't work in Opera") 
        return 
    }
    if (navigator.userAgent.indexOf("MSIE")>=0){ 
        var strName="Msxml2.XMLHTTP"
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
            strName="Microsoft.XMLHTTP"
        } 
        try{ 
            objXmlHttp=new ActiveXObject(strName)
            objXmlHttp.onreadystatechange=handler 
            return objXmlHttp
        } 
        catch(e){ 
            alert("Error. Scripting for ActiveX might be disabled") 
        return 
        } 
    } 
    if (navigator.userAgent.indexOf("Mozilla")>=0){
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler 
        return objXmlHttp
    }
} 

function getPhotOverPhotoContest(PhotoId,cmd){
    if(window.ActiveXObject){
      xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false
      //window.open("xml/getNextPreviousFotoOfContest.xml.asp?cmd="+cmd+"&id="+PhotoId)
      xmlDoc.load("xml/getNextPreviousFotoOfContest.xml.asp?cmd="+cmd+"&id="+PhotoId)
      setNewContestImage()
    }
    else if(document.implementation && document.implementation.createDocument){		
		  xmlDoc= document.implementation.createDocument("","",null);
		  xmlDoc.load("xml/getNextPreviousFotoOfContest.xml.asp?cmd="+cmd+"&id="+PhotoId);
		  xmlDoc.onload=setNewContestImage      
    }    
}
function setNewContestImage(){
  document.getElementById('ContestThumb').src = xmlDoc.getElementsByTagName("thumb")[0].firstChild.nodeValue    
  document.getElementById('ContestBigHolder').value = xmlDoc.getElementsByTagName("big")[0].firstChild.nodeValue  
  document.getElementById('ContestPhotoId').value = xmlDoc.getElementsByTagName("id")[0].firstChild.nodeValue
}
function checkUserExists(Username){
  if(window.ActiveXObject){
      xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false      
      xmlDoc.load("xml/checkUser.xml.asp?username="+Username)
      ReadUserExistsResult()
    }
    else if(document.implementation && document.implementation.createDocument){		
		  xmlDoc= document.implementation.createDocument("","",null);
		  xmlDoc.load("xml/checkUser.xml.asp?username="+Username)
		  xmlDoc.onload=ReadUserExistsResult      
    }
}

function ReadUserExistsResult(){
  if(xmlDoc.getElementsByTagName("result")[0].firstChild.nodeValue != 'OK'){
    document.getElementById('UserResult').innerHTML = xmlDoc.getElementsByTagName("result")[0].firstChild.nodeValue
  }
  else{
    document.getElementById('UserResult').innerHTML = ''
  }
}

function checkModelExists(BrandId,ModelName){
  if(window.ActiveXObject){
      xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false      
      xmlDoc.load("xml/checkModel.xml.asp?BrandId="+BrandId+"&model="+ModelName)
      ReadModelExistsResult()
    }
    else if(document.implementation && document.implementation.createDocument){		
		  xmlDoc= document.implementation.createDocument("","",null);
		  xmlDoc.load("xml/checkModel.xml.asp?BrandId="+BrandId+"&model="+ModelName)
		  xmlDoc.onload=ReadModelExistsResult      
    }
}

function ReadModelExistsResult(){
  if(xmlDoc.getElementsByTagName("result")[0].firstChild.nodeValue != 'OK'){
    document.getElementById('ModelResult').innerHTML = xmlDoc.getElementsByTagName("result")[0].firstChild.nodeValue
  }
  else{
    document.getElementById('ModelResult').innerHTML = ''
  }
}

var xmlModels
function getModels(BrandId,obj2,selModel2){
//function getModels(BrandId,obj,selModel){
// 	if (window.XMLHttpRequest) {
// 	  xmlDoc=GetXmlHttpObject(fillModelListIE(document.getElementById(obj))) 
//    xmlDoc.open("GET", "xml/getFietsenBaseModels.xml.asp?BrandId="+BrandId , true) 

//		//xmlDoc=document.implementation.createDocument("","", null);
//		//xmlDoc.load("xml/getFietsenBaseModels.xml.asp?BrandId="+BrandId)
//		//xmlDoc.onload = fillModelListMOZ(document.getElementById(obj))
//	}
//	// code for IE
//	else {
//		if (window.ActiveXObject) {
//			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
//			xmlDoc.async=false;
//			xmlDoc.load("xml/getFietsenBaseModels.xml.asp?BrandId="+BrandId);
//			fillModelListIE(document.getElementById(obj),selModel)
//		}
	//}
//	if (window.ActiveXObject) {
      obj = document.getElementById(obj2)
			selModel = selModel2	
			xmlModels = GetXmlHttpObject(fillModelListIE)
			var url = "xml/getFietsenBaseModels.xml.asp?BrandId="+BrandId
			//window.open(url)
			xmlModels.open("GET",url,true)	
			xmlModels.send(null)		
}

var obj,selModel
function fillModelListIE(){
  var content = xmlModels.responseXML
  var Recs = content.getElementsByTagName("model")
  obj.options.length = 1
  for(var i=0;i<Recs.length;i++){     
    if (selModel ==  Recs[i].getAttribute("id")){
      obj.options[i+1] = new Option(Recs[i].firstChild.nodeValue,Recs[i].getAttribute("id"))
      obj.options[i+1].selected = true
    }
    else{
      obj.options[i+1] = new Option(Recs[i].firstChild.nodeValue,Recs[i].getAttribute("id"))
    }
  } 
}

var xmlHttp
var subMenuState

function GetXmlHttpObject(handler) { 
	var objXmlHttp=null
	if (navigator.userAgent.indexOf("MSIE")>=0) { 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
			strName="Microsoft.XMLHTTP"
		} 
		try { 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} 
		catch(e){ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0){
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler
		return objXmlHttp
	}
} 

function GetLatestWeather() {	
	var url="feeds/weerFeed.asp"
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		setWeather()
	} 
} 

function setWeather(){
	var obj = document.getElementById('WeatherContainer')
	obj.innerHTML = xmlHttp.responseText;
}

var BidContainer
function GetBids(id){
  var url="feeds/getBids.asp?id="+id
  xmlHttp=GetXmlHttpObject(stateChangeBids)
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function stateChangeBids(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
    setBids()
  }
}

function setBids(){
  var obj= BidContainer
  obj.innerHTML = xmlHttp.responseText;
}

var shopXmlHttp
function addToShop(id) {
	var url="xml/addToShop.xml.asp?id=" + id + "&specs=" + document.getElementById('specs').value
	shopXmlHttp=GetXmlHttpObject(updateShoppingcart)
	shopXmlHttp.open("GET", url , true)
	shopXmlHttp.send(null)
}
function updateShoppingcart() {
	if (shopXmlHttp.readyState==4 || shopXmlHttp.readyState=="complete") { 
		document.getElementById('block_shoppingcart').innerHTML = shopXmlHttp.responseText
		document.getElementById('btn_addtoshop').style.display='block'
		document.getElementById('btn_addtoshop').style.top=(screen.availHeight/2) - 50
		document.getElementById('btn_addtoshop').style.left=(screen.availWidth/2) - 100
	} 
	setTimeout("document.getElementById('btn_addtoshop').style.display='none'",5000);
}

var msgXmlHttp
function SendMessage(strobj,userId){
  var obj = document.getElementById(strobj)
  if (obj != undefined){
    if (obj.Value != '') {
      var url = "xml/sendMessage.xml.asp?userId=" + userId + "&msg=" + obj.value.replace(/\n/g,'<br>')
      //window.open(url)
      msgXmlHttp = GetXmlHttpObject(MessageSend)
      msgXmlHttp.open("GET", url, true)
      msgXmlHttp.send(null)
    }
    else{
      alert('U heeft geen tekst ingevuld.')
    }
  }
}
var oldText
function MessageSend(){
  var oldText = document.getElementById('btn_addtoshop').innerHTML
  if (msgXmlHttp.readyState==4 || msgXmlHttp.readyState=="complete"){
    document.getElementById('btn_addtoshop').innerHTML=msgXmlHttp.responseText
		document.getElementById('btn_addtoshop').style.display='block'
		document.getElementById('btn_addtoshop').style.top=(screen.availHeight/2) - 50
		document.getElementById('btn_addtoshop').style.left=(screen.availWidth/2) - 100
	} 
	document.getElementById('Message').value =''
	document.getElementById('blockMessage').style.display = 'none';
	setTimeout("document.getElementById('btn_addtoshop').style.display='none';document.getElementById('btn_addtoshop').innerHTML=oldText",5000);	
}