function settabs(){
	// Analyses the current URL of page and sets nav tab/button display colors/images accordingly
	var active_color = "#60a030";
	var inactive_color = "#2A70AE";
	var parts = document.location.href.split('/');
	var filename = parts[parts.length-1];
	//alert("Filename - " + filename);
	if((filename.indexOf("index") >= 0)||(filename == "")){
		
	}
    if(filename.indexOf("about-us.php") >= 0){
		document.getElementById('aboutlink').style.color = active_color;
        document.getElementById('aboutlink').style.fontWeight = "bold";
    }else{
    	document.getElementById('aboutlink').style.color = inactive_color;
        document.getElementById('aboutlink').style.fontWeight = "normal";
    }
    if((filename.indexOf("merchant-services.php") >= 0)||(filename.indexOf("solutions.php") >= 0)){
		document.getElementById('sollink').style.color = active_color;
        document.getElementById('sollink').style.fontWeight = "bold";
    }else{
    	document.getElementById('sollink').style.color = inactive_color;
        document.getElementById('sollink').style.fontWeight = "normal";
    }
    if(filename.indexOf("login=1") >= 0){
		document.getElementById('loginlink').style.color = active_color;
        document.getElementById('loginlink').style.fontWeight = "bold";
        document.getElementById('sollink').style.color = inactive_color;
        document.getElementById('sollink').style.fontWeight = "normal";
    }else{
    	document.getElementById('loginlink').style.color = inactive_color;
        document.getElementById('loginlink').style.fontWeight = "normal";
    }	
    if(filename.indexOf("contact-us.php") >= 0){
		document.getElementById('contactlink').style.color = active_color;
        document.getElementById('contactlink').style.fontWeight = "bold";
    }else{
    	document.getElementById('contactlink').style.color = inactive_color;
        document.getElementById('contactlink').style.fontWeight = "normal";
    }
}

function resettabs(){
	// resets all tabs to inactive - then sets current
	var inactive_color = "#2A70AE";
   	document.getElementById('aboutlink').style.color = inactive_color;
    document.getElementById('aboutlink').style.fontWeight = "normal";
  	document.getElementById('sollink').style.color = inactive_color;
    document.getElementById('sollink').style.fontWeight = "normal";
   	document.getElementById('loginlink').style.color = inactive_color;
    document.getElementById('loginlink').style.fontWeight = "normal";
   	document.getElementById('contactlink').style.color = inactive_color;
    document.getElementById('contactlink').style.fontWeight = "normal";
    settabs();
}

function changeFocusImage(imgobj, flag){
    if(flag == 'real'){
        imgobj.src = "images/RealEstate_Big.jpg";
    }else if(flag == 'b2b'){
        imgobj.src = "images/B2B_Big.jpg";
    }else if(flag == 'capital'){
        imgobj.src = "images/CapitalAdvance_Big.jpg";
    }else if(flag == 'retail'){
        imgobj.src = "images/Retail_Big.jpg";
    }else if(flag == 'giving'){
        imgobj.src = "images/Giving_Big.jpg";
    }else if(flag == 'academic'){
        imgobj.src = "images/Academic_Big.jpg";
    }
    return true;
}

function changeSolutionHeaderImage(imgobj, flag, id){
    if(flag == 'real'){
        imgobj.src = "images/RealEstate_Logo_" + id + ".gif";
    }else if(flag == 'b2b'){
        imgobj.src = "images/B2B_Logo_" + id + ".gif";
    }else if(flag == 'capital'){
        imgobj.src = "images/CashAdvance_Logo_" + id + ".gif";
    }else if(flag == 'retail'){
        imgobj.src = "images/Retail_Logo_" + id + ".gif";
    }else if(flag == 'giving'){
        imgobj.src = "images/Giving_Logo_" + id + ".gif";
    }else if(flag == 'academic'){
        imgobj.src = "images/APP_Logo_" + id + ".gif";
    }
    return true;
}

function toggleDiv(divID, status){
    var active_color = "#60a030";
	var inactive_color = "#AAAAAA";
    var linkID = divID + "link";
    if(document.getElementById(divID)){
        document.getElementById(divID).style.display = status;
    }
    if(document.getElementById(linkID)){
        if(status == "block"){
            document.getElementById(linkID).style.color = active_color;
        }else{
            document.getElementById(linkID).style.color = inactive_color;
        }
    }
}

function navHover(obj, status){
    var white_color = "#FFFFFF";
    var orange_color = "#60a030";
    var blue_color = "#2A70AE";    
    if(obj != null){
//        obj = newobj;
//        alert('Width = "' + obj + '"');
    }
    if(status == "on"){
        obj.style.backgroundColor = orange_color;
        obj.style.color = white_color;
        obj.style.fontWeight = "bold";
    }else{
        obj.style.backgroundColor = white_color;
        obj.style.color = blue_color;
        obj.style.fontWeight = "normal";
    }
}

function toggleResource(divID, status){
    var active_color = "#60a030";
	var inactive_color = "#2A70AE";
    var ID = "resourcelinks" + divID;
    var linkID = "rlink" + divID;
    clearResources();    
    if(document.getElementById(ID)){
        document.getElementById(ID).style.display = status;
        if(status == "block"){
            document.getElementById(linkID).style.color = active_color;
        }else{
            document.getElementById(linkID).style.color = inactive_color;
        }
    }
}

function toggleBenefits(ID, status){
    clearBenefits();    
    toggleDiv(ID, status);    
    if(document.getElementById('leftnavsolimg')){
        if(ID == 'overview'){
            document.getElementById('leftnavsolimg').src = "images/LeftBoxBottom.gif";
            if(document.getElementById('infoform')){
                document.getElementById('infoform').style.display = "block";
            }
        }else{
            document.getElementById('leftnavsolimg').src = "images/DLS_BoxBottom.gif";
            if(document.getElementById('infoform')){
                document.getElementById('infoform').style.display = "none";
            }
        }
        if(ID == 'resources'){
            toggleDiv('loginform','block');
            toggleDiv('vcontent','none');
        }else{
            toggleDiv('loginform','none');
            toggleDiv('vcontent','block');
        }
    }
}

function clearBenefits(){
    toggleDiv('overview','none');
    toggleDiv('highlights','none');
    toggleDiv('benefits','none');
    toggleDiv('payoption','none');
    toggleDiv('addservices','none');
    toggleDiv('resources','none');
    toggleDiv('apply','none');
    if(document.getElementById('faq') != null){
        toggleDiv('faq','none');
    }
}

function clearSubNavs(){
    toggleDiv('loginnav','none');
    toggleDiv('solnav','none');
    toggleDiv('aboutnav','none');
}

function clearResources(){
    var inactive_color = "#2A70AE";
    toggleDiv('resourcelinks1','none');
    document.getElementById('rlink1').style.color = inactive_color;
    toggleDiv('resourcelinks2','none');
    document.getElementById('rlink2').style.color = inactive_color;
    toggleDiv('resourcelinks3','none');
    document.getElementById('rlink3').style.color = inactive_color;
    toggleDiv('resourcelinks4','none');
    document.getElementById('rlink4').style.color = inactive_color;
}

function toggleAPP(ID, status){
    clearAPP();    
    toggleDiv(ID, status);
}
function clearAPP(){
    toggleDiv('mission','none');
    toggleDiv('appintro','none');
    toggleDiv('elementsdetail','none');
}

function submit_form(){
    uname = document.form1.username.value;
    pwd = document.form1.password.value;    
    if(uname == "revo" && pwd == "demo"){
        return true;
    }else{
        alert("Please enter correct Username and Password");
        document.form1.username.focus();
        return false;
    }
}

function newwin(url,w,h)  {
    if((w==0) && (h==0)){
        window.open(url,"_blank","status=0,scrollbars=1,resizable=1,toolbar=1,location=0,width="+self.outerWidth+",height="+self.outerHeight);
    }else{
        window.open(url,"_blank","status=0,scrollbars=1,resizable=0,toolbar=0,location=0,width="+w+",height="+h);
    }
}

function validateForm(f){
    var missing = "";
    var invalid = "";

    // required fields for InfoForms
    if(f['email_address'] != null){
        if(f['email_address'].value == ''){
            missing = missing + "Email Address.\n";
        }else{        
            if(f['email_address'].value.indexOf('@') < 0){
                invalid = invalid + "Your email address does not appear valid - please supply a valid email address.\n";
            }
        }
    }
    if(f['fullname'] != null){
        if(f['fullname'].value == ''){
            missing = missing + "Full Name.\n";
        }
    }
    if(f['phone'] != null){
        if(f['phone'].value == ''){
            missing = missing + "Phone Number.\n";
        }else{
            if(ValidPhone(f['phone'].value) != ''){
                invalid = invalid + "Your phone number does not appear valid - please supply a valid 10 digit phone number.\n";
            }
        }
    }
    if(f['org-name'] != null){
        if(f['org-name'].value == ''){
            missing = missing + "Organization Name.\n";
        }
    }
    if(f['business-name'] != null){
        if(f['business-name'].value == ''){
            missing = missing + "Business Name.\n";
        }
    }
    if(f['property-name'] != null){
        if(f['property-name'].value == ''){
            missing = missing + "Property Name.\n";
        }
    }
    if(f['role'] != null){
        if(f['role'].options.selectedIndex < 0){
            if(f['p'].value == 'Giving'){
                missing = missing + "You forgot to tell us if you are a 501(c) organization. Please answer either Yes or No.\n";
            }else if(f['p'].value == 'OnSite'){
                if(f['role-other'].value == ''){
                    missing = missing + "You forgot to tell us your role.\n";
                }
            }
        }
    }    
    if(f['website'] != null){
        if(f['website'].value == ''){
            missing = missing + "Website.\n";
        }
    }
    if(f['property-website'] != null){
        if(f['property-website'].value == ''){
            missing = missing + "Property Website.\n";
        }
    }
     if(f['num-units'] != null){
        if(f['num-units'].value == ''){
            missing = missing + "Number of Units.\n";
        }
    }
    
    if(missing != ''){
        // show missing fields
        alert('Some fields appear incomplete, please complete the following fields:\n' + missing);
        return false;
    }else if(invalid != ''){
        // show invalid message
        alert('There was a problem with some of the data you supplied, please review the following fields and messages:\n' + invalid);
        return false;
    }else{
        return true;
    }
}

function validateApp(f){
	// add form validation code here
	var missing = "";
    var invalid = "";
	var fields_missing = false;
	if (f['1_legal_business_name'].value == ""){
		fields_missing = true;
		missing = missing + "\n> Legal Business Name";
		f['1_legal_business_name'].style.color = "ff0000";
	}
		
	if (fields_missing == true){
		alert('Some fields appear incomplete, please complete the following fields:\n' + missing);
        return false;
    }else if(invalid != ''){
        // show invalid message
        alert('There was a problem with some of the data you supplied, please review the following fields and messages:\n' + invalid);
        return false;
	} else {
		return true;
	}
}

function ValidPhone(aphone)
{
    var valid = "0123456789";
    if(aphone==""){
         return "Phone Number";
    }
    //if number of character in phone field is not equal 10 - display warning and return false
    if(aphone.length !=10){
        return "Invalid phone number length! Please try again.";
    }
    //check each character entered in the phone field 
    for (var i=0; i < aphone.length; i++){
        //put in temp variable each character, one at a time.
        temp = "" + aphone.substring(i, i+1);
        //check index of a phone character in the "valid" variable.
        // if temp contains a character which is not in "valid" variable, 
        //then valid.indexOf(temp) will be -1, otherwise it may be 0.1.2.3.4.5.6.7.8 or 9
        if (valid.indexOf(temp) == "-1"){
            return "Invalid characters in your phone. Please try again.";
        }
    }
    //if all conditions are passed, then return true
    return "";
}

