
function getInternetExplorerVersion()
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}


function stringFilter (input) {
    s = input.value;
    filteredValues = " :-$#.+/()=\\~*";     // Characters stripped out
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
    var c = s.charAt(i);
    if (filteredValues.indexOf(c) == -1) returnString += c;
    }
    input.value = returnString;
}


function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function setupForm() {
    if (userProfile) getValues(userProfile);
}

function fillDummy()
{
document.offerform.cust_name.value="Példa János";
document.offerform.cust_name2.value="Minta Kft.";
document.offerform.cust_mtel.value="363012345678";
document.offerform.cust_tel.value="3611234567";
document.offerform.cust_email.value="mrpelda@gmail.com";
document.offerform.cust_email2.value="mrpelda@gmail.com";
document.offerform.cust_from_country.selectedIndex=0;
document.offerform.cust_from_name.value="Példa József";
document.offerform.cust_from_mtel.value="36209998887";
document.offerform.cust_from_tel.value="3662121212";
document.offerform.cust_from_city.value="Szeged";
document.offerform.cust_from_house.value="22";
document.offerform.cust_from_street.value="Rigó u.";
document.offerform.cust_from_postcode.value="6702";
document.offerform.cust_to_country.selectedIndex=1;
document.offerform.cust_to_name.value="Mr. John Example";
document.offerform.cust_to_mtel.value="44789012345";
document.offerform.cust_to_tel.value="44201333333";
document.offerform.cust_to_city.value="London";
document.offerform.cust_to_house.value="12";
document.offerform.cust_to_street.value="Dummy Lane";
document.offerform.cust_to_postcode.value="ABC 123";
document.offerform.cust_pay_method.selectedIndex=1;
document.offerform.cust_pay_currency.selectedIndex=2;
document.offerform.cust_comment.value="Megjegyzés, csak hogy írjak valamit...";
document.offerform.cust_from_extra_lading.checked=true;
document.offerform.cust_from_extra_lading_lift.checked=true;
document.offerform.cust_from_extra_lading_unreach.checked=true;
document.offerform.cust_from_extra_lading_floor.selectedIndex=10;
document.offerform.cust_from_extra_lading_descr.value="Nagyon fennt van az emeleten, meg nehéz is.";
document.getElementById('cust_from_extra_lading_div').style.display="inline";
document.offerform.num_colis.selectedIndex=2;
document.offerform.fset_coli_1_pcs.value="1";
document.offerform.fset_coli_1_size_l.value="1";
document.offerform.fset_coli_1_size_w.value="1";
document.offerform.fset_coli_1_size_h.value="1";
document.offerform.fset_coli_1_weight.value="1";
document.offerform.fset_coli_1_packaging.selectedIndex=1;
document.offerform.fset_coli_1_comment.value="11111111111";
document.offerform.fset_coli_2_pcs.value="2";
document.offerform.fset_coli_2_size_l.value="2";
document.offerform.fset_coli_2_size_w.value="2";
document.offerform.fset_coli_2_size_h.value="2";
document.offerform.fset_coli_2_weight.value="2";
document.offerform.fset_coli_2_packaging.selectedIndex=2;
document.offerform.fset_coli_2_comment.value="222222222222";
document.offerform.fset_coli_3_pcs.value="3";
document.offerform.fset_coli_3_size_l.value="3";
document.offerform.fset_coli_3_size_w.value="3";
document.offerform.fset_coli_3_size_h.value="3";
document.offerform.fset_coli_3_weight.value="3";
document.offerform.fset_coli_3_packaging.selectedIndex=3;
document.offerform.fset_coli_3_comment.value="333333333333";

document.offerform.route_dates.selectedIndex=2;
document.offerform.accept_terms.checked=true;

}


function getValues(string) {
    getValue(string,"cust_name", document.offerform.cust_name, "text");
    getValue(string,"cust_name2", document.offerform.cust_name2,  "text");    
    getValue(string,"cust_mtel", document.offerform.cust_mtel,  "text");    
    getValue(string,"cust_tel", document.offerform.cust_tel,  "text");    
    getValue(string,"cust_email", document.offerform.cust_email,  "text");    
    getValue(string,"cust_email2", document.offerform.cust_email2,  "text");    
    getValue(string,"cust_from_other_country", document.offerform.cust_from_other_country,  "text");    
    getValue(string,"cust_from_country", document.offerform.cust_from_country,  "select");    
    getValue(string,"cust_from_name", document.offerform.cust_from_name,  "text");    
    getValue(string,"cust_from_mtel", document.offerform.cust_from_mtel,  "text");    
    getValue(string,"cust_from_tel", document.offerform.cust_from_tel,  "text");    
    getValue(string,"cust_from_city", document.offerform.cust_from_city,  "text");    
    getValue(string,"cust_from_house", document.offerform.cust_from_house,  "text");    
    getValue(string,"cust_from_street", document.offerform.cust_from_street,  "text");    
    getValue(string,"cust_from_postcode", document.offerform.cust_from_postcode,  "text");    
    getValue(string,"cust_to_other_country", document.offerform.cust_to_other_country,  "text");    
    getValue(string,"cust_to_name", document.offerform.cust_to_name,  "text");    
    getValue(string,"cust_to_mtel", document.offerform.cust_to_mtel,  "text");    
    getValue(string,"cust_to_tel", document.offerform.cust_to_tel,  "text");    
    getValue(string,"cust_to_city", document.offerform.cust_to_city,  "text");    
    getValue(string,"cust_to_country", document.offerform.cust_from_country,  "select");    
    getValue(string,"cust_to_house", document.offerform.cust_to_house,  "text");    
    getValue(string,"cust_to_street", document.offerform.cust_to_street,  "text");    
    getValue(string,"cust_to_postcode", document.offerform.cust_to_postcode,  "text");    
    getValue(string,"cust_pay_method", document.offerform.cust_pay_method,  "select");    
    getValue(string,"cust_pay_currency", document.offerform.cust_pay_currency,  "select");    
}

function setValues() {
 var a = "";
    a=a+setValue("cust_name", document.offerform.cust_name, "text");a=a+"&";
    a=a+setValue("cust_name2", document.offerform.cust_name2,  "text");a=a+"&";    
    a=a+setValue("cust_mtel", document.offerform.cust_mtel,  "text");a=a+"&";    
    a=a+setValue("cust_tel", document.offerform.cust_tel,  "text");a=a+"&";    
    a=a+setValue("cust_email", document.offerform.cust_email,  "text");a=a+"&";    
    a=a+setValue("cust_email2", document.offerform.cust_email2,  "text");a=a+"&";    
    a=a+setValue("cust_from_other_country", document.offerform.cust_from_other_country,  "text");a=a+"&";    
    a=a+setValue("cust_from_country", document.offerform.cust_from_country,  "select");a=a+"&";    
    a=a+setValue("cust_from_name", document.offerform.cust_from_name,  "text");a=a+"&";    
    a=a+setValue("cust_from_mtel", document.offerform.cust_from_mtel,  "text");a=a+"&";    
    a=a+setValue("cust_from_tel", document.offerform.cust_from_tel,  "text");a=a+"&";    
    a=a+setValue("cust_from_city", document.offerform.cust_from_city,  "text");a=a+"&";    
    a=a+setValue("cust_from_house", document.offerform.cust_from_house,  "text");a=a+"&";    
    a=a+setValue("cust_from_street", document.offerform.cust_from_street,  "text");a=a+"&";    
    a=a+setValue("cust_from_postcode", document.offerform.cust_from_postcode,  "text");a=a+"&";
    a=a+setValue("cust_to_other_country", document.offerform.cust_to_other_country,  "text");a=a+"&";    
    a=a+setValue("cust_to_name", document.offerform.cust_to_name,  "text");a=a+"&";    
    a=a+setValue("cust_to_mtel", document.offerform.cust_to_mtel,  "text");a=a+"&";    
    a=a+setValue("cust_to_tel", document.offerform.cust_to_tel,  "text");a=a+"&";    
    a=a+setValue("cust_to_city", document.offerform.cust_to_city,  "text");a=a+"&";    
    a=a+setValue("cust_to_country", document.offerform.cust_from_country,  "select");a=a+"&";    
    a=a+setValue("cust_to_house", document.offerform.cust_to_house,  "text");a=a+"&";    
    a=a+setValue("cust_to_street", document.offerform.cust_to_street,  "text");a=a+"&";    
    a=a+setValue("cust_to_postcode", document.offerform.cust_to_postcode,  "text");a=a+"&";    
    a=a+setValue("cust_pay_method", document.offerform.cust_pay_method,  "select");a=a+"&";    
    a=a+setValue("cust_pay_currency", document.offerform.cust_pay_currency,  "select");a=a+"&";    
    return a;
}

function replace(text,by) {
// Replaces text with by in string
    var i = string.indexOf(text);
    var newstr = '';
    if ((!i) || (i == -1)) return string;
    newstr += string.substring(0,i) + by;

    if (i+text.length < string.length)
        newstr += replace(string.substring(i+text.length,string.length),text,by);
    
    return newstr;
}

function onCheck(string) { if (string == "on") return true; return false; }

function getValue(string,elementName,object,elementType) {
// gets value of elementName from string and populates object of elementType

    var startPos = string.indexOf(elementName + "=")
    
    if (startPos > -1) {
        startPos = startPos + elementName.length + 1;
        var endPos = string.indexOf("&",startPos);
        if (endPos == -1) endPos = string.length;

        var elementValue = unescape(string.substring(startPos,endPos));
        
        if (elementType == "text")     object.value = elementValue;
        if (elementType == "password") object.value = elementValue;
        if (elementType == "select")   object.selectedIndex = elementValue;
        if (elementType == "checkbox") object.checked = onCheck(elementValue);
        if (elementType == "radio")    object[elementValue].checked = true;
    }
}

function setValue(elementName,object,elementType) {
// sets value of elementName from string and populates object of elementType

    var retval = "";
   
    if (elementType == "text")     elementValue = object.value;
    if (elementType == "password") elementValue = object.value;
    if (elementType == "select")   elementValue = object.selectedIndex;
    if (elementType == "checkbox") elementValue = object.checked;
    if (elementType == "radio")    elementValue = object.checked;

    retval = elementName+"="+elementValue;
    return retval;
}

function Save_Profile () {
var today = new Date();
var expires = new Date(today.getTime() + (56 * 864000000));

var searchString = setValues();
if (searchString.length > 0) Set_Cookie("LouisTransUserProfile3",searchString,expires);

}

function clearProfile () {
var today = new Date();
var expires = new Date(today.getTime() - (56 * 864000000));
Set_Cookie("LouisTransUserProfile3","",expires);
window.location.href=window.location.href;
}

function fp_body_onload(nyelv) {
	var ver = getInternetExplorerVersion();
	if (ver > -1) {
	if (ver < 7.0) {
		document.location="/badbrowser-"+nyelv+".html";
	}
	}
}

