function showTip1(id,e){
    evt = (e) ? e : window.event;
    $(id).setStyle({left: Event.pointerX(evt) + 20});
    $(id).setStyle({top: Event.pointerY(evt) -50});
    $(id).setStyle({display:'block'});

}
function showTip(id){
	$(id).style.display = 'block';
}

function closeTip(id){
	document.getElementById(id).style.display = 'none';
}

function changeAutorenew(area) {
	var url = '/member/autorenew/' + area;
	new Ajax.Request(url);
}

function MM_openBrWindow(theURL,winName,features) {
		window.open(theURL,winName,features);
}


//red coloring of wrong fields
function redDist(fieldname)	{
	if(document.getElementById(fieldname))
		document.getElementById(fieldname).style.backgroundColor="#FFC1BF";
}

//white coloring of right fields
function whiteDist(fieldname){
  if(document.getElementById(fieldname))
	document.getElementById(fieldname).style.backgroundColor="";
}
/*function isEmail(s){                  //.[\w\.-]{2,4}
	var regexp = /^[\w\.-]+@[\w\.-]+\.[\w\.-]{2,4}$/
	return regexp.test(s);
}*/

function elementHide(elementId) {
	var styleObject = getStyleObject(elementId);
   if (styleObject)
		styleObject.display = 'none';
}

function elementShow(elementId) {
	var styleObject = getStyleObject(elementId);
   if (styleObject)
		styleObject.display = 'block';
}
function getStyleObject(objectId) {
	// cross-browser function to get an object's style object given its id
	if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
	} else {
	return false;
	}
} // getStyleObject
// get value of radio group selected element
function getRadioValue($radioId) {
		var el = document.getElementById($radioId);
		//DEBUG
		if (!el) { alert('Bad id -' + $radioId + ' - ' + el);}
		if (el.type != 'radio') alert('Not radio - ' + $radioId);
		var r = document.getElementsByName($radioId);
		var val = -1;
	    for (var j = 0; j < r.length; j++)
			if (r[j].checked)
				val = r[j].value;
		return val;
}

//==========================================================================================
// Validation function

var alertMsg = "";

function addError(errorMsg) {
	alertMsg += errorMsg + '\r\n';
}
function valid_required(fieldName, val) {
	if(val.length == 0) {
		addError(fieldName + ' field required.');
		return false;
	} else
		return true;

}
function valid_match(text, val1, val2) {
	if (val1 != val2) {
		addError(text + ' - must match');
		 return false;
	} else
		return true;
}

function valid_notSelected(fieldName, selectElemet) {
	if (selectElemet.value == '0') {
 	   addError('Please select ' + fieldName);
	   return false;
	} else
		return true;
}


function valid_url(fieldName, val) {
	if (!isUrl(val)) {
 	   addError(fieldName + ' has wrong url format');
   		return false;
	} else
		return true;
}

function valid_email(fieldName, val) {
	if (!isEmail(val)) {
 	   addError(fieldName + ' has wrong email format');
	   return false;
	} else
		return true;
}

function isInteger(n){
  var RegExp = /^(\d+)$/;
  return RegExp.test(n);
}

function isDate(n){
  var RegExp = /^\d{4}-\d{1,2}-\d{1,2}$/;
  return  n.match(RegExp);
}

function isValidDate(n){ // YYYY-MM-DD
	var RegExp = /^([2][0-9][0-9][7-9]|[2][0-9][1][0-9]|[2][1][0-9][0-9])-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])$/;
	return  n.match(RegExp);
}

function isUrl(s) {
	var regexp = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/
	return regexp.test(s);
}

function isEmail(s) {//       /^[\w\._=-]+@[\w\.-]+\.[\w\.-]{2,4}$/
	var regexp = /^[^.@=~,][\w\._=-]+@[^.@=~,][\w\.-]+\.[a-zA-Z]{2,4}$/
	return regexp.test(s);
}

function findtwins(logname) { //AJAX :) seeking of member mail login name duplets in DB
	request = createRequest();
	var sURL = Config.PROJECT_URL + "functions/seektwins.php?logname="+logname;
	request.open( "GET", sURL, false);
	request.send("");
	//ERRORS-----------------------------------------------------
    if(request.status != 200){
        alert("Response problem. status code = " + request.status);
		return false;
	}
	if(request.readyState != 4) {
		alert("A problem occurred with communicating between "+
               "the XMLHttpRequest object and the server program.");
		return false;
	 // END ERRORS--------------------------------------------------
	}else{
		if (request.responseText=="p")//member exist
			return false;
		else
			if (request.responseText=="l")// member not exist
			return true;
	}
}


// END Validation function
//==========================================================================================

//Creates emerging <div> with the comment
function showactivitydetails(t, e){
     if(t == 'wap' || t == 'sss' || t == 'np' || t == 'ss' || t == 'ws' || t == 'wwr') {
        path = '/registration/detInfo/';
     }

     if(t == 1){
        path = '/item/getDet/';
     }
     if(t == 'Worship Alive Plus' || t == 'Worship Alive-remix' || t == 'Sermon Series Services' || t == 'Special Services' || t == 'nuParables' || t == 'Worship Share' || t == 'Worship Services' || t == 'WSS' ){
        path = '/member/detInfo/';
     }
     if(t == 'Worship_Alive_Plus' || t == 'Worship_Alive-remix' || t == 'Sermon_Series_Services' || t == 'Special_Services' || t == 'nuParables' || t == 'Worship_Share' || t == 'Worship_Services' || t == 'WSS' ){
        path = '/member/detInfo/';
     }
     evt = (e) ? e : window.event;
     ajax_tooltipObj = document.createElement('DIV');
     ajax_tooltipObj.style.position = 'absolute';
     ajax_tooltipObj.style.display='block';
     ajax_tooltipObj.style.left = Event.pointerX(evt) + 15;
     ajax_tooltipObj.style.top = Event.pointerY(evt) - 80;
     ajax_tooltipObj.id = 'ajax_tooltipObj';
     document.body.appendChild(ajax_tooltipObj);
     new Ajax.Updater ('ajax_tooltipObj',path+t+'/',{});

}
//Does <div> with the comment invisible
function hideactivitydetails(){
    document.body.removeChild(ajax_tooltipObj);
}
/** @author Irina Melkostupova.
*   Formation emerging <div> in which the detailed information about item is displayed
*
*
**/
function itemsdetails(t){
    path = '/item/tooltipDet/';
    _w   = screen.width/2;
    $('toolDiv').style.left = _w-200;
    $('toolDiv').style.display = 'block';

    new Ajax.Updater ('toolDiv',path+t,{});

}
//Does tooltipObj with the item's details invisible
function hidetooltip(){
    $('toolDiv').style.display = 'none';
}

