var blinkState = true;
var intervalId = setInterval("blink()", 1000)
function blink(){
blinkState = !blinkState
if (blinkState){
        document.getElementById("blinker").style.color = "#969090"
        }else{
        document.getElementById("blinker").style.color = "#DA0C24"
        }
}



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//var newString = Url.decode(string);

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


function fillForms() {

var formList = new Array();

     if(window.location.search != "") {
     QUERYSTRING = window.location.search
     QUERYSTRING = QUERYSTRING.replace(/\?/,"");

     //trenne den querystring nach jedem & in teilstringe auf
     var teilstrings = QUERYSTRING.split("&");

     //durchlaufe jeden dieser teilstrings
     for (i=0;i<teilstrings.length;i++) {

         //trenne den teilsring in weiteren teilstring auf,
         //trenne also formListnamen vom inhalt
         vararr = teilstrings[i].split("=");
         formList[vararr[0]] = vararr[1];
      }

   }



        var formElementsCol = document.forms[0].elements
        for(thisElement=0;formElementsCol[thisElement];thisElement++)
        {
                var currentElement = formElementsCol[thisElement];

                var thisValue = formList["an_"+ currentElement.name];
                                if(currentElement.value.length){
                                continue;
                                }


                if (thisValue != undefined)
                {

                //thisValue = unescape(thisValue);
				thisValue  = Url.decode(thisValue);
				
                                switch(formElementsCol[thisElement].type)
                                {
                        case "submit": break;
                        case "select-one":      currentElement.value            = thisValue ;break;
                        case "radio":           currentElement.checked          = thisValue ;break;
                        case "text":            currentElement.value            = thisValue ; break;
                        case "checkbox":        currentElement.checked          = thisValue ; break;

				 		case "hidden":

				        var InfoText = thisValue;
						while(InfoText.indexOf('+') != -1) {
						   InfoText = InfoText.replace('+', ' ');
						}
				  		document.getElementById("pauschalentext").innerHTML = '<span Style="line-height:35px;">' + 'Unverbindliche Anfrage für das Angebot ' +'"' + InfoText + '"' + '</span>';

						currentElement.value            = InfoText;

				   		break;


                }
                }
       }
};




function resetFormList(){
        formList = [];
        var formElementsCol = document.forms[0].elements
        for(thisElement=0;formElementsCol[thisElement];thisElement++)
        {
                var currentElement = formElementsCol[thisElement];
                thisValue = "";
                switch(currentElement.type)
                        {
                        case "submit": break;
                        case "select-one":      thisValue = currentElement.value                ; break;
                        case "radio":           thisValue = ""                                  ; break;
                        case "text":            thisValue = currentElement.value                ; break;
						case "hidden":          thisValue = currentElement.value                ; break;
                        case "checkbox":        thisValue = currentElement.checked              ; break;
                        }
                if(thisValue!="")formList[currentElement.name] = thisValue ;

        }
                return true;
};



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function checkErrors() {
	
	
        var errorCheck1 = showErrors(document.getElementsByTagName("select"));
        var errorCheck2 = showErrors(document.getElementsByTagName("input"));



        if( errorCheck1 || errorCheck2){
        return false;
        }else{
        return true;
        }


        }



function showErrors(tagList){
	
        labelObject = new Object();

                var errors = false;
                // die var inputList (also die definition welche Felder Pflichtfelder sind ) werden übers Formular befüllt

                for(i=0;i<tagList.length;i++){
                        for(var j=0; inputList[j]; j++){

                              if(inputList[j] == "form_EMAIL" && tagList[i].name == "form_EMAIL"){
                                        if(checkEmail(tagList[i].value)){
                                                document.getElementById('formularerror').style.display='block';
                                                labelObject[tagList[i].name] = true;
                                                errors = true;
                                                }
                                        }


                                if( tagList[i].name == inputList[j] && tagList[i].value.length < 1 ){
                                document.getElementById('formularerror').style.display='block';
                                labelObject[tagList[i].name] = true;
                                errors = true;
                                }

                                if(document.getElementById('form_SALUTATION').value == 0){
                                document.getElementById('formularerror').style.display='block';
                                labelObject['form_SALUTATION'] = true;
                                errors = true;
                                        }



                        }

                }

                tagList = document.getElementsByTagName("label");

				var externalLabelList = ["form_P15", "form_P16", "form_P17"]

                for(i=0;i<tagList.length;i++){
                        tagList[i].style.color = "#000"

                        if(labelObject[tagList[i].htmlFor] == true){tagList[i].style.color = "#DA0C24"};


						if(tagList[i].htmlFor == "form_Anreise" ){

							for(var j=0; externalLabelList[j];j++){

								if(labelObject[externalLabelList[j]] == true){tagList[i].style.color = "#DA0C24"};
							}
						}


                }

						if(errors){FullIframeResize()};
                        return errors;


        }
//########################################################################
//   VALIDATE EMAIL
//########################################################################

function checkEmail (strng) {
        var error=false;
        if (strng == "") {
           //error = "You didn't enter an email address.\n";
           error = true;
        }

                var emailFilter=/^.+@.+\..{2,3}$/;
                if (!(emailFilter.test(strng))) {
                   //error = "Please enter a valid email address.\n";
                   error = true;
                }
                else {
        //test email for illegal characters
                   var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
                         if (strng.match(illegalChars)) {
                          //error = "The email address contains illegal characters.\n";
                          error = true;
                   }
                }
        return error;
}


//########################################################################
//   VALIDATE EMAIL
//########################################################################

function FullIframeResize() {
						var iframe = document.getElementById( 'inneriframe' );
						var height = Math.max( document.body.offsetHeight, document.body.scrollHeight );
						iframe.src = 'http://www.hochschober.at/basic/init/resize_extern.html?height='+height;
					  }
