﻿// <copyright company="Wilshire Press Inc.">
// Copyright (c) 2009 - 2010 Wilshire Press Inc. All Rights Reserved
// </copyright>

//function textCounter(field, countfield, maxlimit) {
//    if (field.value.length > maxlimit) {
//        field.value = field.value.substring(0, maxlimit);
//    }
//    else {
//        countfield.value = maxlimit - field.value.length;
//    }
//}

function textCounter2(field, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    }
}

function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    }
    else {
        countfield.innerText = maxlimit - field.value.length + " character(s) left";
        document.getElementById('teaser').innerText = field.value;
    }
}

function textCounterAuthorProfile(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    }
    else {
        countfield.innerText = maxlimit - field.value.length + " character(s) left";
    }
}


function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}
function getViewPortWidth() {
    var viewPortWidth;
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    if (typeof window.innerWidth != 'undefined') {
        viewPortWidth = window.innerWidth;
    }
    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        viewPortWidth = document.documentElement.clientWidth;
    }
    // older versions of IE
    else {
        viewPortWidth = document.getElementsByTagName('body')[0].clientWidth;
    }
    //
    return viewPortWidth;
}
//function getViewPortHeight() {
//    var viewPortHeight;
//    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
//    if (typeof window.innerWidth != 'undefined') {
//        viewPortHeight = window.innerHeight;
//    }
//    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
//    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
//        viewPortHeight = document.documentElement.clientHeight;
//    }
//    // older versions of IE
//    else {
//        viewPortHeight = document.getElementsByTagName('body')[0].clientHeight;
//    }
//    //
//    return viewPortHeight;
//}
//
function changeBkgndImage() {
    var rn = Math.floor((Math.random() * 6) + 1);
    document.body.style.background = "#030604 url('/images/bkgnd" + rn + ".jpg') no-repeat fixed bottom";
}
//
function changeBkgndImageBookStore() {
    var rn = Math.floor((Math.random() * 5) + 1);
    document.body.style.background = "#030604 url('/images/bkgnd" + rn + "_bookStore.jpg') no-repeat fixed bottom";
}

function ShowPopUp(divName) {
    //
    var url = window.location.href;
    var urlArray = new Array();
    urlArray = url.split("/");
    //
    if ((urlArray[urlArray.length - 1] == "Default.aspx") || (urlArray[urlArray.length - 1].length == 0)) {
        document.getElementById('popup_' + divName).style.display = "block";
        document.getElementById('popup_writeBookContainer').style.visibility = "visible";
    }
}
function HidePopUp(divName) {
    document.getElementById('popup_' + divName).style.display = "none";
    document.getElementById('popup_writeBookContainer').style.visibility = "hidden";
}

//scripts created by Fireworks
//
function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}
//
//end of Fireworks scripts

function displayMain() {
    var heading = "A state-of-the-art platform for Authors and book lovers.";
    var description = "Providing FREE tools to Write, Read, Collaborate, Edit, Print, Publish and Sell in a seamless process.";
    document.getElementById('heading').innerHTML = heading;
    document.getElementById('description').innerHTML = description;
}
function displayPrint() {
    var heading = "No hustle, no hidden fees, low printing prices, great quality and fast delivery.";
    var description = "Click to learn more.";
    document.getElementById('heading').innerHTML = heading;
    document.getElementById('description').innerHTML = description;
}
function displaySell() {
    var heading = "Sell your book on our book store with no fees and keep your rights and profits.";
    var description = "Click to learn more.";
    document.getElementById('heading').innerHTML = heading;
    document.getElementById('description').innerHTML = description;
}
function displayWrite() {
    var heading = "The only writing tool on the internet designed for authors and is completely free to use.";
    var description = "Click to learn more.";
    document.getElementById('heading').innerHTML = heading;
    document.getElementById('description').innerHTML = description;
}
function displayCollaborate() {
    var heading = "Team up with other authors and collaborate with anyone anywhere using our free tools.";
    var description = "";
    document.getElementById('heading').innerHTML = heading;
    document.getElementById('description').innerHTML = description;
}
function displayPrice() {
    var heading = "It’s what it is; no hidden fees no elaborate calculations.";
    var description = "Click to calculate and compare.";
    document.getElementById('heading').innerHTML = heading;
    document.getElementById('description').innerHTML = description;
}
function redirect(urlString) {
    window.location.href = urlString;
}

function showLayer(layername) {
    var cb_name = "cb_" + layername;
    var img_name = "img_" + layername;
    if (document.getElementById(cb_name).checked == true) {
        document.getElementById('img_blank').style.visibility = "visible";
        document.getElementById(img_name).style.visibility = "visible";
    }
    else {
        document.getElementById(img_name).style.visibility = "hidden";
    }
}
