/*******************************************
 * AlexanderReyna.com
 *   Various global javascript 
 * 
 * author:  Grace Pok
 * version 1.0
 *----------------------------------------*/



//returns true if the string starts with "error:".  case INsensitive
//  -- for ajax response
function is_error(str){
	
	if(str.substr(0,6).toLowerCase() == 'error:') {
		return true;
	}
	return false;
}



//friendly error message to display to user.
//hopefully these never ever get called.
function alert_user(str){
	alert("Sorry, we encountered a problem.\nHost said:  " + str + "\nPlease contact the administrator.");
}

//generic failure/exception callbacks for ajax calls
function alert_failure(){
	alert("Sorry, we encountered a problem\n while communicationg with the host.\nPlease contact the administrator.");
}


// strip the specified prefix from the string
function strip_prefix(str, header){
	if (str.substr(0, header.length).toLowerCase() == header.toLowerCase()) {
		str = str.substr(header.length);
		str = str.strip();
	}
	return (str);
}
/* 
 * function to check valid email address
 * Code from: http://www.white-hat-web-design.co.uk/articles/js-validation.php
 */
function is_valid_email(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(address) == false) {
      return false;
   }
   return true;
}


/* 
 * Input:  Date in YYYY-MM-DD
 * Output:  Date in [MM.DD.YYYY]  (with brackets)
 */
function format_date_pastpoll(str) {
	var token = str.split('-');
	return '[' + token[1] + '.' + token[2] + '.' + token[0] + ']';
}

function openWindow_PictureUpload() {
 	window.open('upload_picture.php','_blank','scrollbars=yes,resizable=yes,location=no,width=480,height=280');
}

function closeWindow_PictureUpload() {
	window.close();
}
