BE = '1px solid #f00';
BP = '1px solid #ccc';
zdx = 1;
activeMoveWindowID = '';

// ******[ Hshowe or show the element on Mouse Over / Mouse Out ]******
function showHideMenu(show,hide,num){
	for (var i = 1; i<=num; i++) {
		if ($(hide+i)) {$(hide+i).style.display='none';}
	}
	if($(show)){$(show).style.display='block';}
}

// ******[ Get the radio button value ]******
function getRadioValue(idOrName) {
    var value = null;
    var element = document.getElementById(idOrName);
    var radioGroupName = null;
   
    // if null, then the id must be the radio group name
    if (element == null) {
        radioGroupName = idOrName;
    } else {
        radioGroupName = element.name; 
    }
   
    if (radioGroupName == null) return null;
   
    var radios = document.getElementsByTagName('input');
    for (var i=0; i<radios.length; i++) {
        var input = radios[ i ];      
        if (input.type == 'radio' && input.name == radioGroupName && input.checked) {       
            value = input.value;
            break;
        }
    }
    return value;
}

// ******[ Get Page Size ]******
function getPageSize(){	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	//scroll page
	var x,y;
	if (self.pageYOffset){// all except Explorer
		scrollLeft = self.pageXOffset;
		scrollTop = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop){// Explorer 6 Strict
		scrollLeft = document.documentElement.scrollLeft;
		scrollTop = document.documentElement.scrollTop;
	}
	else if (document.body){ // all other Explorers
		scrollLeft = document.body.scrollLeft;
		scrollTop = document.body.scrollTop;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,scrollLeft,scrollTop) 
	return arrayPageSize;
}

// ******[ Set Element Attributes ]******
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

// ******[ Show Overlay ]******
function showOverlay(canclose){
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.style.zIndex=++zdx;
	if(canclose)objOverlay.onclick = function() { hideOverlay(); return false; }
	objBody.appendChild(objOverlay);
	//get the actual max hieght for use in overlay
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);
	$('overlay').style.display = '';
}

// ******[ Close Overlay ]******
function hideOverlay(){
	if($('overlay'))$('overlay').style.display = 'none';
	if($(activeMoveWindowID))$(activeMoveWindowID).style.display = 'none';
}

// ******[ Auto resize Overlay ]******
function autoResizeOverlay(){
	if($('overlay')){
		var arrayPageSize = getPageSize();
		Element.setHeight('overlay', arrayPageSize[1]);
	}
}

// ******[ New Move Windows ]******
function moveWindow(filename,title,id, width, height, classname){
	activeMoveWindowID = id;
	var title = "<DIV CLASS=\""+classname+"_titlebar\" style=width:"+width+"px onClick=\"changeZindex(\'"+id+"\')\"><DIV CLASS=\""+classname+"_title\" ID=\"pull_down_handle\">"+title+
	"</DIV><DIV CLASS=\""+classname+"_close\">"+
	"<IMG SRC=\"images/close.gif\" CLASS=\""+classname+"_button\" TITLE=\"Close\" onClick=\"close_menu('"+id+"');hideOverlay();\"></DIV></DIV>";
	$(id).className = classname;
	$(id).style.width = width+'px';
	$(id).innerHTML = title+"<DIV ID=\"content_"+id+"\" style=width:"+width+"px CLASS=\""+classname+"_content\" STYLE=\"Height:"+height+"\" onClick=\"changeZindex(\'"+id+"\')\">Loading... Please wait...</DIV>";
	var arrayPageSize = getPageSize();
	cleftpos = (eval(arrayPageSize[2])-eval(width)) / 2;
	ctoppos = (eval(arrayPageSize[5])+50) ;
	$(id).style.top = ctoppos+'px';
	$(id).style.left = cleftpos+'px';
	$(id).style.opacity  = '1';
	$(id).style.zIndex = ++zdx;
	new Draggable($(id),{handle:classname+"_titlebar"});
	Effect.Appear(id);
	var myAjax = new Ajax.Request(filename, { method: 'get', onComplete: function(oR) {
																			if (200 == oR.status){
																				$("content_"+id).innerHTML = oR.responseText;
																			}
																			else $("content_"+id).innerHTML = "Result: "+oR.status+" Cannot get the content";
																		 }
											}
								 );
}

function changeZindex(id){
	activeMoveWindowID = $(id).id;
	$(id).style.zIndex = ++zdx;
}

function close_menu(id){
	$(id).style.display='none';
}

// ******[ Strip whitespace from the beginning and end of a string ]******
function trim(str){
	return str.replace(/^\s+|\s+$/g,'');
}

// ******[ Check if a string is in valid email format.  ]******
function isEmail(str){
	var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return regex.test(str);
}

// ******[ pages navigation ]******
function setPageNumber(page,fileurl,rpTD){
	var url= fileurl+"&page="+page;
	$('toprightCornerMsg').innerHTML = 'Loading Content . . . Please Wait . . . ';
	$('toprightCornerMsg').style.display = '';
	var myAjax = new Ajax.Request(url, { method: 'get', onComplete: function(oR){
		$('toprightCornerMsg').style.display = 'none';
		$(rpTD).innerHTML = oR.responseText;
	
	} });
}
