var maxCharacters = 140;

function updateCharCount()
{
    var questionHelp = document.getElementById("questionHelp");
    var count = questionTextBox.value.length;

    if (count > maxCharacters)
        questionHelp.style.display = 'none';
    
    var charactersLeft = maxCharacters - count;
    
    if (charactersLeft < 0)
        charactersLeft = 0;
    
    document.getElementById("characterCount").innerHTML = charactersLeft;
	
    if (count > maxCharacters)
        questionTextBox.value = questionTextBox.value.substring(0, maxCharacters);
}

function submitenter(myfield,e,button)
{
	var keycode;
	if (window.event)
		keycode = window.event.keyCode;
	else
		if (e) keycode = e.which;
	else 
		return true;

	if (keycode == 13)
	{
		button.click();
		return false;
	}
	else
		return true;
}

function focusTextarea()
{
    var questionHelp = document.getElementById("questionHelp");
    
    questionHelp.style.display = 'none';
    questionTextBox.style.display = '';
    questionTextBox.value = '';
    questionTextBox.focus();
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value)
{
	var expires = "";
	document.cookie = name+"="+value+expires+";path=/;";
}

function clearText(textarea)
{
    if (textarea.value == "Type here...")
    {
        textarea.value = "";
    }
}

function SelectValueSet(SelectName, Value)
{
    var SelectObject = document.getElementById(SelectName);

    for(index = 0; index < SelectObject.length; index++)
    {
        if (SelectObject[index].value == Value)
        {
            SelectObject.selectedIndex = index;
        }
    }
}

function showASBox()
{
    Page_ClientValidate();
    
    if (Page_IsValid)
    {
        showASBox2();
    }
}

function showASBox2()
{
    if (sContentIframe != null) {
        sContentIframe.src = "AntiSpamVerification.aspx";
        sWindowDiv.style.display = '';            
    }
}

function hideASBox()
{
    sWindowDiv.style.display = 'none';
}

function showIframe(id, url, ancho, alto, scrolling) 
{
    document.getElementById(id).innerHTML = "<iframe src='" + url + "' width='" + ancho + "' height='" + alto + "' scrolling='" + scrolling + "' frameborder='0'></iframe>";
}

function forEach(c,a,f){if(!c)return;if(Object.prototype.toString.apply(c)==='[object Array]'||(!(c instanceof Function)&&typeof c.length=='number')){if(c.forEach){c.forEach(a);}else for(var b=0,e=c.length;b<e;b++)a(c[b],b,c);}else for(var d in c)if(f||c.hasOwnProperty(d))a(c[d],d,c);}

function contentSize(){
    var a=document.body,c=document.documentElement,d=0,b=Math.max(Math.max(a.offsetHeight,a.scrollHeight)+a.offsetTop,Math.max(c.offsetHeight,c.scrollHeight)+c.offsetTop);
    if(a.offsetWidth<a.scrollWidth){d=a.scrollWidth+a.offsetLeft;}
    else forEach(a.childNodes,function(e){var f=e.offsetWidth+e.offsetLeft;if(f>d)d=f;});if(c.clientLeft>0)d+=(c.clientLeft*2);if(c.clientTop>0)b+=(c.clientTop*2);return [b,d];
}

function getWindowData(width, height) {
    var g = typeof window.screenX!='undefined'?window.screenX:window.screenLeft;
    var h = typeof window.screenY!='undefined'?window.screenY:window.screenTop
    var f = typeof window.outerWidth!='undefined'?window.outerWidth:document.documentElement.clientWidth;
    var e = typeof window.outerHeight!='undefined'?window.outerHeight:(document.documentElement.clientHeight-22);
    var j = width, c = height, d = parseInt(g+((f-j)/2),10), i = parseInt(h+((e-c)/2.5),10);
    return 'width='+j+',height='+c+',left='+d+',top='+i;
}

var w;
function openPopup(url, width, height) {
    var position = getWindowData(width, height);
    w = window.open(url, 'popupwindow', position + 'scrollbars=no,resizable=no');    
}

function closePopup() {
    if (w != null) { w.close(); }
}

var cH=0,cW=0,resized=false;
function resizeWindow()
{
    var data = contentSize();
    if ((document.all != undefined && cH == 0) || resized)
    {
        cH = data[0];
        resized = false;
    }
    if (data[0] != cH)
    {        
        window.resizeTo(data[1]+8 ,data[0]+81);
        cH = data[0];
        resized = true;
    }
    cW = data[1];
}

function setFocus(id)
{
    var el = document.getElementById(id);
    window.setTimeout(function() {window.focus();el.focus();}, 10);
}
