/**
    $Id: Maxpho Commerce, v 8.5.0, Tue 04 Dec 2007 04:53:24 PM CET $

    Maxpho Company, Web application company
    http://www.maxpho.com

    Copyright (c) 2008 Maxpho, Co.
    All right reserved.
*/

// replace_img
/**
 * Take in input the id name of tag img, and the new source for the image
 * permitt to replace the source for img tag
 *
 * @param imgId the id name for img tag
 * @param source new source for image
 * @return void
 *
 * @author Alessandro Venturelli
 */
function replace_img(imgId, source){
	img = document.getElementById(imgId);
	img.src = source;
}

// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
function getPageSize() {
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);

	return arrayPageSize;
}

// Returns array with x,y page scroll values
// Core code from - quirksmode.org
function getPageScroll() {
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) { // all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('', yScroll);

	return arrayPageScroll;
}

function updateDatePullDownMenu(objForm, fieldName) {
	var pdmDays = fieldName + "_days";
	var pdmMonths = fieldName + "_months";
	var pdmYears = fieldName + "_years";

	time = new Date(objForm[pdmYears].options[objForm[pdmYears].selectedIndex].text, objForm[pdmMonths].options[objForm[pdmMonths].selectedIndex].value, 1);

	time = new Date(time - 86400000);

	var selectedDay = objForm[pdmDays].options[objForm[pdmDays].selectedIndex].text;
	var daysInMonth = time.getDate();

	for (var i=0; i<objForm[pdmDays].length; i++) {
		objForm[pdmDays].options[0] = null;
	}

	for (var i=0; i<daysInMonth; i++) {
		objForm[pdmDays].options[i] = new Option(i+1);
	}

	if (selectedDay <= daysInMonth) {
		objForm[pdmDays].options[selectedDay-1].selected = true;
	} else {
		objForm[pdmDays].options[daysInMonth-1].selected = true;
	}
}

function rowOverEffect(object) {
	if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
	if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function checkBox(object) {
	document.account_newsletter.elements[object].checked = !document.account_newsletter.elements[object].checked;
}

function popupWindow(url, name, params) {
	window.open(url, name, params).focus();
}

function check_name_field(id) {
	var obj = document.getElementById(id).value;
	if(obj == null || obj == ""){
		alert('error');
	}
}

loadImages = function(urlImages) {
	if (document.images) {
		image = new Image();
		for (var i=0; i<urlImages.length; i++) {
			image.src = urlImages[i];
		}
	}
}

function searchEngineFriendly(url){
	while(url.indexOf('&') != -1 || url.indexOf('?') != -1 || url.indexOf('=') != -1){
		if(url.indexOf('&') != -1){
			position = url.indexOf('&');
			url = url.substring(0,position)+'/'+url.substring(position+1,url.length);
		}
		if(url.indexOf('?') != -1){
			position = url.indexOf('?');
			url = url.substring(0,position)+'/'+url.substring(position+1,url.length);
		}
		if(url.indexOf('=') != -1){
			position = url.indexOf('=');
			url = url.substring(0,position)+','+url.substring(position+1,url.length);
		}
	}
	return url;
}

/*function issetLinkParameter(url){
	if(url.indexOf('?') != -1 || url.indexOf(',') != -1 ){
		return true;
	}else{
		return false; 
	}
}*/

var separator = '';
function concatLink2Parameter(url,parameters){
	/*var separator = (issetLinkParameter(url)) ? '&' : '?';*/
	var separator = '/';
	if(parameters!=''){
		url = url + separator + parameters;
	}
	return searchEngineFriendly(url);
}

