/*
	Written by Jonathan Snook, http://www.snook.ca/jonathan
	Add-ons by Robert Nyman, http://www.robertnyman.com
*/

/*
To get all a elements in the document with a “info-links” class.
    getElementsByClassName(document, "a", "info-links");
To get all div elements within the element named “container”, with a “col” class.
    getElementsByClassName(document.getElementById("container"), "div", "col");
To get all elements within in the document with a “click-me” class.
    getElementsByClassName(document, "*", "click-me");
*/

function toggle_incentives_visibility(id) {

    if (id != 'overview') {
        var o = document.getElementById('overview');
        o.style.display = 'none';
    }

    if (id != 'application') {
        var a = document.getElementById('application');
        a.style.display = 'none';
    }

    var e = document.getElementById(id);
    e.style.display = 'block';
}

function toggle_aboutus_visibility(id) {

    if (id != 'company') {
        var c = document.getElementById('company');
        c.style.display = 'none';
    }

    if (id != 'vision') {
        var v = document.getElementById('vision');
        v.style.display = 'none';
    }

    if (id != 'people') {
        var p = document.getElementById('people');
        p.style.display = 'none';
    }

    if (id != 'project') {
        var j = document.getElementById('project');
        j.style.display = 'none';
    }
    
    if (id != 'career') {
        var r = document.getElementById('career');
        r.style.display = 'none';
    }
    
    var e = document.getElementById(id);
    e.style.display = 'block';
    
}

function toggle_whysolar_visibility(id) {

    if (id != 'energy') {
        var n = document.getElementById('energy');
        n.style.display = 'none';
    }

    if (id != 'how') {
        var h = document.getElementById('how');
        h.style.display = 'none';
    }

    if (id != 'benefits') {
        var b = document.getElementById('benefits');
        b.style.display = 'none';
    }

    var e = document.getElementById(id);
    e.style.display = 'block';

}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function updateSessionForKeepingUserLoggedIn() {
    ajax = new sack('index.php?section=ajx_refresh_session');
//	ajax.element = ‘myexamplediv’;
	ajax.runAJAX();
}

function confirmFunc(url, confirmMsg) {
	if (confirm(confirmMsg)) {
		location.href = url;
	}
	return false;
}

function validatePriceFild(El) {
  fildValue = parseFloat(El.value);
  El.value = isNaN(fildValue) ? 0 : fildValue;
}

function trim(stringToTrim) { // malisa
	ret = stringToTrim.replace(/^\s+|\s+$/g, '');
	return ret.replace('\&amp;', '&');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function sendToFriend(turl){
	ajax = new sack();
	var sender_email = document.getElementById('sender_email').value;
	ajax.setVar('sender_email', sender_email);
	var sender_email = document.getElementById('friend_mail').value;
	ajax.setVar('friend_mail', sender_email);
	var sender_email = document.getElementById('custom_message').value;
	ajax.setVar('custom_message', sender_email);
	var address = document.getElementById('address').value;
	ajax.setVar('address', address);
	ajax.onLoading = function(){
			$('send_friend_button').disabled = true;
			$('send_friend_button').value = "Sending...";
	}
	ajax.requestFile = turl + '&subsection=send_mail';
	ajax.onCompletion = function() {
			$('sent_to_friend_form').innerHTML = ajax.response;
			$('send_friend_button').disabled = false;
			$('send_friend_button').value = "Send";
			
	}
	ajax.runAJAX();
};



function changeLanguage(lang){
    document.location.href=locationAddArgument('language', lang);
}

function locationAddArgument(key, value){
    var loc = pound = q = namedAnchor = args = '';
    if(document.location.href.indexOf('?')!=-1){
        q = document.location.href.indexOf('?');
        loc = document.location.href.substr(0, q);
    }else if(document.location.href.indexOf('#')!=-1){
        loc = document.location.href.substr(0, pound);
    }
    if(document.location.href.indexOf('#')!=-1 && document.location.href.indexOf('#')!=document.location.href.length-1){
        pound = document.location.href.indexOf('#');
        namedAnchor = document.location.href.substr(pound);
    }
    if(q!=''){
        var length = (pound!=''?pound-q:document.location.href.length);
        args = document.location.href.substr(q, length);
        if(args.indexOf(key+'=')!=-1){
            var start = args.indexOf(key+'=');
            var end = args.indexOf('&', start);
            args = args.substr(0, start) + key+'='+value + (end!=-1?args.substr(end):'');
        }else{
            args += '&'+key+'='+value;
        }
    }else{
        args = '?'+key+'='+value;
    }
    return loc + args + namedAnchor;
}
