﻿//=======================================
// Page Options Functions
//=======================================


//============ Bubble Toggle ============
function fnBubbleToggle(id) {

    var state = document.getElementById(id).style.display;
    if (state == 'block') {
        document.getElementById(id).style.display = 'none';
    } else {
        document.getElementById(id).style.display = 'block';
    }
    return false;
}

//============ Bookmark This ============
function fnBookmarkThis(){
    if (window.sidebar) { // Firefox 1.x+
	    window.sidebar.addPanel(document.title, document.URL, "");
	    return false;
    } else if(document.all) { //IE 4+
	    window.external.AddFavorite(document.URL, document.title);
	    return false;
	} else {
	
        return true;
    }
}

//============ On Load Functions ============
function fnShowPageOptions() {
    document.getElementById("divSocialMedia").style.display = "block"
}

function fnCheckEmailMessage() {
    
    if (document.URL.toLowerCase().indexOf("emailpage=") >= 0) {
        document.getElementById("EmailBox1").style.display = 'block';
    }
}

//=======================================
// Email this page functions
//=======================================

function fnCheckIt(id,marker,submitCheck){
    
    if(document.getElementById(id)){
        var txtbox = document.getElementById(id);
        if(document.getElementById(marker+'-icon')){var icon = document.getElementById(marker+'-icon');}
        if(document.getElementById(marker+'-star')){var star = document.getElementById(marker+'-star');}
        if(document.getElementById(marker+'-helpbox')){var helpbox = document.getElementById(marker+'-helpbox');}
        if(document.getElementById(marker+'-helptxt')){var helptxt = document.getElementById(marker+'-helptxt');}
        
        //Required Field
        if (txtbox.value==null||txtbox.value==""){
            var msg = 'This is a required field';
            if(submitCheck==true) {
                fn_input_warning(txtbox,icon,star,helpbox,helptxt,msg);
                return false;
            } else {
                fn_input_pending(txtbox,icon,star,helpbox,helptxt,msg);
            }
        
        //Email Validation    
        } else if (marker.toLowerCase().indexOf("email") >= 0) {
            var RegexPattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
            if(RegexPattern.test(txtbox.value)){         
	            fn_input_ok(txtbox,icon,star,helpbox,helptxt);
            }else{   
                var msg = 'Please enter a valid email address';
                if(submitCheck==true) {
                    fn_input_warning(txtbox,icon,star,helpbox,helptxt,msg);
                    return false;
                } else {
	                fn_input_pending(txtbox,icon,star,helpbox,helptxt,msg);
	            }
            }
        //Input ok
        } else {
            if(submitCheck==true) {
                return true;
            } else {
                fn_input_ok(txtbox,icon,star,helpbox,helptxt);
            }
        }
    }
}



function fn_input_ok(txtbox,icon,star,helpbox,helptxt){
    icon.style.display = 'block';
    icon.className = 'CheckIt_icon icon_ok';
    star.innerHTML = '&nbsp;&nbsp;';
    helpbox.style.display = 'none';
    helptxt.innerHTML = '';
    txtbox.style.backgroundColor = '#F1FFD2';
}

function fn_input_pending(txtbox,icon,star,helpbox,helptxt,msg){
    icon.style.display = 'block';
    icon.className = 'CheckIt_icon icon_pending';
    star.innerHTML = '*&nbsp;';
    helpbox.style.display = 'block';
    helptxt.innerHTML = msg;
    txtbox.style.backgroundColor = '#FFF0D2';
}

function fn_input_warning(txtbox,icon,star,helpbox,helptxt,msg){
    icon.style.display = 'block';
    icon.className = 'CheckIt_icon icon_warning';
    star.innerHTML = '*&nbsp;';
    helpbox.style.display = 'block';
    helptxt.innerHTML = msg;
    helptxt.style.color = "#CC0000";
    txtbox.style.backgroundColor = '#FFE0D2';
}

function fnCheckItValid() {
    
    var arrInputElements = document.getElementById("divEmailFriend1").getElementsByTagName("input"), blnIsError = true;
    if (arrInputElements) {
    
        for(i=0;i<arrInputElements.length;i++){
                
            if (arrInputElements[i].id.indexOf("txtYourName") >= 0){
                if(fnCheckIt(arrInputElements[i].id,'divYourName',true)==false){
                    blnIsError = false;
                };
            } else if (arrInputElements[i].id.indexOf("txtYourEmail") >= 0){
                if(fnCheckIt(arrInputElements[i].id,'divYourEmail',true)==false){
                    blnIsError =  false;
                };
            } else if (arrInputElements[i].id.indexOf("txtFriendsName") >= 0){
                if(fnCheckIt(arrInputElements[i].id,'divFriendsName',true)==false){
                    blnIsError =  false;
                };
            } else if (arrInputElements[i].id.indexOf("txtFriendsEmail") >= 0){
                if(fnCheckIt(arrInputElements[i].id,'divFriendsEmail',true)==false){
                    blnIsError =  false;
                };
            } else {
            }
        }
        return blnIsError;
    }
}

function limitText(limitField, limitCount, limitNum) {
	
	var myField = document.getElementById(limitField);
	var myCounter = document.getElementById(limitCount);
	
	if (myField.value.length > limitNum) {
		myField.value = myField.value.substring(0, limitNum);
	} else {
		myCounter.value = limitNum - myField.value.length;
	}
}
