function showdiv(divid) {
   $('#'+divid).show();
}

function hidediv(divid) {
   $('#'+divid).hide();
}

function isValidEmail(str) {	
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function isValidUrl(str){
	if (str != '')
		return str.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
	else
		return true;
}

function validateAgreedToTerms(value){
	if (!value){
		alert('You must agree to the terms and conditions before you can save your changes.');
		return false;
	} else {
		return true;
	}
}

function validateEnterSolutionStep1Form(theform){

	if (!theform.chk_Is_agree_to_terms.checked){
		alert('You must agree to the terms and conditions.');
		return false;
	} 
	
	if (!theform.txt_Solution_title.value){
		alert('You must give your solution a name.');
		return false;
	} 
	if (!theform.txt_Solver_role.value){
		alert('You must enter your role.');
		return false;
	} 
	
	
	/*
	if (!theform.txt_Solution_challenge.value){
		alert('You must provide a brief description of the challenge this Solution solves.');
		return false;
	} 
	if (!theform.txt_Solution_description_brief.value){
		alert('You must provide brief description of the Solution.');
		return false;
	} 
	if (!theform.txt_Solution_description_details.value){
		alert('You must provide a detailed description of the Solution.');
		return false;
	}
	*/
	return true;
	
}

function validateEnterSolutionStep2Form(theform){
	
	if (!theform.txt_Solver_first_name.value){
		alert('You must provide a first name.');
		return false;
	} 
	
	if (!theform.txt_Solver_last_name.value){
		alert('You must provide a last name.');
		return false;
	} 
	if (!theform.txt_Solver_email.value){
		alert('You must provide an email address.');
		return false;
	}
	if (!isValidEmail(theform.txt_Solver_email.value)){
		alert('Please enter a valid email address.');
		return false;
	}
	
	if (!isValidUrl(theform.txt_Solver_url.value)){
		alert('Please enter a valid website address.');
		return false;
	}

	return true;
	
}

function checkForHttp(url,textfield_id){
	// has neither http or https been enterd at the beginning of the string
	if ((url.substr(0,7) != 'http://') && (url.substr(0,8) != 'https://')){
		document.getElementById(textfield_id).value = 'http://' + url;
	}
}

function disableInputField(id){
	$("#"+id).attr("disabled","disabled");
}

function enableInputField(id){
	$("#"+id).removeAttr("disabled");
	$("#"+id).focus();
}