function switchForm(element, on)
{
	if(!on){
		document.getElementById(element).style.display="inline";
	}
	else{
		document.getElementById(element).style.display="none";
	}
}

function showForm(element)
{
	document.getElementById(element).style.display="inline";
}

function hideForm(element)
{
	document.getElementById(element).style.display="none";
}

function calcPriceShort(price, priceAdditional){
	if(document.getElementById('c2').checked){ 
		price += priceAdditional; 
		document.getElementById('price').childNodes[0].data = Math.round(price*100)/100;	
	}
	
}

function switchArticleData(showElement, hide){
	document.getElementById(showElement).style.display="inline";
	for(var i = 0; i < hide.length; i++){
		var tab = hide[i];
		document.getElementById(tab).style.display="none";
	}
	return false;
}

function checkDate(){
	var start = ""+document.getElementById("month_start").options[(document.getElementById("month_start").selectedIndex)].value  +""+ document.getElementById("day_start").options[(document.getElementById("day_start").selectedIndex)].value +""+ document.getElementById("time_start").options[(document.getElementById("time_start").selectedIndex)].value;
	var end = ""+document.getElementById("month_end").options[(document.getElementById("month_end").selectedIndex)].value  +""+ document.getElementById("day_end").options[(document.getElementById("day_end").selectedIndex)].value +""+ document.getElementById("time_end").options[(document.getElementById("time_end").selectedIndex)].value;
	if(start < end){
		return true;
	}
	return false;
}

function checkForm(form, invDate){
	var checked = true;
	if(!checkDate()){
		//alert("no");
		document.getElementById("wrongDate").innerHTML = '<br/>'+invDate;
		checked = false;
	}
	/* if(form.register == 1){
		if(!form.username){
			document.usernameError.innerHTML = '<br/>'+invUsername;
			checked = false;
		}
	}*/
	
	if(checked){
		form.submit();
	}
}

function calcPrice(host, aid, msg, curr){
    try{
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }catch(E){
      xmlhttp = false;
    }
    if(!xmlhttp){
      xmlhttp = new XMLHttpRequest();
    }
    var amount = document.getElementById('amount').value;
    var day_start = document.getElementById('day_start').value;
    var month_start = document.getElementById('month_start').value;
    var time_start = document.getElementById('time_start').value;
    var day_end = document.getElementById('day_end').value;
    var month_end = document.getElementById('month_end').value;
    var time_end = document.getElementById('time_end').value;
        					
    xmlhttp.open("GET", host + "/index.php?a=calcPrice"
    					+ "&day_start=" + day_start
    					+ "&month_start=" + month_start
    					+ "&time_start=" + time_start
    					+ "&day_end=" + day_end
    					+ "&month_end=" + month_end
    					+ "&time_end=" + time_end
    					+ "&amount=" + amount
    					+ "&aid=" + aid
    					,true);
    xmlhttp.onreadystatechange = function(){
      if(xmlhttp.readyState == 4){
      	if(document.getElementById('wrongAmount')){
	    	document.getElementById('wrongAmount').innerHTML = msg +" "+ xmlhttp.responseText +" "+ curr;
	  	}else if(document.getElementById('priceForm')){
	    	document.getElementById('priceForm').value = xmlhttp.responseText;
			document.getElementById('price').style.display='none';
	    	document.getElementById('priceDiv').style.display = 'inline';
	  	}
      }
    }
    xmlhttp.send(null);
}

function modifyRequest(element){
	document.getElementById(element).style.display='none';
	document.getElementById(element+'Form').style.display='inline';
	document.getElementById('cancelDemand').style.display='none';
	document.getElementById('confirmReturn').style.display='none';
	if(element == 'price'){
    	document.getElementById('priceDiv').style.display = 'inline';
    }
}


function print(page){
	printWindow = window.open(page,'printView','dependent=yes, width=600,height=690,location=no,menubar=yes,resizable=yes,scrollbars=yes, status=yes');
}

function changeBG(on, off) {
    document.getElementById(on).className = 'border_bg2';
    document.getElementById(off).className = '';
    document.getElementById(on).style.backgroundImage = 'url(./img/navi_bg1.gif)';
    document.getElementById(off).style.backgroundImage = 'none';
}

function switchArtBG(on, hide){
    document.getElementById(on).className = 'border_bg2';
    document.getElementById(on).style.backgroundImage = 'url(./img/navi_bg1.gif)';
	for(var i = 0; i < hide.length; i++){
		var tab = hide[i];
	    document.getElementById(tab).className = 'main_grey';
	    document.getElementById(tab).style.backgroundImage = 'none';
	}
	return false;
}



function request(zipcode){
  
    try{
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }catch(E){
      xmlhttp = false;
    }
    if(!xmlhttp){
      xmlhttp = new XMLHttpRequest();
    }
    xmlhttp.open("GET", "ajax.php?zip="+zipcode ,true, '', '');
    xmlhttp.onreadystatechange = function(){
      if(xmlhttp.readyState == 4){
        result = xmlhttp.responseText;
        var location = result.split("|");
        document.getElementById('cityInp').value = location[0];
        document.getElementById('cityText').innerHTML = location[0];
       
        document.getElementById('stateInp').value = location[1];
        document.getElementById('stateText').innerHTML = location[1];
        
        var country = '';
        if(location[2] == 'us'){
        	var country = 'USA';
        }else if(location[2] == 'ca'){
        	var country = 'Canada';
        }
        
        document.getElementById('countryInp').value = location[2];
        document.getElementById('countryText').value = country;
      }
    }
    xmlhttp.send(null);
  
}

//var Ergebnis = regUS.match(derSatz);

function checkSearch(){

	var regUS = /^[0-9][0-9][0-9][0-9][0-9]$/;
	var regCA = /^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]$/;
	if(
		(document.getElementById('zipIn').value && !document.getElementById('searchIn').value)
		|| document.getElementById('searchIn').value.length < 3 
		|| (document.getElementById('zipIn').value.length > 0 
			&& (
				!document.getElementById('zipIn').value.match(regUS)
				&& 
				!document.getElementById('zipIn').value.match(regCA)
				)
			)
	){
		if((document.getElementById('zipIn').value && !document.getElementById('searchIn').value)
			|| document.getElementById('searchIn').value.length < 3){
			document.getElementById('searchIn').style.border='solid red 1px';
		    document.getElementById('searchIn').style.backgroundColor='#FFDCDC';
		}else{
			document.getElementById('searchIn').style.border='solid black 1px';
		    document.getElementById('searchIn').style.backgroundColor='#ffffff';
		}
		
	    if(document.getElementById('zipIn').value.length > 0 
			&& (
				!document.getElementById('zipIn').value.match(regUS)
				&& 
				!document.getElementById('zipIn').value.match(regCA)
				)
			){
				document.getElementById('zipIn').style.border='solid red 1px';
	    		document.getElementById('zipIn').style.backgroundColor='#FFDCDC';
		}else{
			document.getElementById('zipIn').style.border='solid black 1px';
		    document.getElementById('zipIn').style.backgroundColor='#ffffff';
		}
	}else{
		document.getElementById('searchForm').submit();
	}
}
