var loading_text="<div style='margin-top:15px;margin-left:5px;'><img src=include/images/loading.gif />&nbsp;<b>Loading.....</b></div>";

function  show_image_details(id){

 win=dhtmlwindow.open("ajaxbox", "ajax", "index.php?module=front:home&action=show_details&id="+id, "Tour Place", "width=550px,height=300px,left=30px,top=20px,resize=1,scrolling=1")
win.show();
win.moveTo('middle', 30);
}

function my_ajax(module,action,id,extra){
var URL = 'index.php?module='+module+'&action='+action;
if(id != undefined && id != ''){

URL = URL +'&id='+id;
}
if(extra != undefined && extra != ''){
URL = URL + extra;
}

//alert(URL);

new Ajax.Request( URL, {
  method: 'get',
  onSuccess: function(transport) 
  {
  var cnt=$('column2').innerHTML =transport.responseText;
  },
  onFailure: function()
  { 
  alert('Something went wrong...') 
  },
  onLoading: function()
  {
  var cnt=$('column2').innerHTML="loading...........";
  }

});
}

function popupWindow(url,width,height) {
  if(width=='undefined') width='400px';
  if(height=='undefined') height='400px';
  window.open(url,'popupWindow','toolbar=no,location=no,titlebar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',screenX=150,screenY=150,top=150,left=150').focus();
}

function openmypage(page,title,resize,width,height){
var wsize="width=315,height=400,";
if((width != undefined && width != '') && (height != undefined && height != ''))wsize="width="+width+",height="+height+",";
ajaxwin=dhtmlwindow.open("ajaxBox", "ajax", page, title, wsize+"center=1,resize="+resize+",scrolling=1");
ajaxwin.show();
}

function closemypage(){
dhtmlwindow.close(ajaxwin);
}

function delconfirm(module,id){
res = confirm('Are you sure you want to delete this?');
  if(res) { 
		my_ajax(module,'delete',id);		
		}
}


function deactive(module,id) {
        res = confirm('Are you sure you want to deactivate this?');
        if(res) { 
		my_ajax(module,'deactivate',id);		
		}
}
function active(module,id) {
        res = confirm('Are you sure you want to activate this?');
        if(res) { my_ajax(module,'activate',id);}
}
function setfrontpage(module,id) {
	my_ajax(module,'setfrontpage',id);
}
function unsetfrontpage(module,id) {
	my_ajax(module,'unsetfrontpage',id);
}




function aform_submit(form){
$(form).request({
  onComplete: function(transport){$('column2').innerHTML=transport.responseText;},
  onLoading: function(){var cnt=$('column2').innerHTML=loading_text;}
})
}


function del_submit(form){
$(form).request({
  onComplete: function(transport){$('column2').innerHTML=transport.responseText;},
  onLoading: function(){var cnt=$('column2').innerHTML=loading_text;}
})
}
function make_check(a_formelement, a_value, a_form)
{

    var l_formelement = a_formelement;
    if (l_formelement) {
        if (l_formelement.length) {
            for (i=0;i<l_formelement.length;i++) {
                l_formelement[i].checked=a_value;
            }
        }
        else{
            l_formelement.checked = a_value;
        }
    }
	a_form.sel_all.checked=a_value;
}

function del_confirm(form)
{

var agree=confirm("Are you sure you wish to continue?");
if (agree)
{
	del_submit(form);
}
else
	return false ;
}


function show_hide(id)
{
	
if (id==1)
{
var f1=$('step_1');
var f2=$('step_2');
var f3=$('step_0');
}
else if (id==2)
{
var f1=$('step_2');
var f2=$('step_1');
var f3=$('step_0');
}
var venu=$('venu_id').value;
var date1=$('date1').value;
var date2=$('date2').value;
if ((venu=='')||(date1=='')||(date2==''))
{
	alert('Please check the availability');
}
else
{
f1.style.display="block";
f2.style.display="none";
f3.style.display="none";
}
}

function random_bannerAds(){

new Ajax.Updater('topbanner', 'index.php?module=front:home&action=show_bannerads', {
onComplete: function(transport) {
}
});
}

function showParameterDefinition (parameterType,id)
{
	//alert(parameterType);
	new Ajax.Updater('parameterDefinition_'+id, 'index.php?module=back:modulemanager&action=newType&parameterType='+parameterType+'&paraid='+id, 
					 {
						 onComplete: function(transport) {}
					 });
}

function addRow(id){
	id=id+1;
	alert(id);
	new Ajax.Updater('parameter_'+id, 'index.php?module=back:modulemanager&action=newType&queryType=addRow&paraid='+id, {onComplete: function(transport) {}});	
}
function deleteRow(id){
	alert(id);
	new Ajax.Updater('parameter_'+id, 'index.php?module=back:modulemanager&action=newType&queryType=delRow&paraid='+id, {onComplete: function(transport) {}});	
}
function sectioncategory(sectionid){
	//alert(sectionid);
	var req = 'index.php?module=back:content&action=category&sectionid='+sectionid;
	new Ajax.Updater('category', req, {onComplete: function(transport) {
															//alert(req);
															}});	
}
function linktomore(id){
	//alert(id);
	var req = 'index.php?module=front:home&action=linktomore&moduleid='+id;
	new Ajax.Updater('productBox', req, {onComplete: function(transport) {
															//alert(req);
															}});	
}
function validateEmail(id)  
{  
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(id);  
}  
function newsletterFormSubmit(name, email, subscription){
	//alert(name +" "+ email +" "+ subscription);
	//is_empty(name);
	if(name.toUpperCase() != 'navn' && name != '' && email.toUpperCase() != 'email' && email != '' && validateEmail(email) && (subscription == '0' || subscription == '1') && subscription != ''){
		var req = 'index.php?module=front:home&action=newsletter&sub_name='+name+'&sub_email='+email+'&subscription='+subscription;
		//alert(req);
		new Ajax.Updater('newsletterMessageBox', req, {onComplete: function(transport) {
																//alert(req);
																}});	
	}else{
		alert("Fill out the fields correctly");
	}
}

function confirmSubmit()
{
var agree=confirm("Are you sure you wish to continue?");
if (agree)
	return true ;
else
	return false ;
}
function validation_check(field)
{
var to_test=$(field).value;
if (to_test=='')
alert('Please Fill the field Correctly');
}

function changeStatus(uid,stat){

var URL = 'index.php?module=back:user&action=status:'+uid+'&stat='+stat;
new Ajax.Request( URL, {
  method: 'get',
  onSuccess: function(transport) {    
  },
  onFailure: function(){ alert('Something went wrong...') },
  onLoading: function(){var cnt=$('column2').innerHTML=loading_text;}

});
}

function changeAccess_level(uid,stat){

var URL = 'index.php?module=back:user&action=access_level:'+uid+'&stat='+stat;
new Ajax.Request( URL, {
  method: 'get',
  onSuccess: function(transport) {    
  },
  onFailure: function(){ alert('Something went wrong...') },
  onLoading: function(){var cnt=$('column2').innerHTML=loading_text;}

});
}

var oldLink = null;
//setActiveStyleSheet(document.getElementById("defaultTheme"), "Aqua");
// code to change the active stylesheet
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
    // if we add this call we close the calendar on single-click.
    // just to exemplify both cases, we are using this only for the 1st
    // and the 3rd field, while 2nd and 4th will still require double-click.
    cal.callCloseHandler();
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    // we already have some calendar created
    _dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(1, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    // cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    _dynarch_popupCalendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
  _dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = el;                 // inform it what input field we use

  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

// If this handler returns true then the "date" given as
// parameter will be disabled.  In this example we enable
// only days within a range of 10 days from the current
// date.
// You can use the functions date.getFullYear() -- returns the year
// as 4 digit number, date.getMonth() -- returns the month as 0..11,
// and date.getDate() -- returns the date of the month as 1..31, to
// make heavy calculations here.  However, beware that this function
// should be very fast, as it is called for each day in a month when
// the calendar is (re)constructed.
function isDisabled(date) {
  var today = new Date();
  return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}

function flatSelected(cal, date) {
  var el = document.getElementById("preview");
  el.innerHTML = date;
}

function showFlatCalendar() {
  var parent = document.getElementById("display");

  // construct a calendar giving only the "selected" handler.
  var cal = new Calendar(0, null, flatSelected);

  // hide week numbers
  cal.weekNumbers = false;

  // We want some dates to be disabled; see function isDisabled above
  cal.setDisabledHandler(isDisabled);
  cal.setDateFormat("%A, %B %e");

  // this call must be the last as it might use data initialized above; if
  // we specify a parent, as opposite to the "showCalendar" function above,
  // then we create a flat calendar -- not popup.  Hidden, though, but...
  cal.create(parent);

  // ... we can show it here.
  cal.show();
}

function selectType(formName) {
	var form = $(formName);
	var type = $(formName).type.value;
	var type_id = $(formName).type_id.value;

	if ( (type != "separator") && ( form.name.value == "") ){
		alert( "Item must have a Title" );
		form.type.value='';
		form.name.focus();
		return false;
	}
	
	if( type_id == 0 ){
		alert( "Please select a display area" );
		form.type.value='';
		form.type_id.focus();
		return false;
	}
	if( type == 0 ){
		alert( "Please select a Type" );
		form.type.focus();
		return false;
	}  
	
	var page ='';
	var title ='';
	var val = $(formName).type.value;
	//alert(val);
	if(val=='module'){
		page = 'index.php?module=back:menumanager&action=selectModule';
		title = 'Select a module';
		document.getElementById('link').value = 'index.php?module=front:';
		openmypage(page,title,'0','650','500');
	}else if(val=='staticcontent'){
		page = 'index.php?module=back:menumanager&action=selectContent';
		title = 'Select an Article';
		document.getElementById('link').value = 'index.php?module=front:home&action=content';
		openmypage(page,title,'0','650','500');
	}else if(val=='categorylist'){
		page = 'index.php?module=back:menumanager&action=categorylist';
		title = 'Select a Category';
		document.getElementById('link').value = 'index.php?module=front:home&action=categorylist';
		openmypage(page,title,'0','650','500');
	}else if(val=='sectionlist'){
		page = 'index.php?module=back:menumanager&action=sectionlist';
		title = 'Select a Section';
		document.getElementById('link').value = 'index.php?module=front:home&action=sectionlist';
		openmypage(page,title,'0','650','500');
	}else if(val=='contentsectionlist'){
		page = 'index.php?module=back:menumanager&action=contentsectionlist';
		title = 'Select a content to show with its section';
		document.getElementById('link').value = 'index.php?module=front:home&action=contentsectionlist';
		openmypage(page,title,'0','650','500');
	}else if(val=='externallink'){
		 //alert('External Link');
		var d=$('link');
		d.readOnly=false;
		//document.getElementById("link").readOnly=false
	
	}


	
}

function selectComponentType(formName, paramLink) {
	//alert(paramLink);
	var form = $(formName);

	var page ='';
	var title ='';
	var val = $(formName).type.value;
	//alert(val);
	if(val=='module'){
		page = 'index.php?module=back:menumanager&action=selectModule';
		title = 'Select a module';
		if(document.getElementById('link')){
			document.getElementById('link').value = 'index.php?module=front:';
		}else if(document.getElementById('params_link')){
			document.getElementById('params_link').value = 'index.php?module=front:';
		}
		
		openmypage(page,title,'0','650','500');
	}else if(val=='staticcontent'){
		page = 'index.php?module=back:menumanager&action=selectContent';
		title = 'Select an Article';
		if(document.getElementById('link')){
			document.getElementById('link').value = 'index.php?module=front:home&action=content';
		}else if(document.getElementById('params_link')){
			document.getElementById('params_link').value = 'index.php?module=front:home&action=content';
		}
		
		openmypage(page,title,'0','650','500');
	}else if(val=='categorylist'){
		page = 'index.php?module=back:menumanager&action=categorylist';
		title = 'Select a Category';
		if(document.getElementById('link')){
			document.getElementById('link').value = 'index.php?module=front:home&action=categorylist';
		}else if(document.getElementById('params_link')){
			document.getElementById('params_link').value = 'index.php?module=front:home&action=categorylist';
		}
		openmypage(page,title,'0','650','500');
	}else if(val=='sectionlist'){
		page = 'index.php?module=back:menumanager&action=sectionlist';
		title = 'Select a Section';
		if(document.getElementById('link')){
			document.getElementById('link').value = 'index.php?module=front:home&action=sectionlist';
		}else if(document.getElementById('params_link')){
			document.getElementById('params_link').value = 'index.php?module=front:home&action=sectionlist';
		}
		
		openmypage(page,title,'0','650','500');
	}else if(val=='contentsectionlist'){
		page = 'index.php?module=back:menumanager&action=contentsectionlist';
		title = 'Select a content to show with its section';
		if(document.getElementById('link')){
			document.getElementById('link').value = 'index.php?module=front:home&action=contentsectionlist';
		}else if(document.getElementById('params_link')){
			document.getElementById('params_link').value = 'index.php?module=front:home&action=contentsectionlist';
		}
		
		openmypage(page,title,'0','650','500');
	}else if(val=='externallink'){
		 //alert('External Link');
		var d=$('link');
		d.readOnly=false;
		//document.getElementById("link").readOnly=false
	
	}


	
}


function SelectModule(modulename, title, action) {
	alert(modulename + title + action);
	var modaction = '';	
	//index.php?module=front:home&action=content
			var linkval = document.getElementById('link').value;
			if(action != undefined && action !=''){
				modaction = '&action=' + action;	
				}
			modulename = modulename.substr(4);
			document.getElementById('link').value = linkval + modulename + modaction;	
			
			document.getElementById('id_name').value = title;			
}

function SelectArticle(id, title, object) {
	//alert(title);
		if(document.getElementById('link')){
			var linkval = document.getElementById('link').value;
			document.getElementById('link').value = linkval + '&id=' + id;			
		}else if(document.getElementById('params_link')){
			var linkval = document.getElementById('params_link').value;
			document.getElementById('params_link').value = linkval + '&id=' + id;			
		}
		document.getElementById(object + '_name').value = title;
}

function writeDynaListbvbv( selectParams, source, key, orig_key, orig_val ) {
	
	var html = '\n	<select ' + selectParams + '>';
	var i = 0;
	for (x in source) {
		if (source[x][0] == key) {
			var selected = '';
			if ((orig_key == key && orig_val == source[x][1]) || (i == 0 && orig_key != key)) {
				selected = 'selected="selected"';
			}
			html += '\n		<option value="'+source[x][1]+'" '+selected+'>'+source[x][2]+'</option>';
		}
		i++;
	}
	html += '\n	</select>';

	document.writeln( html );
}
							
		var originalOrder 	= '';
		var originalPos 	= 'left';
		var orders 			= new Array();	// array in the format [key,value,text]
		
	orders[0] = new Array( "right","0","0::Key Concepts" );
	orders[1] = new Array( "right","2","2::Polls" );
	orders[2] = new Array( "right","3","3::Who\'s Online" );
	orders[3] = new Array( "right","4","4::Sponsors Links" );
	orders[4] = new Array( "right","5","5::Advertisement" );
	orders[5] = new Array( "right","6","6::Statistics" );
	orders[6] = new Array( "right","7","7::Random Image" );
	orders[7] = new Array( "imageflow","0","0::ImageFlow" );
	orders[8] = new Array( "user1","0","0::Banner Slogan" );
	orders[9] = new Array( "user1","2","2::Latest News" );
	orders[10] = new Array( "top","0","0::Newsflash" );
	orders[11] = new Array( "user4","0","0::Search" );
	orders[12] = new Array( "user3","0","0::Top Menu" );
	orders[13] = new Array( "banner","0","0::Banners" );
	orders[14] = new Array( "breadcrumb","0","0::Breadcrumbs" );
	orders[15] = new Array( "left","0","0::Main Menu" );
	orders[16] = new Array( "left","2","2::Related Items" );
	orders[17] = new Array( "left","3","3::Login Form" );
	orders[18] = new Array( "left","4","4::Resources" );
	orders[19] = new Array( "left","5","5::User Menu" );
	orders[20] = new Array( "left","6","6::Example Pages" );
	orders[21] = new Array( "left","7","7::Archive" );
	orders[22] = new Array( "left","8","8::Sections" );
	orders[23] = new Array( "left","9","9::Wrapper" );
	orders[24] = new Array( "left","10","10::Feed Display" );
	orders[25] = new Array( "footer","0","0::Footer" );
	orders[26] = new Array( "user2","0","0::Registration fees" );
	orders[27] = new Array( "user2","2","2::Popular" );
	orders[28] = new Array( "syndicate","0","0::Syndication" );	
	
function allselections() {
	var e = document.getElementById('selections');
		e.disabled = true;
	var i = 0;
	var n = e.options.length;
	for (i = 0; i < n; i++) {
		e.options[i].disabled = true;
		e.options[i].selected = true;
	}
}
function disableselections() {
	var e = document.getElementById('selections');
		e.disabled = true;
	var i = 0;
	var n = e.options.length;
	for (i = 0; i < n; i++) {
		e.options[i].disabled = true;
		e.options[i].selected = false;
	}
}
function enableselections() {
	var e = document.getElementById('selections');
		e.disabled = false;
	var i = 0;
	var n = e.options.length;
	for (i = 0; i < n; i++) {
		e.options[i].disabled = false;
	}
}
function previewImage( list, image, base_path, multiple ) {
	var srcImage;
	
	//alert(list + '\n' + image + '\n' + base_path);
	form = document.edit_module;
	//alert(list.length);
	//srcList = eval( "form." + list );
	if(multiple)
		srcList = eval( "form." + "elements['" + list+ "[]']");
	else
		srcList = eval( "form." + list );
	srcImage = eval( "document." + image );
	//alert(srcImage);
	//alert(srcList.length + ' ' + srcImage.length);
	var srcOption = srcList.options[(srcList.selectedIndex < 0) ? 0 : srcList.selectedIndex];
	//alert(srcOption.length);
	var fileName = srcOption.text;
	var fileName2 = srcOption.value;
	//alert(fileName.length + " " + fileName2.length );
	if(srcImage){
		if (fileName.length == 0 || fileName2.length == 0) {
			srcImage.src = 'include/images/blank.gif';
		} else {
			srcImage.src = base_path + fileName2;
		}
	}
	//alert(srcImage.src);
}	


function previewFile( list, image, base_path, multiple ) {
	var srcImage;
	
	//alert(list + '\n' + image + '\n' + base_path);
	form = document.edit_module;
	//alert(list.length);
	//srcList = eval( "form." + list );
	if(multiple)
		srcList = eval( "form." + "elements['" + list+ "[]']");
	else
		srcList = eval( "form." + list );
	srcImage = eval( "document." + image );
	//alert(srcImage);
	//alert(srcList.length + ' ' + srcImage.length);
	var srcOption = srcList.options[(srcList.selectedIndex < 0) ? 0 : srcList.selectedIndex];
	//alert(srcOption.length);
	var fileName = srcOption.text;
	var fileName2 = srcOption.value;
	var fileSplit = fileName2.split('.');
	var ext = fileSplit[fileSplit.length - 1].toLowerCase();
	//alert(ext);
	//alert(fileName.length + " " + fileName2.length );
	if(srcImage){
		if (fileName.length == 0 || fileName2.length == 0) {
			srcImage.type = 'image/gif';
			srcImage.data = 'include/images/blank.gif';
		} else {
			if(ext == 'jpg' || ext == 'jpeg'){
				srcImage.type = 'image/jpeg';
			}else if(ext == 'gif'){
				srcImage.type = 'image/gif';
			}else if(ext == 'png'){
				srcImage.type = 'image/png';
			}else if(ext == 'html' || ext == 'htm' || ext == 'txt'){
				srcImage.type = 'text/html';
			}else if(ext == 'wav'){
				srcImage.type = 'audio/x-wav';
			}else if(ext == 'swf'){
				srcImage.type = 'application/x-shockwave-flash';
			}
			srcImage.data = base_path + fileName2;
		}
	}
}	


