$(document).ready(function() {
	markActiveLink();
	if($("body").attr('id') == "page5")
		$("#contact-form").validate();
});

//sets the new languaje
function chanegUrlLang(languaje){
	var currentUrl = location.href;
	if (gup('lang')!=''){ //lang parameter exists
		$partsArray = currentUrl.split('lang=');
		$newUrl = $partsArray[0]+'lang='+languaje;
		window.location = $newUrl;
	}
	else if (gup('id')!=''){
		window.location = currentUrl + "&lang=" + languaje;
	}
	else{//we need to add the lang parameter at the end of the url string
		window.location = currentUrl + "?lang=" + languaje;
	}
}

//returns the value of a parameter in the URL
function gup( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//adds the current class to the main menu
function markActiveLink() {
    $("ul.sf-menu a").filter(function() {
        var currentURL = window.location.toString().split("/");
        //delete extra parameters in the url
        var cleanURL = (currentURL[currentURL.length-1]).toString().split("?");
		if (currentURL[3]=="catalog")
			return $(this).attr("href") == "/catalog";
		if ( cleanURL.indexOf("#") > 0 )
			cleanURL = cleanURL.toString().split("#");
        if(cleanURL != '' && cleanURL != '#'){ //if the bit after the last slash is the current page name
			if(cleanURL[0] == "company.php")
				return $(this).attr("rel") == cleanURL[0];
			else if (cleanURL[0] == "services.php")
				return $(this).attr("rel") == cleanURL[0];
			else
				return $(this).attr("href") == cleanURL[0];
		}
        else{ //if the bit is empty we are at the root
            return $(this).attr("href") == "index.php";
		}
    }).addClass("active");

 }
