﻿

var REQUIRED_FLASH_VERSION = 8;

/*
Global PopUp functions
*/

function openRegistration() {
    top.document.location.href = "http://www.camel.ch/app/pub/register/registration.jsp";
}


function openMotoGP() {
    var sUrl = "/app/prv/event/moto_gp/index.jsp";
    var w = window.open(sUrl, "motoGP", "width=571, height=610, scrollbars=0");
    assertPop(w);
}

function openMotoGPWinners() {
    var sUrl = "/app/prv/event/moto_gp/winner.jsp";
    var w = window.open(sUrl, "motoGP", "width=500, height=610, scrollbars=0");
    assertPop(w);
}

function openCnfFreePack() {
    var sUrl = "/app/prv/games/cnf/freepack/index.jsp";
    var w = window.open(sUrl, "cnfFreePack", "width=498, height=686, scrollbars=0");
    assertPop(w);
}

function openCnfMainDrawing() {
    var sUrl = "/app/prv/games/cnf/maindrawing/index.jsp";
    var w = window.open(sUrl, "cnfMainDrawing", "width=498, height=686, scrollbars=0");
    assertPop(w);
}

function openCnfBiWeekly() {
    var sUrl = "/app/prv/games/cnf/biweekly/index.jsp";
    var w = window.open(sUrl, "cnfBiWeekly", "width=498, height=686, scrollbars=0");
    assertPop(w);
}

function openVoting() {
    var sVotingUrl = "/app/prv/voting/index.jsp";
    var w = window.open(sVotingUrl, "popupVoting", "width=800, height=500, scrollbars=0");
    assertPop(w);
}

function openFAQ(sCategory) {
    var sFAQUrl = rootUrl + "_AREA_/Faq.aspx" + ((sCategory) ? "?category=" + sCategory : "");
    sFAQUrl = sFAQUrl.replace(/_AREA_/, (location.href.indexOf("prv") != -1) ? "prv" : "pub");
    var w = window.open(sFAQUrl, "popupFaq", "width=500, height=550, scrollbars=1");
    assertPop(w);
}

function openContacts() {
    var sContactUrl = rootUrl + "pub/Contact.aspx";
    var w = window.open(sContactUrl, "popupContact", "width=500, height=550, scrollbars=0");
    assertPop(w);
}

function openTermsOfUse(sCategory) {
    var sTermsOfUseUrl = rootUrl + "_AREA_/TermsOfUse.aspx" + ((sCategory) ? "?category=" + sCategory : "");
    sTermsOfUseUrl = sTermsOfUseUrl.replace(/_AREA_/, (location.href.indexOf("prv") != -1) ? "prv" : "pub");
    var w = window.open(sTermsOfUseUrl, "popupTermsOfUse", "width=500, height=600, scrollbars=1");
    assertPop(w);
}

function openPrivacyPolice() {
    var sPrivacyPoliceUrl = rootUrl + "pub/PrivacyPolicy.aspx";
    var w = window.open(sPrivacyPoliceUrl, "popupPrivacyPolice", "width=500, height=580, scrollbars=1");
    assertPop(w);
}

function openImprint() {
    var sImprintUrl = rootUrl + "pub/Imprint.aspx";
    var w = window.open(sImprintUrl, "popupImprint", "width=500, height=500, scrollbars=1");
    assertPop(w);
}

function openUserInspiration() {
    var sUrl = "/app/prv/userinspiration/index.jsp?new=true";
    var w = window.open(sUrl, "popupUserInspiration", "width=800, height=550, scrollbars=0");
    assertPop(w);
}

function openUserInspirationViewer() {
    var sUrl = "/app/prv/userinspiration/viewer.jsp";
    var w = window.open(sUrl, "popupUserInspirationViewer", "width=800, height=550, scrollbars=0");
    assertPop(w);
}

function openComment(resultIndx) {
    var sUrl = "/app/prv/comment/index.jsp";
    var xUrl = sUrl + "?resultIndx=" + resultIndx;
    var w = window.open(xUrl, "popupComment", "width=500, height=600, scrollbars=1");
    assertPop(w);
}

function openProfile(section) {
    var sUrl = rootUrl + "prv/MyProfile.aspx";
    if (section) {
        sUrl += "?dpl=" + section;
    }
    var w = window.open(sUrl, "popupProfile", "width=510, height=750, scrollbars=1");
    assertPop(w);
}

function openNewsletter() {
    openProfile('newsletter');
}
function openMyProfile(section) {
    openProfile(section);
}

function openTellAFriend() {
    var sUrl = "/pz/prv/tell_a_friend_popup.jsp";
    var w = window.open(sUrl, "popupRProfile", "width=500, height=580, scrollbars=0");
    assertPop(w);
}

function openChooseLanguage(newlang) {
    var sUrl = "/pz/prv/choose_language_popup.jsp";
    sUrl = sUrl + "?nl=" + newlang;
    window.open(sUrl, "popupChooseLanguage", "width=500, height=270, scrollbars=0");
}

function openRegisterByMail(sUrl) {
    if (sUrl) {
        var w = window.open(sUrl, "popupRByMail", "width=500, height=730, scrollbars=1");
        if (w.focus) w.focus();
    }
    else {
        return;
    }
}

function openParticipationRules() {

    openTermsOfUse('Inspirations');
}

function openStandardPopup(sUrl) {
    if (sUrl) {
        var w = window.open(sUrl, "popupStandard", "width=500, height=410, scrollbars=0");
        if (w.focus) w.focus();
    }
    else {
        return;
    }
}

/**
* register more than one onload events
*/
function registerOnLoadEvent(func) {
    var oldonload = window.onload;

    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            oldonload();
            func();
        }
    }
}
/* alias to previous function */
function registerOnloadEvent(func) {
    registerOnLoadEvent(func);
}

function enableAlphaImage(obj, sizingMethod) {

    var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
    var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
    if (itsAllGood) {
        if (obj && obj.src.match(/\.png$/i) != null && !obj.isModified) {
            sizingMethod = (sizingMethod) ? sizingMethod : "image";
            var src = obj.src;
            //var width = obj.offsetWidth;
            //var height = obj.offsetHeight;
            obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + sizingMethod + "')";
            //obj.width = width;
            //obj.height = height;
            obj.src = "/pz/gfx/spacer.gif";
            obj.isModified = true;
        }
    }
}

function backToContent() {
    location.href = history.back(-1);
}

// functions needed for checking forms

// fetches an object by id
function get(aName) {
    return document.getElementById(aName);
}

// fetches objects using the name
function getByName(aName) {
    return document.getElementsByName(aName);
}

// show red thing
function red(aName) {
    var obj = get(aName);
    obj.className = "formError";
}

// reset red thing
function black(aName) {
    var obj = get(aName);
    obj.className = "";
}

function valid(anId, aPattern) {
    return 0 == get(anId).value.search(aPattern);
}

// check email
function validEmail(anId) {
    return valid(anId, /^[a-zA-Z0-9_\-\.]+@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z0-9\-_]+\.)+[a-zA-Z]{2,4}))$/);
}

// check valid name (firstname, lastname)
function validName(anId) {
    return valid(anId, /^[^0-9_!"#$%&()*+,\/:;<=>?@\[\]^{|}~\.\- \u005C]{2}[^0-9_!"#$%&()*+,\/:;<=>?@\[\]^{|}~\u005C]{0,28}$/);
}

// check phone number
function validPhone(anId) {
    return checkPhoneNumber(anId, /^(0[\d]{9})?$/);
}

// check cellphone number
function validCellphone(anId) {
    return checkPhoneNumber(anId, /^(07(6|7|8|9)\d{7})?$/);
}

// check the street
function validStreet(anId) {
    return valid(anId, /^.{0,50}$/);
}

// check the house no
function validHouseNo(anId) {
    return valid(anId, /^.{0,10}$/);
}

// check the zip code
function validZipcode(anId) {
    return valid(anId, /^[\d]{1,4}$/);
}

// date exists (!= 31.02)
function validDate(year, month, day) {
    var aDate = new Date(year, month - 1, day);
    if (year != -1 && month != -1 && day != -1 && aDate.getMonth() == month - 1) {
        return true;
    }
    return false;
}

// find out if one radio button is checked
function radioChecked(aName) {
    var objs = document.getElementsByName(aName);
    for (i = 0; i < objs.length; i++) {
        var o = objs[i];
        if (o.checked) return true;
    }
    return false;
}

// checks and normalizes a phone number
function checkPhoneNumber(anId, aPattern) {
    var number = get(anId).value;
    number = removeChars(number);
    get(anId).value = normalizePhoneNumber(number);
    return 0 == number.search(aPattern);
}


function normalizePhoneNumber(number) {
    var newNumber = number.substring(0, 3);
    if (number.length > 3) newNumber += " " + number.substring(3, 6);
    if (number.length > 6) newNumber += " " + number.substring(6, 8);
    if (number.length > 8) newNumber += " " + number.substring(8, 10);
    if (number.length > 10) newNumber += " " + number.substring(10, number.length);
    return newNumber;
}


// remove blanks and certain punctuation characters
function removeChars(aString) {
    var newString = aString;
    do {
        aString = newString;
        newString = aString.replace(/ |\/|\-|\\|\(|\)|\./, "");
    } while (newString != aString);
    return aString;
}

function openShop() {
    var sUrl = "/app/prv/shop/index.jsp";
    var w = window.open(sUrl, "shopPop", "width=800, height=550, scrollbars=no, toolbar=no, resizable=no");
    assertPop(w);
}

function openClePopup(sUrl) {
    var w = window.open(sUrl, "clePopup", "width=485, height=550, scrollbars=no, toolbar=no, resizable=no");
    assertPop(w);
}

function openPointcenter() {
    openClePopup("/app/prv/pointcenter/index.jsp");
}

function openCleSignup() {
    openClePopup("/app/prv/signup/index.jsp");
}

function openCleSurvey() {
    openCleSignup();
}

function openQuiz() {
    openClePopup("/app/prv/games/quiz/index.jsp");
}

function openMegaquiz() {
    openClePopup("/app/prv/games/megaquiz/index.jsp");
}

function openMegaquizWinners() {
    openClePopup("/app/prv/games/megaquiz/winners.jsp");
}

function openExperiencePopup() {
    var sUrl = "/app/prv/shop/index.jsp?category=cat4";
    var w = window.open(sUrl, "shopPop", "width=800, height=550, scrollbars=no, toolbar=no, resizable=no");
    assertPop(w);
}

function openCamelOrangePopup() {
    var sUrl = "/app/prv/games/camelorange/index.jsp";
    var w = window.open(sUrl, "shopPop", "width=1024, height=768, scrollbars=no, toolbar=no, resizable=no");
    assertPop(w);
}

function openScratchAndWin() {
    var sUrl = "/app/prv/games/scratchwin/index.jsp";
    var w = window.open(sUrl, "scratchwin", "width=393, height=539, scrollbars=no, toolbar=no, resizable=no");
    assertPop(w);
}

function openNewPackPopup() {
    var sUrl = "/app/prv/games/new_pack/index.jsp";
    var w = window.open(sUrl, "shopPop", "width=995, height=700, scrollbars=no, toolbar=no, resizable=no");
    assertPop(w);
}

function openCamelOnePopup() {
    var sUrl = "/app/prv/camel_one/index.jsp";
    var w = window.open(sUrl, "camelOne", "width=720, height=540, scrollbars=no, toolbar=no, resizable=no");
    assertPop(w);
}
function openNaturalflavorPopup() {
    var sUrl = "/app/prv/naturalflavor/index.jsp";
    var w = window.open(sUrl, "camelOne", "width=720, height=540, scrollbars=no, toolbar=no, resizable=no");
    assertPop(w);
}

function assertPop(w) {
    if (w) {
        if (w.focus) w.focus();
    } else {
        alert("Um die Pop-Ups auf Ihrem Computer zu sehen, müssen Sie Ihren Pop-Up Blocker entweder deaktivieren oder anpassen. Dazu sollten Sie www.camel.ch auf die Liste der erlaubten Websites setzen.");
    }
}

function write(s) {
    document.write(s);
}


