﻿//browser detection hack.  chrome doesn't like utf8 encoding & decoding
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) { 
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera",
			versionSearch: "Version"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

//intermezzo for utf8 en-decoding
var Utf8 = {

    // public method for url encoding
    encode: function(string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }

        return utftext;
    },

    // public method for url decoding
    decode: function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }
        return string;
    }
}





function FillSearchAgents(XmlToParse, ElementToFillIn, IndivElementName) {
    $(ElementToFillIn).html('');

    
    var content = $(XmlToParse).find('AccompanyingText').text() + '<ul>';
    var counter = 0;
    $(XmlToParse).find(IndivElementName).each(function() {
    content += '<li><a onclick="Javascript:JumpToAgent(' + $(this).find('SearchId').text() + ');">' + $(this).find('SearchName').text() + '</a></li>';   //<strong>35 jobs</strong>
        counter++;
    });
    content += '</ul>';
    $(ElementToFillIn).html(content);
}


function fillJobsList(jobsListName, indivJobElementName, jobsListContentXML, SEOText) {
    var content = '<h2>'+ SEOText +'</h2><div class="jobs">';
    var posCounter = 0;
    var titleLink = $(jobsListContentXML).find('Title').text();
    var urlLink = $(jobsListContentXML).find('Url').text();
    $(jobsListContentXML).find(indivJobElementName).each(function() {
        posCounter++;
        if (posCounter <= 6) { //only show first six.
            content += '<div class="pos-' + posCounter + '"><article> ';
            if ($(this).find('JobUrl').text().length > 0) {
                content += '<a href="' + $(this).find('JobUrl').text() + '">';
             }
            else {
                content += '<a href="Javascript:JumpToJob(' + $(this).find('JobId').text() + ')">';
            }
            content += '<h3>' + $(this).find('JobTitle').text() + '</h3><div class="article-content">';
            if ($(this).find('JobCompanyImg').text().length > 0) {
                content += '<img src="' + $(this).find('JobCompanyImg').text() + '" alt="' + $(this).find('JobCompany').text() + '">';
            }
            content += '<p>' + $(this).find('JobDescription').text() + '</p>' +
                        '</div></a></article></div>';
        }

    });
    //taggedjobs:  kill link when less then or equal to six jobs
    if (indivJobElementName == 'TaggedJob' && posCounter <= 6) {
        content += "</div>";
    }
    else {
        content += '</div><a class="more" href="' + urlLink + '">' + titleLink + '</a>';
    }
    document.getElementById(jobsListName).innerHTML = content;
    //$(jobsListName).children('jobs').html(content);
    return posCounter;
}

    /*vars for jobslist */
    var slideby = 1;
    var pos = 1
    var horlistwidth = 0;
    var scrollvalue = 0;
    var visible = null


	/*fill jobslist*/
	/***************/
	function fillJobsListSlider(jobsListName, indivJobElementName, jobsListContentXML,taggedjobsCookieName,taggedJobsCounter) {
    var content = '<section>';
   // var total = 1;
    $(jobsListContentXML).find(indivJobElementName).each(function() {
        content += '<article> <a href="Javascript:JumpToJob(' + $(this).find('JobId').text() + ')"><strong class="delete" onclick="javascript:TagUnTagJobNew(\'' + $(this).find('JobId').text() + '\', \'' + taggedjobsCookieName + '\', \'' + taggedJobsCounter + '\',\'jobdetail\');callTaggedJobsService();"><em></em></strong>' +
                        '<h2>' + $(this).find('JobTitle').text() + '</h2><div class="article-content">';
        if ($(this).find('JobCompanyImg').text().length > 0) {
            content += '<img src="' + $(this).find('JobCompanyImg').text() + '" alt="' + $(this).find('JobCompany').text() + '">';
        }
        content += '<p>' + $(this).find('JobDescription').text() + '</p></div></a></article>';
        //total++;

    });
    content += '</section>';
    $(jobsListName).html(content);

    $('carousel-holder h3').html('pos:' + pos);

    /* slider */
    /**********/

    
	if ($(window).width() < 464) {
		visible = 1
	} else if ($(window).width() < 768) {
		visible = 2
	} else if ($(window).width() < 990) {
		visible = 3
	} else {
		visible = 4
	}

	
	var total = $('.carousel article').size();

    if (total >= visible) {
        //$('.carousel-holder ul').css("left",0-scrollvalue+"%");	
        $('.carousel-holder a.arrow').removeClass("disabled")
        $('.carousel-holder a.next').show()
        $('.carousel-holder a.prev').hide()

    } else {
        $('.carousel-holder a.arrow').addClass("disabled")
    }

	var resize = false

    var init = function() {
	

        if ($(window).width() < 464) {
            visible = 1
        } else if ($(window).width() < 768) {
            visible = 2
        } else if ($(window).width() < 990) {
            visible = 3
        } else {
            visible = 4
        }
		
		var total = $('.carousel article').size();

        if (total - visible <= pos - 1) {
            $('.carousel-holder a.next').hide()
        }
        if (total <= visible) {
            $('.carousel-holder a.arrow').hide()
        } else if (total - visible > pos - 1) {
            $('.carousel-holder a.next').show()
        }
		
		/*if(resize == true){*/
			if (total - visible < pos - 1 && total <= visible) {
				$('.carousel-holder section').css("left", 0 + '%');
				pos = 1;
			} else if (total - visible < pos - 1 && total > visible) {
				pos--
				$('.carousel-holder section').css("left", 0 - (scrollvalue * (pos - 1)) + '%');
			}
			resize=false;
		/*}*/
        //alert('total: ' + total + ' visible: ' + visible);
        if (total >= visible) {
            //$('.carousel-holder ul').css("left",0-scrollvalue+"%");	
            $('.carousel-holder a.arrow').removeClass("disabled")
        } else {
            $('.carousel-holder a.arrow').addClass("disabled")
        }

        scrollvalue = 100 / visible

        //calculate width ul
        liwidth = $('.carousel-holder .carousel').width() / visible
        $('.carousel-holder .carousel article').css("width", liwidth + "px");
        /* + parseInt($('.carousel-holder .carousel ul li').css("padding-right")) + parseInt($('.carousel-holder .carousel ul li').css("padding-left"));*/

        horlistwidth = 4;
        $('.carousel-holder article').each(function() {
            horlistwidth = horlistwidth + $(this).width();
        });

        var factor = horlistwidth / $('.carousel').width();
        var invfactor = $('.carousel').width() / horlistwidth;
        $('.carousel-holder section').css("width", (100 * factor) + "%");
        //$('.carousel-holder  ul li').css("padding","0 "+1.5 * invfactor+"%");
        $('.carousel-holder article').css("width", ((100 / visible) * invfactor) + "%");
    }
	
    init();

    $(window).resize(function() {
        init();
		resize = true;
        $('.carousel-holder section').css("left", 0 - (scrollvalue * (pos - 1)) + '%');
    });

    //$(jobsListName).page();
    //todo:  steal init from slider.js, integrate here.
	
	

	//scrollParams
	params = new Array();
	
	var scrollParams = function(dir){
		if(dir=='right'){
			params.doscroll=scrollvalue+x_pct
		}else if(dir=='left'){
			params.doscroll=scrollvalue-x_pct	
		}
		if( Math.abs(move_y-move_x) >0){
			params.scrollspeed=t2-t1;
			params.easing = 'easeOutSine'
			if(params.scrollspeed<200){
				params.scrollspeed = 200
				params.easing = 'easeOutBounce'
			}else if(params.scrollspeed>800){
				params.scrollspeed = 800
			}
		}else{
			params.scrollspeed = 600;
			params.easing = 'easeOutSine';
		}
		return params
	}

    //scroll to right
    var scrollToRight = function() {
        if (total - visible >= pos) {

            if (total - visible < pos + 1) {
                $('.carousel-holder a.next').hide()
            } else {
                $('.carousel-holder a.next').show()
            }
            if (pos > 0) {
                $('.carousel-holder a.prev').show()
            } else {
                $('.carousel-holder a.prev').hide()
            }

			scrollParams('right');

            $('.carousel-holder .carousel section').animate({
               left: '-='+params.doscroll+"%"
            }, params.scrollspeed, params.easing, function() {
                // Animation complete.

                $('.carousel-holder a.next').removeClass("disabled");

                pos++
				
				var total = $('.carousel article').size();



            });
        }
    };

    //scroll to left
    var scrollToLeft = function() {
        if (pos > 1) {

            if (total - visible < pos - 1) {
                $('.carousel-holder a.next').hide()
            } else {
                $('.carousel-holder a.next').show()
            }
            if (pos > 2) {
                $('.carousel-holder a.prev').show()
            } else {
                $('.carousel-holder a.prev').hide()
            }

            scrollParams('left');
			
			$('.carousel-holder .carousel section').animate({
                left: '+='+params.doscroll+"%"
            }, params.scrollspeed, params.easing, function() {
                // Animation complete.
                //$('.carousel-holder .carousel li').last().remove();
                //$('.carousel-holder .carousel ul').css("left",-scrollvalue+"%");
                //$('.carousel-holder .carousel li').last().prev().clone().prependTo('.carousel-holder .carousel ul');

                $('.carousel-holder a.prev').removeClass("disabled");

                pos--;
				var total = $('.carousel article').size();
	

            });
        }
    };

    //portfolio btn next
    $('.carousel-holder a.next').click(function() {
        if (!($(this).hasClass('disabled'))) {
            if (total - visible >= pos) {
                $(this).addClass("disabled");
                x_pct = 0
				move_x = 0
				move_y = 0
				scrollToRight();
            }
        }
        return false;
    });

    //portfolio btn prev
    $('.carousel-holder a.prev').click(function() {
        if (!($(this).hasClass('disabled'))) {
            if (pos > 1) {
                $(this).addClass("disabled");
                x_pct = 0
				move_x = 0
				move_y = 0
				scrollToLeft();
            }
        }
        return false;
    });

    $('.carousel-holder section').mouseover(function(e, d) {
        $('.carousel-holder .carousel section').mousewheel(function(e, d) {
            if (!($('.carousel-holder a.arrow').hasClass('disabled'))) {
                if (d > 0) {
                    if (pos > 1) {
                        $('.carousel-holder a.prev').addClass("disabled");
                        x_pct = 0
						scrollToLeft();
                    }
                } else {
                    if (total - visible >= pos) {
                        $('.carousel-holder a.next').addClass("disabled");
                        x_pct = 0
						scrollToRight();
                    }
                }
                return d;
            }
            return false
        });
    });

    /* swipe trigger */
    /*****************/
  	var down_x = null;
	var down_x_pct = null;
	var down_y = null;
	var up_x = null;
	var up_x_pct = null;
	var x_pct = 0;
	var move_x = null;
	var move_y = null;
	var start_x_pct = null;
	var t1;
	var t2;	
	
	$(".carousel-holder .carousel").mousedown(function(e){
		e.preventDefault();	
		t1=0;
		t2=0;
		t1=new Date().valueOf();
		down_x = e.pageX;
	});
	
	$(".carousel-holder .carousel").mouseup(function(e){
		up_x = e.pageX;
		$(".swipe-icon").fadeOut();
		t2=new Date().valueOf();
		doSwipe();
	});
	
	$(".carousel-holder .carousel").bind('touchstart', function(e){
		
		down_x = e.originalEvent.touches[0].pageX;
		down_x_pct = (e.originalEvent.touches[0].pageX * 100)/screen.width;
		down_y = e.originalEvent.touches[0].pageY;
		$(".swipe-icon").show();
		start_x_pct = -scrollvalue * (pos - 1)//-scrollvalue//-100;
		t1=0;
		t2=0;
		t1=new Date().valueOf();
	})
	
	
	 $(".carousel-holder .carousel section").bind("touchmove", function(e) {  

	  move_x = e.originalEvent.touches[0].pageX;
	  move_y = e.originalEvent.touches[0].pageY;
	  up_x = e.originalEvent.touches[0].pageX;
	  up_x_pct = (e.originalEvent.touches[0].pageX * 100)/screen.width;
	  console.log(Math.abs(down_x-move_x) > Math.abs(down_y-move_y));
		if( Math.abs(down_x-move_x) > Math.abs(down_y-move_y) ) {
			e.preventDefault();
			
			var orig = e.originalEvent;  
			/*x_pct = ((orig.changedTouches[0].pageX * 100)/screen.width)-down_x_pct */
			

			/*if(!($('.carousel-holder a.arrow').hasClass('disabled'))){
				$(".carousel-holder .carousel section").css({position:'relative', left: start_x_pct+x_pct+'%'});
			}*/
			//$(".swipe-icon").fadeOut();	
			//$(".swipe-icon").html(start_x_pct+x_pct);	
		}
	  
    }); 
	 
	$(".carousel-holder .carousel").bind('touchend', function(e){
		$(".swipe-icon").fadeOut();
		t2=new Date().valueOf();
		doSwipe();

	}); 
	
	//doSwipe
	var doSwipe = function(){
		if ((down_x_pct - up_x_pct) > 25)
		{
			if(!($('.carousel-holder a.next').hasClass('disabled'))){
				if (total - visible >= pos) {
					$('.carousel-holder a.next').addClass("disabled");
					scrollToRight();
				}/*else{
					$(".carousel-holder .carousel section").animate({left: start_x_pct+'%'}, 200, 'easeOutBounce')
				}*/
			}
			return false;
		}
		else if ((up_x_pct - down_x_pct) > 25)
		{
			if(!($('.carousel-holder a.prev').hasClass('disabled'))){
				if (pos > 1) {
					$('.carousel-holder a.prev').addClass("disabled");
					scrollToLeft();
				}/*else{
					$(".carousel-holder .carousel section").animate({left: start_x_pct+'%'}, 200, 'easeOutBounce')
				}*/
			}
			return false;
		}
		/*else{
			$(".carousel-holder .carousel section").animate({left: start_x_pct+'%'}, 600, 'easeOutQuad')
		}*/
	}
    /****************/

    /* delete item */
    /***************/
    $('.carousel-holder strong.delete').click(function() {
        $(this).parent().parent('article').fadeOut(300, function() { $(this).remove(); });
        total--;
		//pos--;
		//$(".carousel-holder .carousel section").animate({left: 0 - (scrollvalue * (pos - 1))+'%'}, 600, 'easeOutQuad')
		resize=true
		init();
        return false
    })
    
    //init();    
}
function ClearSlider(jobsListName) {
    $(jobsListName).html('<section></section>');
}

function EnableButton(tagName) {
    if ($(tagName).hasClass('disabled'))
    { $(tagName).removeClass('disabled'); }
    $(tagName).removeAttr('disabled');        
}

function PrepareNewsLettersForTransport(tag, indivHTMLElement,token,userid) {
    var returnvalue = '<?xml version="1.0"?><Package xmlns="http://schemas.jobat.be/Esb/2011/04">';
    returnvalue += '<userId>' + userid + '</userId>';

    $(tag).find(indivHTMLElement).each(function() {
        var label = $(this).children('label').attr('id');
        if (label) {
            returnvalue += ('<' + label + '>' + $(this).children('input').is(':checked') + '</' + label + '>');
        }
    });
    returnvalue += '<Token>' + token + '</Token>';
    returnvalue += '</Package>';
    return returnvalue;
}

function SetNewsLetters(tag, xmlData, indivXmlElement,newsletterurl) {
    var content = '';  //= '<fieldset>';

    var counter = 0;
    var checked;
    $(xmlData).find(indivXmlElement).each(function() {
        if ($(this).find('Enabled').text() == 'true') {
            checked = 'checked="checked"';
        }
        else {
            checked = '';
        }
        counter++;
        if (counter <= 6) {  //6 tags only
            content += '<div class="row"><input id="check-' + counter + '" ' + checked + '" class="cb" type="checkbox" onclick="javascript:EnableButton(\'' + tag + ' :input \');" value="tip" /> ' +
                       '<label id="' + $(this).find('Name').text() + '" for="check-' + counter + '" class="cb">' + $(this).find('Description').text() + '</label></div>';
        }

    });

    $(tag + ' #fieldNewsLetters').html(content);
}
function SetApplications(tag, xmlData, indivXmlElement,arrayParams) {
    var content = '';
    if (xmlData) {
        $(xmlData).find(indivXmlElement).each(function() {
            content += '<p>' + $(this).find('Jobtitle').text() + ' ' + $(this).find('CompanyName').text() +'</p>';
        });
        content += '<div class="btn"><a href="#" class="button" onclick="Javascript:JumpToApplications();">' + arrayParams[1] + '</a></div>';
    }
    else { 
        content += '<p>' + arrayParams[0] + '</p><div class="btn"><a class="button" href="#"onclick="Javascript:JumpToApplications();">'+ arrayParams[2] +'</a></div>';
    }
    $(tag).html(content);
    //document.getElementById(tag).innerHTML = content;
    $('#fieldProfileMail').html('');
}

function SetProfileInfo(tag, xmlData,detailTag,arrayObjects) {
    

    var name = $(xmlData).find('FirstName').text() + ' ' + $(xmlData).find('LastName').text();
    if ($(xmlData).find('Image').text() == 'nopic.png') {
        //no picture
        $(tag).children(detailTag).children('img').attr('src', arrayObjects[0]);
        $(tag).children(detailTag).children('img').attr('alt', name);
    }
    else {
        $(tag).children(detailTag).children('img').attr('src', $(xmlData).find('Image').text());
        $(tag).children(detailTag).children('img').attr('alt', name);
    }
    $(tag).children(detailTag).children('h4').html(name);

    if ($(xmlData).find('CurrentJob').text() == 'n/a') {
        $(tag).children(detailTag).children('h5').html(arrayObjects[4]);
    }
    else {
        $(tag).children(detailTag).children('h5').html($(xmlData).find('CurrentJob').text());
    }
    var list = '';
    if ($(xmlData).find('CurrentCompany').text().length  > 0 ) {
        list += '<li>' + $(xmlData).find('CurrentCompany').text() + '</li>';
    }
    if ($(xmlData).find('JobLength').text().length > 0) {
        list += '<li>' + $(xmlData).find('JobLength').text()   +'</li>';
    }
    $(tag).children(detailTag).children('ul').html(list);
    $(tag).children(detailTag).children('#progress_bar').children('.ui-progress').attr('style', 'width:' + $(xmlData).find('UserStatus').text() + '%;');
    $(tag).children(detailTag).children('#progress_bar').children('.ui-progress').children('span').children('strong').html($(xmlData).find('UserStatus').text() + '%');
    if ($(xmlData).find('UserStatus').text() == "100") {
        $(tag).children(detailTag).children('p.info').html(arrayObjects[6]);
     }
    else {
        $(tag).children(detailTag).children('p.info').html(arrayObjects[5] + ' ' + $(xmlData).find('MissingSections').text());
    }
}

function GetUserSearches(target, cookiename, nodataText, searchurl) {
    var textData = '';
    var cookievalue = readCookie(cookiename);
    if (cookievalue && cookievalue.length > 0) {
        var Searches = cookievalue.split('|');
        
        var tussen = Searches.length;
        for (var c = tussen; c > 0; c--) {
            var Search = Searches[c - 1].split('@');  //filter,keyword,jobcount
            var toReplace = "+";
            textData += '<li><a href="' + searchurl + '?filter=' + Search[0] + '"><span>';
            if (BrowserDetect.browser == 'Chrome') {
                textData += Search[1].replace(/#/g, ",");
            }
            else {
                textData += Utf8.decode(Search[1].replace(/#/g, ","));
            }
            textData += '</span> <strong>' + Search[2] + ' jobs</strong></a></li>';
        }
    }
    else {
        cookievalue = readCookie("LastJobatSearch");
        if (cookievalue && cookievalue.length > 0) {
            var Searches = cookievalue.split('&');

            for (var i = 0; i < Searches.length; i++) {
                var Search = Searches[i].split('=');
                var toReplace = "+";
                textData += '<li><a href="' + searchurl + '?filter=' + Search[0] + '"><span>';
                if (BrowserDetect.browser == 'Chrome') {
                    textData += Search[1].replace(/#/g, ",");
                }
                else {
                    textData += Utf8.decode(Search[1].replace(/#/g, ","));
                }
                textData += '</span> <strong>' + Searches.length + ' jobs</strong></a></li>';
            }
        }
        else {
            textData = '<li><p>' + nodataText + '</p></li>';
        }
    }
    $(target).html(textData);
}

function RemoveUserSearch(target, cookiename, nodataText) {
    deleteCookie(cookiename);
    $(target).html('<li><p>' + nodataText + '</p></li>');
}


function CallWCF(varTypeS, varUrlS, SuccessFunction, functionErrorName) {
    CallWCF3Param(varTypeS, varUrlS, '', SuccessFunction, functionErrorName);
}

function CallWCF3Param(varTypeS, varUrlS, varDataS, SuccessFunction,functionErrorName) 
{
    $.ajax({
    //kcl
    //problem with caching
    //FireFox did not cache, IE did cache
        cache: false,
        type: varTypeS, //GET or POST or PUT or DELETE verb
        url: varUrlS, // Location of the service
        data: varDataS, //Data sent to server
        contentType: "application/xml;", // content type sent to server
        dataType: "xml", //Expected data format from server
        processdata: true, //True or False
        success: function(msg) {//On Successfull service call
            SuccessFunction(msg);
        }
    });
}

//toggles article tab first.
function SelectArticles() {
    $('.ui-tabs-nav li:not(.last)').removeClass('ui-tabs-selected').removeClass('ui-state-active');
    $('.ui-tabs-nav li.last').addClass('ui-tabs-selected').addClass('ui-state-active');
    $('.ui-tabs-nav li.last').fadeIn();
    $('#jobs').addClass('ui-tabs-hide');
    $('#articles').removeClass('ui-tabs-hide');
    $('.search-block').addClass('article-search');
}

function SaveOpenCloseProfile() {
    var boxeslist = ['profilenotloggedin','profileloggedin','profileJobsMail','profileApplications','profileNewsLetters'];
    var toSaveData = '';
    for(var i=0;i< boxeslist.length;i++) {
        if($('#' + boxeslist[i] +' h3').hasClass('open')){
            toSaveData += boxeslist[i] + '|1&';
        }
        else
        {
            toSaveData += boxeslist[i] + '|0&';
        }
    }
    saveCookie('JobatMainPageBoxes', toSaveData, 30);
}

function ReadOpenCloseProfile() {
    var data = readCookie('JobatMainPageBoxes');
    if (data) {
        var splitData = data.split('&');
        for (var i = 0; i < splitData.length; i++)
        {
            var indivSplitter = splitData[i].split('|');

            if (indivSplitter[0] != '') {
                if (indivSplitter[1] == '1') {  //open
                    if (!$('#' + indivSplitter[0] + ' h3').hasClass('open')) {
                        $('#' + indivSplitter[0] + ' h3').toggleClass('open');
                        $('#' + indivSplitter[0] + ' h3').parent().next('.simple-block-content').fadeToggle();
                    }
                }
                else {  //close
                    if ($('#' + indivSplitter[0] + ' h3').hasClass('open')) {
                        $('#' + indivSplitter[0] + ' h3').toggleClass('open');
                        $('#' + indivSplitter[0] + ' h3').parent().next('.simple-block-content').fadeToggle();
                    }
                } 
            }

        } 
    }
}

