// JavaScript Document
function parseUrl1(data) {
    var e=/^((http|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+\.[^#?\s]+)(#[\w\-]+)?$/;

    if (data.match(e)) {
        return  {url: RegExp['$&'],
                protocol: RegExp.$2,
                host:RegExp.$3,
                path:RegExp.$4,
                file:RegExp.$6,
                hash:RegExp.$7};
    }
    else {
        return  {url:"", protocol:"",host:"",path:"",file:"",hash:""};
    }
}
function parseUrl2(data) {
    var e=/((http|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+\.[^#?\s]+)(#[\w\-]+)?/;

    if (data.match(e)) {
        return  {url: RegExp['$&'],
                protocol: RegExp.$2,
                host:RegExp.$3,
                path:RegExp.$4,
                file:RegExp.$6,
                hash:RegExp.$7};
    }
    else {
        return  {url:"", protocol:"",host:"",path:"",file:"",hash:""};
    }
}

function xtractFile(data){
	var m = data.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
	return {path: m[1], file: m[2]}
}

function get_url_param( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

function rel_paths_fix () {
	
	var page = get_url_param("page")
	var product = get_url_param("product")
	
	for(var i=0; i<document.images.length; i++)
	{
	  var img = document.images[i]
	  
	  var imgName = img.src.toUpperCase()
	  var ext = imgName.substring(imgName.length-3, imgName.length)
	  
	  if (ext == "JPG" || ext == "PNG" || ext == "GIF")
	  {
		if (product == "")
	  	{
		img.src = "pages/"+ page+"/" + xtractFile(img.src).file
		//alert (img.src)
		}
		else {
		img.src = "pages/"+ page+"/" + product +"/" + xtractFile(img.src).file			
		}
		
	  }
	}
}

window.onload=function() {
rel_paths_fix();
}


