/*
Module	: CAT
Functie	: Javascript functies
Datum	: 03-05-2006
*/

/********************************
	Functions by SmackWeb Design
*********************************/
//Function: When clicking on a form the field wil get the text that you gave along with 
//			the function.
function clearValue(form, input, setText){
	eval ( "document." + form + "." + input + ".value='" + setText + "';" );
};

//Function: When clicking outside a formfield that was selected the field will get the 
//			text that you gave along with the fucntion IF the field is empty or equal to
//			the other text that you send along in the function.
function checkBlur(form, input, current, getText){
	getValue = eval ( "document." + form + "." + input + ".value;" );

	if (getValue == "" || getValue == getText) {
		eval ( "document." + form + "." + input + ".value='" + current + "';" );
	} else {
		eval ( "document." + form + "." + input + ".value='" + getValue + "';" );
	};
};
/************************************
	End functions by SmackWeb Design
************************************/



function getTopMenuItem(url, id){
 mainFrame = document.getElementById('mainFrame');
 if (url.indexOf('?') > 0) 
  seperator = '&';
 else seperator = '?';
 mainFrame.location.href = url + seperator + 'menuid=' + id;
 return;
}

function priceonly(){
 if ((event.keyCode<48&&event.keyCode!=44&&event.keyCode!=45)||event.keyCode>57)
  return false
}

function changeClass(id, klasse){
 document.getElementById(id).className = klasse;
}

function accessDenied(){
 alert('Access denied');
}

function changeFont(f){
	
	document.getElementById('fontType').style.fontFamily = f.value;
}

function showSub(id){
 
 theRows=document.getElementById("dataTable").rows
 reg=new RegExp("^"+id)
 for (i=0;i<theRows.length;i++)
  if (reg.test(theRows[i].id))
     if  (theRows[i].style.display=="none") {
       theRows[i].style.display="";
	   src = 'min';
	 }else{
       theRows[i].style.display="none";
	   src = 'plus';
	 }

 document.getElementById('icon_' + id).src = 'images/icons/icon_' + src + '.gif';
}

function loadMainPage(page){
 if (page != '') parent.MAIN.location.href = page;
 return;
}

/*
============================================================================================
	Module specifieke functies
============================================================================================
*/
function closeFrame(num){
	currentSize = parent.catalogFrameSet.cols.split(",");
	if (num == 1){
		parent.catalogFrameSet.cols = '20,' + currentSize[1] + ',' + currentSize[2];
	}
	if (num == 2){
		parent.catalogFrameSet.cols = currentSize[0] + ',20,' + currentSize[2];
	}
	if (num == 3){
		parent.catalogFrameSet.cols = currentSize[0] + ',' + currentSize[1] + ',20';
	}
}

function deleteArtikelTechspec(id,parent,message){
 if (confirm(message)){
  a = document.getElementById('tb_tech' + id);
  a.style.display = 'none';
  
  b = document.getElementById(parent);
  b.name = b.name + '|deleted'
  //a.innerText = '';
 }
 return;
}

function Show_AjaxList(obj, opt1, opt2){		
		ajax_showOptions(obj,opt1,opt2);
}

function showElement(id){
	if (document.getElementById(id)){
		if (document.getElementById(id).style.display == 'none'){
			document.getElementById(id).style.display = '';
		}else{
			document.getElementById(id).style.display = 'none';
		}
	}
}

function closePage(nr){

	if (nr == 2)
 		parent.catalogFrameSet.cols = '250,100%,0%';

	if (nr == 3)
 		parent.catalogFrameSet.cols = '20,100%,0%';
	
	document.location.href = 'about:blank';
}

function saveLng(){
	document.lngFrm.action = 'save_language.asp';
	document.lngFrm.submit();
}

function changeClass(id, klasse){
 document.getElementById(id).className = klasse;
}

function showGroupEdit(id){
 a = document.getElementById(id);
 	if (a.style.display == 'none'){
		a.style.display = '';
	}else{
		a.style.display = 'none';
	}
}

function editZoekenGroep(id){
	document.location.href = '/sis/back/catalogus/?id=' + id;
}

function getGroup(type, level, id){

	if (type == 0){
		document.location.href = 'groepen.asp?level=' + level + '&id=' + id;
	}else{
		parent.FRAME2.document.location.href = 'groepen.asp?level=' + level + '&id=' + id;
	}
 
}

function createLng(){
	verstuur = true;
	for (i = 0; i <= document.lngFrm.length; i++){
		a = document.lngFrm[i];
		if (a.value == ''){
		 verstuur = false;
		}
	}

	if (verstuur == false){
		if (confirm('U heeft niet alle velden ingevuld. Weet u zeker dat u de language ') == true){
		
		}else{
		}
	}
}

function saveLngNew(){
	a = document.lngFrmNew.new1;
	if (a.value == ''){
		alert('U dient een variabele naam in te vullen');
		a.focus();
		return;
	}
	
	document.lngFrmNew.action = 'save_language.asp';
	document.lngFrmNew.submit();		
}

function RemoveItemsinSelect(id1){
  selectbox1 = document.getElementById(id1);
 
  if (selectbox1 != -1) {
    for(i=selectbox1.length-1; i>=0; i--)
    {
      if(selectbox1.options[i].selected)
      {
				selectbox1.options[i] = null;
      }
    }
  }
}


var http_request = false;
  
function AsyncHttpRequest(url, arg ,stype, xml) {
		http_request = false;
		
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }           
        }

        if (!http_request) {
            alert('Your browser badly enough doesnt support Ajax Scripting. Try ');
            return false;
        }
        // http_request.onreadystatechange = alertContents;		
		if (stype == 'POST') {
			http_request.open(stype, url, false);
			http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			http_request.send(arg);
		} else {
			http_request.open(stype, url + "?" + arg, false);
			http_request.send(null);
		}	
		
		if (http_request.readyState == 4) {
            if (http_request.status == 200) {
   				if (xml == true) {
					if (!http_request.overrideMimeType) {						
						//if (http_request.responseXML == null) {						
							var xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
							try {
								xmlDocument.loadXML(http_request.responseText);					
							} catch(e) { alert("Could not parse XML file.") }
							return xmlDocument;							
						// } else {
						//	return http_request.responseXML;
						// } 
					} else {
						return http_request.responseXML;
					}
				} else {
					return http_request.responseText;
				}
            } else {
				if (xml == true) {
			    alert('Er is een probleem met het halen van gegevens. HTTP Error:' + http_request.status );
				} else {
					return http_request.status;
				}
            }
        }		
	}

function editTab(id1, id2, id3){
 document.location.href = 'edit.asp?tab=' + id1 + '&item=' + id2;
 return;
}

function editCustomer(id1, id2, id3){
 document.location.href = 'edit.asp?id=' + id1;
 return;
}

function editTechspec(id1, id2, id3){
 document.location.href = 'edit.asp?id=' + id1;
 return;
}

function editUnit(id1, id2, id3){
 document.location.href = 'edit.asp?id=' + id1;
 return;
}

function editEmail(id1, id2, id3){
 document.location.href = 'edit.asp?id=' + id1;
 return;
}

function deleteTab(id1, id2, id3){
 if (confirm('Weet u zeker dat u deze tab wilt verwijderen?')) document.location.href = 'delete.asp?tab=' + id1 + '&item=' + id2;
 return;
}

function editColumn(id1, id2, id3){
 document.location.href = 'edit.asp?column=' + id1 + '&tabel=' + id2;
 return;
}

function deleteColumn(id1, id2, id3){
 if (confirm('Weet u zeker dat u deze kolom wilt verwijderen?')) document.location.href = 'delete.asp?column=' + id1 + '&tabel=' + id2;
 return;
}

function deleteCustomer(id1, id2, id3){
 if (confirm('Weet u zeker dat u dit item wilt verwijderen?')) document.location.href = 'delete.asp?id=' + id1;
 return;
}

function deleteEmail(id1, id2, id3){
 if (confirm('Weet u zeker dat u dit item wilt verwijderen?')) document.location.href = 'delete.asp?id=' + id1;
 return;
}

function deletePage(id, parent, message){
 if (confirm(message)){
  document.location.href = 'delete_page.asp?id=' + id + '&open_node=' + parent;
 }
 return;
}

function shopItems(id){
 location.href = 'items.asp?group_id=' + id;
}

function shopItems2(id){
 location.href = 'items.asp?id=' + id;
}

function deleteMenuItem(id, parent, message){
 if (confirm(message)){
  document.location.href = 'delete_menuopties.asp?id=' + id + '&open_node=' + parent;
 }
 return;
}


function getTab(id){
	tab_left = document.getElementById('tab_left_' + id);
	tab_right = document.getElementById('tab_right_' + id);
	tab_middle = document.getElementById('tab_middle_' + id);
	tab_div = document.getElementById('div_tab_' + id);
	
	// Verbergen van de alle tabs
	divs = document.getElementsByTagName('div');
	for (i = 0; i <= divs.length-1; i++){
		div_class = divs[i].className;
		if (div_class == 'tab_content'){
			divs[i].style.display = 'none';
		}
	}

	// Resetten van actieve tab
	tabs_active = document.getElementsByTagName('td');
	for (i = 0; i <= tabs_active.length-1; i++){
		tab_class = tabs_active[i].className;
		if (tab_class == 'tab_active') tabs_active[i].className = 'tab';
		if (tab_class == 'tab_left_active') tabs_active[i].className = 'tab_left';
		if (tab_class == 'tab_right_active') tabs_active[i].className = 'tab_right';
	}
	
	// Gezelecteerde tab laten zien
	if (tab_middle.className == 'tab_active'){
		tab_left.className = 'tab_left';
		tab_right.className = 'tab_right';
		tab_middle.className = 'tab';
		tab_div.style.display = 'none';
	}else{
		tab_left.className = 'tab_left_active';
		tab_right.className = 'tab_right_active';
		tab_middle.className = 'tab_active';
		tab_div.style.display = '';
	}
}

function editItem(parent, id2, id3){
 document.location.href = 'edit.asp?parent=' + parent;
 return;
}

function getLocation(url){
 document.location.href = url;
}

function clearField(id){
 document.getElementById(id).value = '';
 return;
}

function deleteUser(id, parent, message){
 if (confirm(message)){
  document.location.href = 'delete_user.asp?id=' + id + '&open_node=' + parent;
 }
 return;
}

function insertGroup(id, id2, id3){
 parent.document.getElementById("FRAME2").src="edit.asp?parent=" + id;
 return;
}

function changeRowColorItem(id, color){
 document.getElementById(id).bgColor = color;
}

function editGroep(id, id2, id3){
 parent.catalogFrameSet.cols = '20,100%,0%';
 parent.document.getElementById("FRAME2").src="edit.asp?id=" + id;
 return;
}

function editArtikel(id, id2, id3){
 parent.parent.catalogFrameSet.cols = '20,20,100%';
 parent.parent.FRAME3.document.location.href = '/sis/back/catalogus/edit_artikel.asp?artikelnr=' + id + "&id=" + id2;
 return;
}


function edit(id, id2, id3){
 document.location.href = 'edit.asp?id=' + id;
 return;
}

function editMenuItem(id, id2, id3){
 document.location.href = 'edit_menuopties.asp?id=' + id;
 return;
}

function uploaden(field, newdir, stayindir, add){
  winstyle = "width=800, height=550, screenX=300, screenY=300, resizable=yes";
  window.open('/sis/back/jscripts/filebrowser/index.asp?field=' + field + '&newdir=' + newdir + '&stayindir=' + stayindir + '&add=' + add,null,winstyle);
}

function detailsGroupLink(id){
   winstyle = "width=650, height=550";
   window.open('itemselect.asp?id=' + id,'Details',winstyle);
}

function deleteGroup(url, extrastr){
  if (confirm('Weet u zeker dat u dit item wilt verwijderen? / Are you sure you want to delete this item?') == true)
  location.href = url + extrastr;
  return;
}
function deleteItem(url, extrastr){
  if (confirm('Weet u zeker dat u dit item wilt verwijderen? / Are you sure you want to delete this item?') == true)
  location.href = url + extrastr;
  return;
}

function deleteTechspec(id, parent, message){
 if (confirm(message)){
  document.location.href = 'delete.asp?id=' + id + '&open_node=' + parent;
 }
 return;
}

function deleteUnit(id, parent, message){
 if (confirm(message)){
  document.location.href = 'delete.asp?id=' + id + '&open_node=' + parent;
 }
 return;
}

function editUser(id, id2, id3){
 document.location.href = 'edit_user.asp?id=' + id;
 return;
}

function showDiv(id){
 elm = document.getElementById('div_' + id);
 if (elm.style.display == 'none'){
  elm.style.display = '';}
 else{
  elm.style.display = 'none';}
}

function getLanguage(id){
 divs = document.getElementsByTagName('div');
 for (i = 0; i <= divs.length-1; i++){
  indexof = divs[i].id.indexOf('page_');
  if (indexof != -1){
	divs[i].style.display = 'none';
  }
 }
 divs = document.getElementsByTagName('div');
 for (i = 0; i <= divs.length-1; i++){
  indexof = divs[i].id.indexOf('selection_');
  if (indexof != -1){
	divs[i].className = 'language_selection';
  }
 }

 divs = document.getElementsByTagName('tr');
 for (i = 0; i <= divs.length-1; i++){
  indexof = divs[i].id.indexOf('page_');
  if (indexof != -1){
	divs[i].style.display = 'none';
  }
 }
 divs = document.getElementsByTagName('tr');
 for (i = 0; i <= divs.length-1; i++){
  indexof = divs[i].id.indexOf('selection_');
  if (indexof != -1){
	divs[i].className = 'language_selection';
  }
 }

 divs = document.getElementsByTagName('tbody');
 for (i = 0; i <= divs.length-1; i++){
  indexof = divs[i].id.indexOf('page_');
  if (indexof != -1){
	divs[i].style.display = 'none';
  }
 }
 divs = document.getElementsByTagName('tbody');
 for (i = 0; i <= divs.length-1; i++){
  indexof = divs[i].id.indexOf('selection_');
  if (indexof != -1){
	divs[i].className = 'language_selection';
  }
 }

 document.getElementById('selection_' + id).className = 'language_selection_active';
 document.getElementById('page_' + id).style.display = '';
 return;
}

function submitForm(id1, id2, id3){
 document[id2].submit();
}

function getMyColor(t)	{
  var hbcms_color_picker_path = "color_picker.asp";
  var old_color = t.value.replace('#','');
  //if ( document.all) {
	//  var color = showModalDialog(hbcms_color_picker_path+ '?field='+t.id+'&current=' + old_color, "", "dialogWidth:30.5em; dialogHeight:20.0em; status:0");
	//  if (color != null ) {
	//	  t.value = color;
	//	  t.style.color = color;
	//  }  else {
	//	  t.focus();
	//  }
 // } else {
	  var color = window.open(hbcms_color_picker_path+ '?field='+t.id+'&current=' + old_color,  "hbcmsPop", "top=200,left=200,scrollbars=no,dialog=yes,modal=yes,width=440,height=340,resizable=no,aaa=rt4");
 // }
  return;
}

function insertPage(parent, id2, id3){
 document.location.href = 'edit_page.asp?parent=' + parent;
 return;
}

function editPage(id, id2, id3){
 document.location.href = 'edit_page.asp?id=' + id;
 return;
}

function insertKlant(parent, id2, id3){
 document.location.href = 'edit.asp?parent=' + parent;
 return;
}

function insertMenuItem(parent, id2, id3){
 document.location.href = 'edit_menuopties.asp?parent=' + parent;
 return;
}
