/*

*/

/*
	function to send a popup window
*/
function PopUpWin(url,height,width, rez, scroll){
	//alert(url);
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var attr='resizable='+rez+',left=' + left + ',top=' + top +', scrollbars = '+ scroll;
	if(height&&width){
		var left = (screen.width - width) / 2;
		var top = (screen.height - height) / 2;
	    attr='height=' + height + ',width=' + width + ',resizable='+rez+',left=' + left + ',top=' + top+', scrollbars = '+scroll;
	}
	window.open(url,'_blank',attr);
}

function OpenNewWin(url){
	window.open(url);
}

/** Sets focus on the elem */
function setFocus(idElem){
	var elem = document.getElementById(idElem);
	if(elem){
		elem.focus();
	}
}

function SendSaveTemplateSettings(){
	var id=document.getElementById("id_template").value;
	var name=document.getElementById("TemplateName").value;
	var url="TemplateSettings.aspx?id=" + id + "&TemplateName=" + name + "&action=editName";
	window.opener.location=url;
	self.close();
}
function ConfirmDeleteTemplate(id,name){
	if(confirm("Are you sure you want to delete the Template ?")){
	
		var url="TemplateSettings.aspx?id=" + id + "&TemplateName=" + name + "&action=deleteTemplate";
		window.location=url;
	}
}
function SendCopyTemplateSettings(){
	var id=document.getElementById("id_template").value;
	var name=document.getElementById("TemplateName").value;
	var url="TemplateSettings.aspx?id=" + id + "&TemplateName=" + name + "&action=copyTemplate";
	window.opener.location=url;
	self.close();
}

function ConfirmAction(msg,action_to_perform){
	if(confirm(msg)){
		if(document.getElementById("action_performed")){
			var elem_action=document.getElementById("action_performed");
			if(elem_action.type=="text"||elem_action.type=="hidden"){
				elem_action.value=action_to_perform;
			}
			
		}
		return true;
	}
	else{
		if(document.getElementById("action_performed")){
			var elem_action=document.getElementById("action_performed");
			if(elem_action.type=="text"||elem_action.type=="hidden"){
				elem_action.value="";
			}
			
		}
		return false;
	}
}
function PromptText(msg,default_value,action_to_perform,destination_field){
	var name = prompt(msg, default_value);
	if(document.getElementById("action_performed")&&null!=name){
		var elem_action=document.getElementById("action_performed");
		if(elem_action.type=="text"||elem_action.type=="hidden"){
			elem_action.value=action_to_perform;
		}
	}
	if(document.getElementById(destination_field)&&null!=name){
		var elem_value=document.getElementById(destination_field);
		if(elem_value.type=="text"||elem_value.type=="hidden"){
			elem_value.value=name;
		}
	}	
	if(null!=name){
		return true;
	}
	return false;
}

//-------------------------------------------------
//				jscalendar
//-------------------------------------------------

//Update the date in the input field.
function selected(cal, date) {
	cal.sel.value = date; 
  	if (cal.dateClicked){
		cal.callCloseHandler();
	}
}

function closeHandler(cal) {
  	cal.hide();// hide calendar
  	_dynarch_popupCalendar = null;
}

// This function shows the calendar under the element having the given id.
function showCalendar(id, format, showsOtherMonths, character) {
	var el = document.getElementById(id);
	if (_dynarch_popupCalendar != null) {
		_dynarch_popupCalendar.hide();
	} else {
		var cal = new Calendar(0, null, selected, closeHandler);
		
		cal.weekNumbers = false;
		
		cal.showsTime = false;
		
		if (showsOtherMonths) {
			cal.showsOtherMonths = true;
		}
		
		_dynarch_popupCalendar = cal;
		
		cal.create();
	}
	if(character){
		_dynarch_popupCalendar.setDateFormat(character + format + character);
	}else{
		_dynarch_popupCalendar.setDateFormat(format);
	}
	_dynarch_popupCalendar.parseDate(el.value);
	_dynarch_popupCalendar.sel = el;
	
	_dynarch_popupCalendar.showAtElement(el, "Br");
	
	return false;
}

//-------------------------------------------------
function trim(text){
	text = leftTrim(text);
	return rightTrim(text);
}

function rightTrim(text){
	while(text.charAt((text.length -1))==" " || text.charAt((text.length -1))=="	"){
		text = text.substring(0,text.length-1);
	}
	return text;
}

function leftTrim(text){
	while(text.charAt(0)==" " || text.charAt(0)=="	"){
		text = text.replace(text.charAt(0),"");
	}
	return text;
}

