var firstLoop = true;
var emailexp = /^[a-z0-9][a-z_0-9\-\.]+@[a-z_0-9\.\-]+\.[a-z]{2,7}$/i

function reportChannel(url){
	var flip = document.getElementById('channel_report_confirm');
	if (flip.value == 'yes'){
		document.location.href = url+'/1';
	} else {
		alert('Please select the Yes option to confirm the report');
	}
}	

function isEmail(str) {
	return emailexp.test(str);
}

function isNumberKey(e){

	var key;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which 
	else
		return true;
   
	if ((key==null) || (key==0) || (key==8) || 
    	(key==9) || (key==13) || (key==27) )
		return true;   
		
	keychar = String.fromCharCode(key);
	var exp = /^[0-9\.]$/
	return exp.test(keychar);
}

function isAlphaNumKey(e){
	var key;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which 
	else
		return true;
   
	if ((key==null) || (key==0) || (key==8) || 
    	(key==9) || (key==13) || (key==27) )
		return true;   
		
	keychar = String.fromCharCode(key);
	var exp = /^[0-9a-zA-Z]$/
	return exp.test(keychar);
}

var mailtoexp = /^mailto:[a-z0-9][a-z_0-9\-\.]+@[a-z_0-9\.\-]+\.[a-z]{2,7}$/i

function isMailto(str) {
	return mailtoexp.test(str);
}

function isUrl(str) {	
    var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
    return v.test(str);
}

function checkLength(e,textfield){
	var key;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which
	else
		return true;

	if ((key==null) || (key==0) || (key==8) ||
    	(key==9) || (key==13) || (key==27) )
		return true;

	if (textfield.value.length > 500){
		return false;
	} else {
		return true;
	}
}

function checkLengthOnBlur(textfield){
	if (textfield.value.length > 500){
		textfield.value = textfield.value.substr(0,500);
		return false;
	} else {
		return true;
	}
}
///////////////////////////////////////////////////////////////
//FUNCIONES DE MANEJO DE COMBOS
///////////////////////////////////////////////////////////////
function selectInCombo(objCombo, paramerter){
    try{
        var count = objCombo.options.length;
        objCombo.selectedIndex = -1;
        
        for (i = 0; i < count; i++){
            if (objCombo.options[i].value == paramerter){
                objCombo.selectedIndex = i;
                return;
            }
        }
    }catch(e){

    }
}

function getComboText(objCombo, value){
    var count = objCombo.options.length;
    
    for (i = 0; i < count; i++){
        if (objCombo.options[i].value == value){
            return objCombo.options[i].text;
        }
    }
}

function getComboOption(objCombo, value){
    var count = objCombo.options.length;
    
    for (i = 0; i < count; i++){
        if (objCombo.options[i].value == value){
            return objCombo.options[i];
        }
    }
}

function removeAllOptions(objCombo) {
    for (i = objCombo.length; i >= 0; i--) {
        objCombo.remove(i);
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////

function validMessage() {
	var errores = "";

	var email = document.contact.email.value;
	if (!isEmail(email) || email.length < 8)
		errores+="* Type a valid e-mail address.\n";

	var name = document.contact.name.value;
	if (name.length < 3)
		errores+="* Type your Name.\n";

	var message = document.contact.message.value;
	if (message.length < 10)
		errores+="* Type your message.\n";

	if (errores!="") {
		alert(errores);
		return false;
	} else {
		return true;
	}
}

function bookmark(url,title){

	if (window.sidebar) { // Mozilla Firefox Bookmark

		window.sidebar.addPanel(title, url,"");

	} else if( window.external ) { // IE Favorite

		window.external.AddFavorite( url, title); 
		
	} else if(window.opera && window.print) { // Opera Hotlist

		return true; 
	}
	
}

function popup(url, name, height, width, scroll){
	window.open(url,name,"width="+width+",height="+height+",status=no,scrollbars="+scroll);
}
