var noneBlock = function () {
    var a_nB, o_showHide, s_nBit, i_nBdisplay, i, a_arguments = noneBlock.arguments;
    for (i = 0; i < a_arguments.length; i = i + 1) {
        a_nB = a_arguments[i].split("!");
        s_nBit = a_nB[0];
        i_nBdisplay = a_nB[1];
        o_showHide = document.getElementById(s_nBit);
        o_showHide.style.display = (i_nBdisplay === "0") ? "none": (i_nBdisplay === "1") ? "block": (i_nBdisplay === "2") ? "inline": "";
    }
};
var statelist = function () {
    var input = document.getElementById('state'),
    opt = input.getElementsByTagName('optgroup'),
    label = document.getElementById('label-state'),
    country = document.getElementById('country');
    switch (country.value) {
    case "United States":
        label.style.display = "block";
        input.style.display = "block";
        opt[0].style.display = "block";
        opt[1].style.display = "none";
        break;
    case "Canada":
        label.style.display = "block";
        input.style.display = "block";
        opt[1].style.display = "block";
        opt[0].style.display = "none";
        break;
    default:
        label.style.display = "none";
        input.style.display = "none";
        input.value = "";
        break;
    }
};
var comlength = function () {
    var com = document.getElementById('description'),
    count = document.getElementById('comment-length'),
    output = count.getElementsByTagName('em')[0],
    i = com.value.length;
    output.innerHTML = i;
    count.style.display = "block";
    if (i >= 130) {
        output.style.color = "#990";
    }
    if (i >= 151) {
        output.style.color = "#900";
    }
    if (i <= 129) {
        output.style.color = "#090";
    }
};
var mediakit = function () {
    var field = [],
    fail,
    country = document.getElementById('country').value,
    warning = document.getElementById('form-alert'),
    li = warning.getElementsByTagName('li'),
    space,
    email,
    phone,
    a,
    i,
    j,
    k,
    x;
    fail = function (x) {
        field[i].style.background = "#def";
        warning.style.display = "block";
        li[x].style.display = "list-item";
    };
    field[0] = document.getElementById('company');
    field[1] = document.getElementById('first_name');
    field[2] = document.getElementById('last_name');
    field[3] = document.getElementById('city');
    field[4] = document.getElementById('state');
    field[5] = document.getElementById('email');
    field[6] = document.getElementById('phone');
    field[7] = document.getElementById('description');
    space = new RegExp(/^\s+$/g);
    email = new RegExp(/^[\w\-\.]+@([\w\-]+\.)+[\w\-]{2,4}((\s*[,;]*\s*)?[\w\-\.]+@([\w\-]+\.)+[\w\-]{2,4})*$/g);
    phone = new RegExp(/^(1\s*[\-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[\-\/\.]?\s*(\d{3})\s*[\-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX]|[eE][xX][tT])\.?\s*(\d+))*$/);
    warning.style.display = "none";
    for (k = 0; k < li.length; k += 1) {
        li[k].style.display = "none";
    }
    for (i = 0; i < field.length; i += 1) {
        a = field[i].value;
        field[i].style.background = "#fff";
        if (i === 4) {
            if ((country === "United States" || country === "Canada") && (a === null || a === "")) {
                fail(i);
            } else if (country === "United States" && (a === "Alberta" || a === "British Columbia" || a === "Manitoba" || a === "New Brunswick" || a === "Newfoundland and Labrador" || a === "Northwest Territories" || a === "Nova Scotia" || a === "Ontario" || a === "Prince Edward Island" || a === "Quebec" || a === "Saskatchewan" || a === "Yukon")) {
                fail(10);
            } else if (country === "Canada" && (a === "Alabama" || a === "Alaska" || a === "Arizona" || a === "Arkansas" || a === "California" || a === "Colorado" || a === "Connecticut" || a === "Delaware" || a === "District of Columbia" || a === "Florida" || a === "Georgia" || a === "Hawaii" || a === "Idaho" || a === "Illinois" || a === "Indiana" || a === "Iowa" || a === "Kansas" || a === "Kentucky" || a === "Louisiana" || a === "Maine" || a === "Maryland" || a === "Massachusetts" || a === "Michigan" || a === "Minnesota" || a === "Mississippi" || a === "Missouri" || a === "Montana" || a === "North Carolina" || a === "North Dakota" || a === "Nebraska" || a === "Nevada" || a === "New Hampshire" || a === "New Jersey" || a === "New Mexico" || a === "New York" || a === "Ohio" || a === "Oklahoma" || a === "Oregon" || a === "Pennsylvania" || a === "Rhode Island" || a === "South Carolina" || a === "South Dakota" || a === "Tennessee" || a === "Texas" || a === "Utah" || a === "Verginia" || a === "Vermont" || a === "Washington" || a === "West Virginia" || a === "Wisconsin" || a === "Wyoming")) {
                fail(11);
            }
        } else if (i === 7) {
            if (a.length > 150) {
                fail(i);
            }
        } else {
            if (field[i] && li[i]) {
                if (a === null || a === "" || a === String(space.exec(a)) || typeof(a) === "undefined") {
                    fail(i);
                }
                for (j = 0; j < field.length; j += 1) {
                    if (j === 4 || j === 7) {
                        continue;
                    }
                    if (field[j] && li[j]) {
                        if (field[j].value === null || field[j].value === "" || field[j].value === String(space.exec(field[j].value)) || typeof(field[j].value) === "undefined") {
                            field[j].style.background = "#def";
                            warning.style.display = "block";
                            li[j].style.display = "list-item";
                        }
                    }
                }
            }
        }
        if (i === 5 && li[5].style.display === "none") {
            if (email.test(a) === false) {
                fail(8);
            }
        }
        if (i === 6 && li[6].style.display === "none") {
            if (a.match(phone) === null || a.match(phone).length < 3) {
                fail(9);
            }
        }
    }
    if (warning.style.display === "block") {
        return false;
    } else {
        return true;
    }
};

/* existing t4good scripts */
/* original script
var applcntMgr = function (s_id,o_linkId) {
	$(s_id).style.display = ($(s_id).style.display=='block')?'none':'block';
	o_linkId.innerHTML = (o_linkId.innerHTML == '+ Add a Team Member')?'- Remove Team Member':'+ Add a Team Member';
	document.getElementById('appCnt').value=($(s_id).style.display=='block')?parseInt(document.getElementById('appCnt').value)+1:parseInt(document.getElementById('appCnt').value)-1;
}*/

function applcntMgr(s_id,o_rdo){
  var myRdo = document.getElementsByName(o_rdo);
  var myDiv = document.getElementById(s_id);
  var myCount = document.getElementById('appCnt').value;
  // alert(myRdo[0].checked);
  if (myRdo[1].checked == true) {
     myDiv.style.display = 'block';
  } else {
	 myDiv.style.display = 'none';
  }
  if (myDiv.style.display == 'block') {
    myCount = parseInt(myCount) + 1;
  } else {
	if (myCount > 0) {
	  myCount = parseInt(myCount) - 1;
	}
  }
  //alert(myCount);
}

function highlightErr(s_theForm,a_fldList){
  for (i = 0; i < document.getElementById(s_theForm).elements.length; i++){
   for (x = 0; x < a_fldList.length; x++){ 
	if(a_fldList[x] == document.getElementById(s_theForm).elements[i].id){
 	   document.getElementById(s_theForm).elements[i].style.backgroundColor='#FFFFCC';
	}
   }	                      
  }
}

function showAddtl(i_addtl){
  for (i = 1; i <= i_addtl; i++){
 	document.getElementById("container"+i).style.display="block";                      
  }
}

function checkwdct(fname,tbox,tbhead,wlimit,alertbox,msg){
  var tb = tbox;
  var tbval = tb.value;
  var tbh = tbhead;
  var count = tbval.replace(/\S+/g,"a").replace(/\s+/g,"").length;
  if (count > wlimit) {
    var allwords = tbval.split(/\s+/g);
	tbval = "";
	for (var i = 0; i < wlimit; i++){
	  tbval += allwords[i] + (" ");
	}
	tb.value = tbval;
	count = tbval.replace(/\S+/g,"a").replace(/\s+/g,"").length;
  }
  tbh.innerHTML = count;
  if (tbh.innerHTML == wlimit) {
    var wlimitmsg=msg.replace("xx",wlimit);
	alertbox.innerHTML = wlimitmsg;
  } else {
	alertbox.innerHTML = "&nbsp;";
  }
}

function checkCharCount(element,currentCountElement,errorMsgElement,maxCount){
	var currentCount = element.value.length;
	currentCountElement.innerHTML = currentCount;
	errorMsgElement.innerHTML = (currentCount > maxCount) ? "You have exceeded the maximum number of characters." : "";
}

/*function hiliteRow() {
  var aRowElem = li.getElementsByTagName("a");
  aRowElem.length = 0;
  var sOdd = true;
  for (var i = 0; i < aRowElem.length; i++) {
    if (sOdd) {
	  aRowElem[i].className = 'hilite';
	  sOdd = false;
	} else {
	  aRowElem[i].className = '';
	}
  }
}*/

