// JavaScript Document


function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var histogram = {}, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}


function countChars(idElement){
if (max_chars < 1) {
	max_chars = 140;
}
counter = document.getElementById(idElement);
field = document.getElementById('text').value;
field_length = field.length;

// Calculate remaining chars
remaining_chars = max_chars-field_length;
if(remaining_chars>=21){
counter.style.color="#FFFFFF";
} else {
	counter.style.color="#CC0000";
}
// Update the counter on the page
counter.innerHTML = remaining_chars;
}

function countChars_new(idElement, max_chars){
if (max_chars < 1) {
	max_chars = 140;
}
counter = document.getElementById(idElement);
field = document.getElementById('text').value;
field_length = field.length;

// Calculate remaining chars
remaining_chars = max_chars-field_length;
if(remaining_chars>=21){
counter.style.color="#FFFFFF";
} else {
	counter.style.color="#CC0000";
}
// Update the counter on the page
counter.innerHTML = remaining_chars;
}



function countCharsNew(idElement){
max_chars = 140;
counter = document.getElementById(idElement);
field = document.getElementById('textarea-new').value;
field_length = field.length;

// Calculate remaining chars
remaining_chars = max_chars-field_length;
if(remaining_chars>=21){
counter.style.color="#FFFFFF";
} else {
	counter.style.color="#CC0000";
}
// Update the counter on the page
counter.innerHTML = remaining_chars;
}


// Clear with dropdowns
function eFocus_layer(field, id_class){
if (field.value == field.defaultValue){
field.value = field.defaultValue;
}
var layer = document.getElementById(id_class);
field.className="inputon";
layer.className="visibilityon"
}
function eBlur_layer(field, id_class){
if (field.value == ''){
field.value = field.defaultValue;
field.className="inputoff";
var layer = document.getElementById(id_class);
layer.className="visibilityoff"
}else{
field.className="inputon";
var layer = document.getElementById(id_class);
layer.className="visibilityoff"
}
}


function toggle(id) {  
         var state = document.getElementById(id).style.display;  
             if (state == 'block') {  
                 document.getElementById(id).style.display = 'none';  
             } else {  
                 document.getElementById(id).style.display = 'block';  
             }  
}  


// form validation
function validateForm(obj) {

	errors = false;
	
	// Validate form Values
	
     // your name
	if (((obj == document.getElementById('your_name')) || (obj == null)) && ((!document.getElementById('your_name').value) || (document.getElementById('your_name').value == ''))) {
		document.getElementById('your_name').style.color = 'red';
		document.getElementById('your_name').style.border = '1px solid red';
		document.getElementById('your_name').style.background = '#fff url(/images/error.gif) no-repeat right center';
		errors = true;
	} else if ((obj == document.getElementById('your_name')) || (obj == null)) {
		document.getElementById('your_name').style.color = 'green';
		document.getElementById('your_name').style.border = '1px solid green';
		document.getElementById('your_name').style.background = '#fff url(/images/pass.gif) no-repeat right center';
	}

		// twitter name
	if (((obj == document.getElementById('twitter_name')) || (obj == null)) && ((!document.getElementById('twitter_name').value) || (document.getElementById('twitter_name').value == ''))) {
		document.getElementById('twitter_name').style.border = '1px solid #50ABF0';
		document.getElementById('twitter_name').style.background = '#fff';
	} else if ((obj == document.getElementById('twitter_name')) || (obj == null)) {
		document.getElementById('twitter_name').style.color = 'green';
		document.getElementById('twitter_name').style.border = '1px solid green';
		document.getElementById('twitter_name').style.background = '#fff url(/images/pass.gif) no-repeat right center';
	}
	
		// Email Address
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = document.getElementById('email').value;
	if (((obj == document.getElementById('email')) || (obj == null)) && (reg.test(address) == false)) {
		document.getElementById('email').style.color = 'red';
		document.getElementById('email').style.border = '1px solid red';
		document.getElementById('email').style.background = '#fff url(/images/error.gif) no-repeat right center';
		errors = true;
	} else if ((obj == document.getElementById('email')) || (obj == null)) {
		document.getElementById('email').style.color = 'green';
		document.getElementById('email').style.border = '1px solid green';
		document.getElementById('email').style.background = '#fff url(/images/pass.gif) no-repeat right center';
	}
		
		// I am (select dropdown)
if (((obj == document.getElementById('i_am')) || (obj == null)) && ((!document.getElementById('i_am').value) || (document.getElementById('i_am').value == '0'))) {
	document.getElementById('i_am').style.color = 'red';
	document.getElementById('i_am').style.border = '1px solid red';
	document.getElementById('i_am').style.background = '#fff url(/images/error.gif) no-repeat 165px center';
	errors = true;
	} else if ((obj == document.getElementById('i_am')) || (obj == null)) {
		document.getElementById('i_am').style.color = 'green';
		document.getElementById('i_am').style.border = '1px solid green';
		document.getElementById('i_am').style.background = '#fff url(/images/pass.gif) no-repeat 165px center';
}

	// message
 if (((obj == document.getElementById('message')) || (obj == null)) && ((!document.getElementById('message').value) || (document.getElementById('message').value == ''))) {
 document.getElementById('message').style.color = 'red';
  document.getElementById('messagew').style.border = '1px solid red';
  document.getElementById('message').style.background = '#fff url(/images/error.gif) no-repeat right top';
  errors = true;
 } else if ((obj == document.getElementById('message')) || (obj == null)) {
  document.getElementById('message').style.color = 'green';
  document.getElementById('message').style.border = '1px solid green';
  document.getElementById('message').style.background = '#fff url(/images/pass.gif) no-repeat right top';
}


	
	if (errors == true) {
		return false;
	} else {
		return true;
	}
}


function initfaqAccordian() {
  $('#faq-accordian ul').hide();
  $('#faq-accordian ul:first').show();
  $('#faq-accordian li a').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        return false;
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        $('#faq-accordian ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return false;
        }
      }
    );
  }
$(document).ready(function() {initfaqAccordian();});


sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
