﻿
//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.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');
	}
	

	//layout actions on page load and change
	this.valign_colomns = function(){
	this.setmainmenu_level2();
	this.scaleMiddleColomn();
	}
	
	
	this.onload_action = function(){
	this.pre_img[this.pre_img.length]=this.ptr+'CmWare/img/website/ajaxloader.gif';
	this.externallinks();
	this.valign_colomns();
	this.iniYelM();
	
	//$("tr:nth-child(2n)").css("background-color", "#FFF");
	$("tr:even, li:even").addClass("even");
		
	// initialize tooltip
	$("a[title]").tooltip({
	   // tweak the position
	   offset: [-3, 0]
	})
	
	//do wrapping h2 in blocks
	$('.block h2 img').wrap('<div class="w1" />');
	$('.block h2 .w1 img').wrap('<div class="w2" />');
	$('.block h2 .w1 .w2 img').wrap('<div class="w3" />');
	}
	

	//CUSTOMER SPECIFIC METHODS
	this.setmainmenu_level2 = function(){
	var num_of_childs=0;
		if(document.getElementById("menu211218518_lev2_childs")){
		num_of_childs=this.val_by_id('menu211218518_lev2_childs');
		}
		if(document.getElementById("bl2") && num_of_childs>0){
		var h=$("#bl1 ul ul").height();
		//scretchng the dropzone height (so that submenu will fitt)
		document.getElementById('bl2').style.height=h+'px';
		var x=this.getabsx('bl2');
		var y=this.getabsy('bl2');
		//positioning the real submenu (as a floating object) to the available location
		$("#bl1 ul ul").css("left",x);
		$("#bl1 ul ul").css("top",y);
		$("#bl2").css("visibility","visible");
		$("#bl1 ul ul").css("visibility","visible");
		//resseting height of loc50
		//document.getElementById('loc50').style.height=h+'px';
		this.subMenuheight=h;
		}
		else{
		//alert("no menu");
		$("#bl2").html("<div id='hdr'><div><!--somevalue--></div></div>");
		//$("#bl2").css("display","none");
		}
	}
	
	this.scaleMiddleColomn = function(){
	var tempNum=this.val_by_name("common_form", "template_num");
	var top=0;
	
		if(tempNum=="1"){
		top=475;
		}
		else if(tempNum=="2"){
		top=376;	
		}
		else if(tempNum=="3"){
		top=377;	
		}
		else if(tempNum=="4"){
		top=477;	
		}
		else if(tempNum=="5"){
		top=197;	
		}

	//resseting height of loc70
	document.getElementById('loc70').style.height='auto';
	//getting height of wrap
	var docheight = ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight );
	var wrapheight = document.getElementById('loc70').offsetHeight+top;
	var t=document.getElementById('loc70').offsetHeight+(docheight-wrapheight);
		if(t<this.subMenuheight){
		t=this.subMenuheight;
		}
		if (wrapheight<docheight) { 
		document.getElementById('loc70').style.height=t+'px';
		}
	}
	
	this.iniYelM = function(){
		if($('.ym .block').length>0){
		$(".ym").css("visibility","visible");
		
		var h=$(".ym .block").height();
		$(".ym .block").css("margin-top", 57-Math.round(h/2)+'px');
		}
		else{
		$(".ym").css("display","none");	
		}
	}
	
}

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

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

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


    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();
}


//declaring a new class refercences
function refercences(){

this.frameRate=15;
this.defaultSpeed=10;
this.speed=this.defaultSpeed;
this.begin=-78;
this.end=0;
this.pos=this.begin;

	this.moveUp = function(id){
		if(this.act=='allowUp'){
		//$(".ref #"+id+" .imgs").css({"background-color":"#F5F3F5"});
			if(this.pos<this.end-this.speed){
			this.pos+=this.speed;
			$(".ref #"+id+" .imgs").css({"margin-top":""+this.pos+"px"});	
			var t=setTimeout(id+".moveUp('"+id+"')",this.frameRate);
			}
			else{
			//placing clip at end position
			this.pos=this.end;
			$(".ref #"+id+" .imgs").css({"margin-top":""+this.pos+"px"});
			}
		}
	}
	this.moveDown = function(id){
		if(this.act=='allowDown'){
		
			/*
			this.diff=parseInt(this.begin-this.pos);
			this.diffP=parseInt((this.diff/this.begin)*100);
			this.speed=Math.ceil((this.defaultSpeed/100)*this.diffP);
			*/
			
			if(this.pos>this.begin+this.speed && false){				
			this.pos-=this.speed;
			$(".ref #"+id+" .imgs").css({"margin-top":""+this.pos+"px"});	
			var t=setTimeout(id+".moveDown('"+id+"')",this.frameRate);
			}
			else{
			//placing clip at begin position
			this.pos=this.begin;
			$(".ref #"+id+" .imgs").css({"margin-top":""+this.pos+"px"});
			//$(".ref #"+id+" .imgs").css({"background-color":"#E8E8E8"});
			//$(".ref #"+id+" .imgs").css({"background-color":"transparent"});
			}
			
		}
	}
}

	$(document).ready(function() {				  
	var numOfrefs = $('.ref .bl').length;
							  
		//declaring instances on the fly
		for(i=1; i<=numOfrefs; i++){
		window["r"+i] = new refercences();//window because of global scope
		}
	
		$('.ref .bl').hover(
			// mouseover 
			 function(){
				var id= $(this).attr('id');
				eval(id).speed=eval(id).defaultSpeed;
				eval(id).act='allowUp';
				eval(id).moveUp(id);	
			 },
			 // mouseout 
			 function(){
				var id= $(this).attr('id');
				eval(id).act='allowDown';
				eval(id).moveDown(id, id);
			 } 
		 );
	

	});

