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

//declaring the array that will be used for preloading images
this.pre_img = new Array();
		
	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 ImgObj = new Array();//new array for all the images objects
			for(i=0; i<img.length; i++) {
			//alert('preloading '+img[i]);
			ImgObj[i] = new Image(); //new img obj
			ImgObj[i].src = img[i];
			}
		}
	}

	//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.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.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.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(){	
	//fitting the content to 'loc30_top'
	this.fitcontents2loc30top(1);
	}
	
	this.onload_action = function(){
	this.externallinks();
	this.preload_images(this.pre_img);
	this.valign_colomns();
	}
	
	//CUSTOMER SPECIFIC METHODS
	
	this.fitcontents2loc30top = function(minus){
		if(document.getElementById('loc30_top_content')){
		var default_font_size=18;
		var default_font_pos=125;
		//getting width of content
		var w = document.getElementById('loc30_top_content').offsetWidth;
			if(w> 178){
			var newsize=default_font_size-minus;
			var newtop=default_font_pos+minus+1;
			document.getElementById('loc30_top_content').style.fontSize = newsize+'px';
			document.getElementById('loc30_top_content').style.top = newtop+'px';
			this.fitcontents2loc30top((minus+1));
			}
		}
	}
	
	
}
	
//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();
}
