//============== TinyBox Functions ================
function fnTinyClose(){
	TINY.box.hide();
}
function fnTinyLoad(){
	/*var tbContent = "<a href='#' onClick='fnTinyClose()' id='tinyClose'>Close <strong>X</strong></a><div id='tinyContainer'><img class='tinyImage' alt='Jonas Transparent CD' src='/media/images/tinybox-CD.jpg' /><p>New Release! Pick up Jonas' first solo album <em>Transparent</em> today. </p><a class='btnOrange' href='/store/'>Get Your Copy Now!</a></div><div class='fClear'></div>";
	TINY.box.show(tbContent,0,520,0,0);*/
}
//============== Form Functions ================
function fnErrorField(fieldName,bFail){
	if(bFail){
		document.getElementById(fieldName).value='Required';
        document.getElementById(fieldName).style.color="red";
	}else{
		document.getElementById(fieldName).style.color="black";
	}
}
function fnFormCheck(){
    var bValid=true;
    var sFirstName=document.getElementById("frmFName").value;
    var sLastName=document.getElementById("frmLName").value;
    var sEmail=document.getElementById("frmEmail").value;
    var sComments=document.getElementById("frmComments").value;
    if(sFirstName==""||sFirstName=='Required'){
        fnErrorField("frmFName",true);
        bValid=false;
    }else{
		fnErrorField("frmFName",false);
	}
    if(sLastName==""||sLastName=='Required'){
		fnErrorField("frmLName",true);
        bValid=false;
    }else{
		fnErrorField("frmLName",false);
	}
    var reEmailPat=/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})/;
    if(reEmailPat.test(sEmail)===false){
        fnErrorField("frmEmail",true);
        bValid=false;
    }else{
		fnErrorField("frmEmail",false);
	}
    if(sComments==""||sComments=='Required'){
        fnErrorField("frmComments",true);
        bValid=false;
    }else{
		fnErrorField("frmComments",false);
	}
	return bValid;
}
function fnNewsCheck(){
    var bValid=true;
    var sEmail=document.getElementById("email").value;
    var reEmailPat=/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})/;
    if(reEmailPat.test(sEmail)===false){
        fnErrorField("email",true);
        bValid=false;
    }else{
		fnErrorField("email",false);
	}
	return bValid;
}
//============== Cookie Check Functions ================
function fnSetCookie(sName,sVal,nDays) {
    var dtCur = new Date();
    dtCur.setTime(dtCur.getTime() + (nDays * 24 * 60 * 60 * 1000));
    document.cookie = sName +"=" + escape(sVal) + ";expires=" + dtCur.toGMTString() + ";path=/";
}
function fnGetCookie(sVal) {
    if (document.cookie.length > 0) {
        nValStart = document.cookie.indexOf(sVal + "=");
        if (nValStart != -1) {
            nValStart = nValStart + sVal.length + 1;
            nValEnd = document.cookie.indexOf(";", nValStart);
            if (nValEnd == -1) {nValEnd = document.cookie.length;}
            return unescape(document.cookie.substring(nValStart, nValEnd));
        }
    }
    return "";
}
function fnPopupViewed(){
    nDays = 15;
    fnSetCookie("popup","true",nDays);
}
function fnPopupCheck() {
	// Check Cookie
	var bViewed = fnGetCookie('popup');
	if (bViewed != "true") {
		fnPopupViewed();
		fnTinyLoad();
	}
}
/*============== jQuery Doc Ready ================*/
$(document).ready(function() {
	if ($.browser.msie) {
		var nDecimalLoc=jQuery.browser.version.indexOf(".");
		var nVersion=jQuery.browser.version.slice(0,nDecimalLoc);
		$('body').addClass ("ie");
		$('body').addClass ("ie"+nVersion);
		if(nVersion<=6){
			$('#page').prepend('<div class="errorBox"><p>This site does not support IE6 and lower. Please upgrade to a <a href="http://www.browserchoice.eu/BrowserChoice/browserchoice_en.htm">more secure browser</a> immediately for a safer experience.</p></div>');
		}
	}
	if($.browser.opera){
		$('body').addClass ("opera");
	}
	// Blank windows for non-jw site links
	var sSiteUrl = "jonaswoods.net";
	$("a[href*=http://]").not("a[href*="+sSiteUrl+"]").attr("target","_blank");
});
