// Framebuster
if (parent.frames.length > 0){
	/*top.location.replace(document.location); */
}


// JavaScript Document
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function reloadwindow() {
  document.location.reload();
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

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

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+'\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+'\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+'\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'\n'; }
  } if (errors) alert(errormsg+'\n'+errors);
  document.MM_returnValue = (errors == '');
}

function sendendForm(message) {
	alert(message);
}

function clearInputText(thefield){
	if (thefield.defaultValue==thefield.value){
		thefield.value = "";
	}
} 
function clearInputTextCustom(thefield, defValue){
	if (defValue==thefield.value){
		thefield.value = "";
	}
} 


function jumpmenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/* checkbox jump to page */
function jumpcheckbox(targetbox, url1, url2){
	if(targetbox.checked==true){
		document.location.href = url1;
	} else {
		document.location.href = url2;
	}
}

/* set image & text for image gallery */
function show_picture(image_id, image_url, text_id, text_value){
	if (image_url.length > 0){
		img_big = document.getElementById(image_id);
		if (img_big){
			img_big.src = image_url;
		}
	}
	if (text_value.length > 0){
		//document.getElementById(text_id).innerHTML = text_value;
	}
}

// formsubmit confirm
function confirmSubmit(msg){
	var agree=confirm(msg);
	if (agree){
		return true ;
	} else {
		return false ;
	}
}

/* ajax form validate function for autolist */
function ajaxform_validate_items(item, page_url, nr){

	var validateForm = $('#validate_'+item);
      
    $('#'+item).keyup(function () {
        var t = this; 
        //if (this.value != this.lastValue) {            
            if (this.timer) clearTimeout(this.timer);
            validateForm.removeClass('error').html('<img src="../media/image/ajax-loader.gif"/>');

            this.timer = setTimeout(function () {
                $.ajax({
                    url: page_url,
                    data: 'autolist_validate=' + t.value + '&autolist_validate_nr=' + nr,
                    dataType: 'json',
                    type: 'post',
                    success: function (j) {
                        validateForm.html(j.msg);
                    }
                });
            }, 500);
            this.lastValue = this.value;
        //}
    });
}


function change_bgimage(targ, img){ 
    document.getElementById(targ).style.backgroundImage = "url("+img+")"; 
} 



/// SWITCHBOX
function switchbox_one2two(menu, nonm) {
	m1len = menu.length ;
    for ( i=0; i<m1len ; i++){
        if (menu.options[i].selected == true ) {
            m2len = nonm.length;
            nonm.options[m2len]= new Option(menu.options[i].text, menu.options[i].value);
        }
    }

    for ( i = (m1len -1); i>=0; i--){
        if (menu.options[i].selected == true ) {
            menu.options[i] = null;
        }
    }
}

function switchbox_two2one(menu, nonm) {
    m2len = nonm.length ;
    for ( i=0; i<m2len ; i++){
        if (nonm.options[i].selected == true ) {
            m1len = menu.length;
            menu.options[m1len]= new Option(nonm.options[i].text, nonm.options[i].value);
			menu.options[m1len].selected = true;
        }
    }
    for ( i=(m2len-1); i>=0; i--) {
        if (nonm.options[i].selected == true ) {
            nonm.options[i] = null;
        }
    }
}

function switchbox_selectall() {
	
	for(j=0; j<switchbox_total.length; j++){
		tmp = switchbox_total[j];
		if(tmp.length == 0){
			tmp.options[0]= new Option('empty', 'empty');
			tmp.options[0].selected = true;
		}
		for (i=0; i<tmp.length; i++) {
			tmp.options[i].selected = true;
		}
	}
	for(j=0; j<imageswitchbox_total.length; j++){
		tmp = imageswitchbox_total[j];
		for (i=0; i<tmp.length; i++) {
			tmp.options[i].selected = true;
		}
	}
}
/// SWITCHBOX
function imageswitchbox_one2two(menu, nonm) {
	m1len = menu.length ;
    for ( i = (m1len -1); i>=0; i--){
        if (menu.options[i].selected == true ) {
            menu.options[i] = null;
        }
    }
}

function imageswitchbox_two2one(menu, nonm) {
	
	myText = document.getElementById('non_text');
    m2len = nonm.length ;
    for ( i=0; i<m2len ; i++){
        if (nonm.options[i].selected == true ) {
            m1len = menu.length;
            menu.options[m1len]= new Option(myText.value+' => '+nonm.options[i].text, myText.value+';'+nonm.options[i].text);
			menu.options[m1len].selected = true;
        }
    }
}
/// CHECK / UNCHECK all checkboxes with a specific name
function check_all_checkboxes(form_name, field_name, is_checked)
{
	if(!document.forms[form_name]){
		return;
	}

	var obj_checkboxes = document.forms[form_name].elements[field_name];
	if(!obj_checkboxes){
		return;
	}

	var checkbox_count = obj_checkboxes.length;
	if(!checkbox_count)
		obj_checkboxes.checked = is_checked;
	else
		// set the check value for all check boxes
		for(var i = 0; i < checkbox_count; i++)
			obj_checkboxes[i].checked = is_checked;
}

/// CHECK / UNCHECK all checkboxes with a specific name
function check_all_checkboxes(form_name, field_name, is_checked)
{
	if(!document.forms[form_name]){
		return;
	}

	var obj_checkboxes = document.forms[form_name].elements[field_name];
	if(!obj_checkboxes){
		return;
	}

	var checkbox_count = obj_checkboxes.length;
	if(!checkbox_count)
		obj_checkboxes.checked = is_checked;
	else
		// set the check value for all check boxes
		for(var i = 0; i < checkbox_count; i++)
			obj_checkboxes[i].checked = is_checked;
}

/// CHECK / UNCHECK all checkboxes with a specific name
function check_all_checkboxes_asoc(form_name, field_name, is_checked)
{
	if(!document.forms[form_name]){
		return;
	}

	var elements = document.forms[form_name].elements;
	if(!elements){
		return;
	}

	for (var name_element in elements){
		if (name_element.substring(0, field_name.length) == field_name){
			element = document.forms[form_name].elements[name_element];
			if (!element.disabled){
				element.checked = is_checked;
			}
		}
	}
}





