﻿
//Een nieuwe class declareren
function common(){

//declaring the array that will be used for preloading images
this.pre_img = new Array();
this.debug=false;

	this.console =function(msg) {
		if(this.debug){
		document.getElementById('console').innerHTML=document.getElementById('console').innerHTML+msg+'<br>';
		}
	}
	
	this.getElementsByClassName =function(element, tag, classes) {
	var arrElements = (tag == "*" && element.all)? element.all : element.getElementsByTagName(tag);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
		if(typeof classes == "object"){
			for(var i=0; i<classes.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + classes[i].replace(/\-/g, "\\-") + "(\\s|$)"));
			}
		}
		else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + classes.replace(/\-/g, "\\-") + "(\\s|$)"));
		}
		var oElement;
		var bMatchesAll;
		for(var j=0; j<arrElements.length; j++){
			oElement = arrElements[j];
			bMatchesAll = true;
			for(var k=0; k<arrRegExpClassNames.length; k++){
				if(!arrRegExpClassNames[k].test(oElement.className)){
					bMatchesAll = false;
					break;
				}
			}
			if(bMatchesAll){
				arrReturnElements.push(oElement);
			}
		}
	return (arrReturnElements)
	}

	this.preload_images = function(img) {
		if(document.images){
		var preload_image_object = new Image();	
		var i = 0;
			for(i=0; i<img.length; i++) {
			//alert('preloading '+img[i]);
			this.console('preloading '+img[i])
			preload_image_object.src = img[i];
			}
		}
	}

	this.changeSrc = function(id, src){
	//alert('changin '+id+' with '+src);
	document.getElementById(id).src=src;
	}

	//called at 'window.onload';
	this.externallinks = function() {
	 if (!document.getElementsByTagName) return;
	 var anchors = document.getElementsByTagName('a');
	 for (var i=0; i<anchors.length; i++) {
	   var anchor = anchors[i];
	   if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external')
		 anchor.target = '_blank';
		}
	}

	this.val_by_id = function(id){		
	var value = document.getElementById(id).value;
	return value;
	}
	
	this.val_by_name = function(form, name){
	var value = document.forms[form][name].value;
	return value;
	}
	
	this.getradiovalue=function(form, name){
	var radioObj = document.forms[form][name]; 
		if(!radioObj)
		return "";
	var radioLength = radioObj.length;
		if(radioLength == undefined)
			if(radioObj.checked)
			return radioObj.value;
			else
			return "";
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
			return radioObj[i].value;
			}
		}
	}
	
	this.setradiovalue=function(form, name, newvalue){
	var radioObj = document.forms[form][name]; 
		if(!radioObj)
		return;
		var radioLength = radioObj.length;
		if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
		}
		for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
			if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
			}
		}
	}
		
		
	this.get_content_from_object = function(id){
		if(document.getElementById(id)){
		return document.getElementById(id).innerHTML;
		}
	}
	
	this.sent_content_to_object = function(object, content){
		if(document.getElementById(object)){
		document.getElementById(object).innerHTML=content;
		}
	}

	this.change_class = function(id, newClass) { 
		if(document.getElementById(id)){
		document.getElementById(id).className=newClass; 
		}
	}
	
	this.string_only_spaces = function(string){
		//going to the num of chars of the string
		for(c=0; c<string.length; c++){
		var current_string_char=string.substring(c,c+1);
			if(current_string_char!=" "){
			return false
			}
		}
	return true;
	}
	
	this.valid_email = function(email) {
		if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		return true;
		}
		else{
		return false;
		}
	}
	
	this.isCharAndNum = function(str){
		var expr = /(?=.*\d)(?=.*[a-zA-Z])/;
		if (expr.test(str)){
			return true;
		}else{
		return false;
		}
	}

	this.enableform = function(form, enable) {	
		if(form=='*'){
			for (formIndex=0; formIndex<document.forms.length; formIndex++){
				for(x=0;x<document.forms[formIndex].length;x++){
				document.forms[formIndex].elements[x].disabled=true;
				}
			}
		}
		else{
		var el = document.forms[form].elements;
			for(var i=0;i<el.length;i++){
				if(enable==false){
				el[i].setAttribute('disabled',true);
				}
				else{
				el[i].removeAttribute('disabled');
				}
			}
		}
	}
	
	
	this.getabsy = function(id){	
		if(document.getElementById(id)){
		var ret = 0;
		div=document.getElementById(id);
			while( div != null ){
			ret += div.offsetTop;
			div = div.offsetParent;
			}
		return ret;
		}
	}
	
	this.getabsx = function(id){	
		if(document.getElementById(id)){
		var ret = 0;
		div=document.getElementById(id);
			while( div != null ){
			ret += div.offsetLeft;
			div = div.offsetParent;
			}
		return ret;
		}
	}
	
	//to ammount label
	this.num2amountlabel = function(num, lan){
	var sep='.';
		if(lan=='nl'){
		sep=',';
		}
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num.replace(',','.') + sep + cents);
	}

			
	this.goto_url = function(form, url, send_method){
		if(send_method=='submit'){
		//defining form action
		document.forms[form].action = url;
		//submitting the form
		document.forms[form].submit();
		}
		else{
		document.location = url;
		}
	}
	
	this.open_win = function(url){
	window.open(this.ptr+url, 'new_window');
	}
	
	this.valign_colomns = function(){
	//layout actions on page load and change
	this.setmainmenu_level2();
	}
	
	
	this.onload_action = function(){
	this.pre_img[this.pre_img.length]=this.ptr+'CmWare/images/website/ajaxloader.gif';
	this.externallinks();
	this.valign_colomns();
	}
	

	//CUSTOMER SPECIFIC METHODS
		
	this.setmainmenu_level2 = function(){
		if(document.getElementById("menu211218518_lev2_childs")){
		var num_of_childs=this.val_by_id('menu211218518_lev2_childs');
		}
		else{
		var num_of_childs=0;	
		}
		if(document.getElementById("bl13001") && num_of_childs>0){
		var h=$("#bl12971 ul ul").height();
		//scretchng the dropzone height (so that submenu will fitt)
		document.getElementById('bl13001').style.height=(55+h)+'px';
		var x=this.getabsx('bl13001');
		var y=this.getabsy('bl13001')+55;
		//positioning the real submenu (as a floating object) to the available location
		$("#bl12971 ul ul").css("left",x);
		$("#bl12971 ul ul").css("top",y);
		$("#bl13001").css("visibility","visible");
		$("#bl12971 ul ul").css("visibility","visible");
		}
		else{
		//	alert("no menu");
		$("#bl13001").css("display","none");
		$("#loc10 ul ul").css("display","none")
		}
	
	}
	
	/*this.setmainmenu_level2 = function(){
		if(document.getElementById('menu211218470_lev2') && document.getElementById('submenu')){
		var x=this.getabsx('submenu');
		var y=this.getabsy('submenu');
		//positioning the real submenu (as a floating object) to the available location
		document.getElementById('menu211218470_lev2').style.left=x+'px';
		document.getElementById('menu211218470_lev2').style.top=y+'px';	
		//scretchng the dropzone height (so that level2menu will fitt)
		var dropzone_height=document.getElementById('menu211218470_lev2').offsetHeight;
		document.getElementById('submenu').style.height=dropzone_height+10+'px';
		//
		this.sent_content_to_object('h1_mainmenu-lev2', this.val_by_id('menu211218470_lev1_label'));
		}
		else if(!document.getElementById('menu211218470_lev2') && document.getElementById('submenu')){
		//alert('no submenu but a unneeded wrapper instead');
		//hyding the unneeded placeholder
		document.getElementById('bl13001').style.display='none';
		}
	}*/


}

//declating the first instance
var sw = new common();

	//declaring the 'all_labels' class
	function language_labels(){
	//emty class (only declared for creating 'label-instance')
	}

//declaring the 'label-instance' (this will be extended epending on the modules)
var label = new language_labels();


    function create_http_object(){
	var ActiveXTypes = [
		"Microsoft.XMLHTTP",
		"MSXML2.XMLHTTP.5.0",
		"MSXML2.XMLHTTP.4.0",
		"MSXML2.XMLHTTP.3.0",
		"MSXML2.XMLHTTP"
	];
	for( var i = 0; i < ActiveXTypes.length; i++ ){
		try
		{
			return new ActiveXObject( ActiveXTypes[i] );
		}
		catch( e )
		{ }
	}
	try{
		return new XMLHttpRequest();
	}
	catch( e ){ }
	return false;
    }

    function make_request(url, callback_function, http_method, post_values, return_xml){
	http = create_http_object();
        if(!http){
        alert('This browser doesnt support ajax requests.');
        return false;
        }
		http.onreadystatechange = function(){
			if(http.readyState == 4){
				if(http.status == 200){
					if(callback_function){
						if(return_xml){
						eval(callback_function + '(http.responseXML)');
						}
						else{
						eval(callback_function + '(http.responseText)');
						}
					}
				}
				else{
				alert('Error! (' + http.status + ')');
				}
			}
		}
        if(!post_values){
        post_values = null;
        }
        if(!http_method){
        http_method = "GET";
        }
        http.open(http_method, url, true);
        if(http_method == "POST"){
        http.setRequestHeader('Content-Type', 'application/x-www-form-URLencoded');
		http.setRequestHeader("Content-length", post_values.length);
		http.setRequestHeader("Accept-Charset","UTF-8");
        }
    http.send(post_values);
    }

//
window.onload = function(){
sw.onload_action();
}

window.onresize = function (){
sw.valign_colomns();
}

