crint = 1;
vmint = 1;
cmint = 1;
drint = 1;
lsint = 1;

function nextCR() {

    switch (crint) {
        case 1:
        document.getElementById("celestial-reasonings-samples").innerHTML = "Aquarius:<br>It is true, the journey should be as enjoyable as the destination.  If you aren't having fun on the trip, what changes are needed in your life?";
        crint = 2;
        return(false);
    
        case 2:
        document.getElementById("celestial-reasonings-samples").innerHTML = "Gemini:<br>Seasoned runners know: sometimes stopping to walk and use different muscles for a minute actually improves race time; so, take it easy!";
        crint = 3;
        return(false);
    
        case 3:
        document.getElementById("celestial-reasonings-samples").innerHTML = "Sagittarius:<br>Lasting change happens in tiny increments, so do not lose faith that you still have the capacity for being exactly who you want to be.";
        crint = 1;
        return(false);
    }
}

function nextVM() {

    switch (vmint) {
        case 1:
        document.getElementById("vitamin-me-samples").innerHTML = "Vitamin Me!<br>If you feel pulled in different directions, ask yourself what would make YOU the happiest in the long term. Do that thing.";
        vmint = 2;
        return(false);
    
        case 2:
        document.getElementById("vitamin-me-samples").innerHTML = "Vitamin Me!<br>It's scientifically proven that smiling (even if you don&rsquo;t feel like it) will put you in a better mood.";
        vmint = 3;
        return(false);
    
        case 3:
        document.getElementById("vitamin-me-samples").innerHTML = "Vitamin Me!<br>Stand up for your ideas! Being respected and appreciated for your uniqueness is much better than being a doormat.";
        vmint = 1;
        return(false);
    }
}

function nextCM() {

    switch (cmint) {
        case 1:
        document.getElementById("cats-meow-samples").innerHTML = "Kitty-ism! &ldquo;I think my human is a lousy hunter. She goes out all day, comes home tired, yet always brings me the same boring meal!&rdquo;";
        cmint = 2;
        return(false);
    
        case 2:
        document.getElementById("cats-meow-samples").innerHTML = "The perfect gift:  Sponsor a special needs cat through a rescue group in your friends&rsquo; name (try bestfriends.org). How thoughtful!";
        cmint = 1;
        return(false);
    
    }
}

function nextDR() {

    switch (drint) {
        case 1:
        document.getElementById("dogs-rule-samples").innerHTML = "Dog-ism! &ldquo;Why am I the one in trouble? You left a loaf of bread on the counter. I thought that meant help myself. I sorry.&rdquo;";
        drint = 2;
        return(false);
    
        case 2:
        document.getElementById("dogs-rule-samples").innerHTML = "OMG! Open gate! Quick, text GlobalPetFinder! Finally, GPS for the dog! Don&rsquo;t skip the microchip, in case she slips her collar.";
        drint = 1;
        return(false);
    
    }
}

function nextLS() {

    switch (lsint) {
        case 1:
        document.getElementById("love-and-sex-sample-select").innerHTML = "<a href=\"#\" onclick=\"return nextLS();\">Show subscribe message</a>";
        document.getElementById("love-and-sex-samples").innerHTML = "Want more action? Tell your guy you got a spray tan and he can&rsquo;t touch you for 3 days or it&rsquo;ll smear. He&rsquo;ll jump you ASAP. Could guys BE any easier?";
        lsint = 2;
        return(false);
    
        case 2:
        document.getElementById("love-and-sex-sample-select").innerHTML = "<a href=\"#\" onclick=\"return nextLS();\">Show sample message</a>";
        document.getElementById("love-and-sex-samples").innerHTML = "<img src=\"./images/love_and_sex_sms.png\">";
        lsint = 1;
        return(false);
    
    }
}

function generate_address( username, hostname, subject ) {
    var domain = ".com";
    var atsign = "&#64;";
    var addr = username + atsign + hostname + domain;
    document.write( 
        "<" + "a" + " " + "href=" + "mail" + "to:" + addr + "?subject=" + subject + ">" +
        addr +
        "<\/a>");
}

function TOSPopUpWindow(url) {
	window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=620,height=630,screenX=150,screenY=150,top=150,left=150')
}

function NewTOSPopUpWindow(url) {
	window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=430,screenX=150,screenY=150,top=150,left=150')
}

function WallpaperPopUpWindow(url) {
	window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=505,height=430,screenX=150,screenY=150,top=150,left=150')
}

function DJPopUpWindow(url) {
	window.open(url,'DJpopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=490,height=630,screenX=150,screenY=150,top=150,left=150')
}

function ISPopUpWindow(url) {
	window.open(url,'ISpopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=750,height=450,screenX=150,screenY=150,top=150,left=150')
}

function BNPopUpWindow(url) {
	window.open(url,'BNpopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=750,height=650,screenX=150,screenY=150,top=150,left=150')
}

function NewsletterPopUpWindow(url) {
    window.open(url,'newsletterPopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=490,height=230,screenX=150,screenY=150,top=150,left=150')
}

function MMPopUpWindow(url) {
	window.open(url,'MMPopUpWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=700,screenX=160,screenY=160,top=160,left=160')
}

function LNOGalleryPopUpWindow(url) {
    window.open(url,'LNOGalleryPopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=560,height=500,screenX=150,screenY=150,top=150,left=150')
}

function CAPopUpWindow(url) {
    window.open(url,'CAPopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=300,height=300,screenX=150,screenY=150,top=150,left=150')
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode; 
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }

    function containsElement(arr, ele) {
        var found = false, index = 0;
        while(!found && index < arr.length)
        if(arr[index] == ele)
            found = true;
        else
            index++;
        return found;
    }
    
    function getIndex(input) {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
        if (input.form[i] == input)index = i;
        else i++;
        return index;
    }
    return true;
}

var timeout = 500;
var closetimer  = 0;
var ddmenuitem  = 0;

function mopen(id) {    
    mcancelclosetime();

    if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';

    ddmenuitem = document.getElementById(id);
    ddmenuitem.style.visibility = 'visible';
}

function mclose() {
    if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

function mclosetime() {
    closetimer = window.setTimeout(mclose, timeout);
}

function mcancelclosetime() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

document.onclick = mclose;

function verifyEmail() {
    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if (document.getElementById('home_email_field').value.search(emailRegEx) == -1) {
        document.getElementById('home_email_field').value = "Enter a valid email";
    } else {
        var poststr = "email=" + encodeURI(document.getElementById("home_email_field").value) +
                      "&phone=" + encodeURI(document.getElementById("home_phone_field").value);
        document.getElementById('home_email_field').style.display = "none";
        document.getElementById('home_phone_field').style.display = "none";
        document.getElementById('home_go_button').style.display = "none";
        document.getElementById('home_email_message').style.display = "block";
        makePOSTRequest('home_email_capture.php', poststr);
    }
}

var http_request = false;

function makePOSTRequest(url, parameters) {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        return false;
    }
    
    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.send(parameters);
}
