// Index Anim
var pHauteur=28;
var pSettings=new Array();
var monInterval=null;

var animBloc=null;
var animDiff=null;
var animEnd=null;

var openBloc=null;
var openBlocToOpen=null;

pSettings["forms-login"]=new Array('172', 'link-new');
pSettings["forms-create"]=new Array('296','link-create');

function show_bloc(pElement) {
	if(!monInterval) {
		var pInit=Math.ceil(pSettings[pElement][0]);
		var pEndHidden=pInit+pHauteur;
		
		animBloc=pElement;
		animDiff=pInit;
		animEnd=pEndHidden;
		
		if(parseInt(document.getElementById(animBloc).style.top)>=0) {
			monInterval=setInterval(hide_bloc,10);
		}
		else {
			if(openBloc) {
				var pInit=Math.ceil(pSettings[openBloc][0]);
				var pEndHidden=pInit+pHauteur;
				
				animBloc=openBloc;
				animDiff=pInit;
				animEnd=pEndHidden;
				openBlocToOpen=pElement;
				
				monInterval=setInterval(hide_bloc,10);
			}
			else {
				monInterval=setInterval(anim_bloc,10);
			}
		}
	}
}

function hideAll() {
	pElement="forms-login";
	pSettings[pElement][0]=document.getElementById(pElement).offsetHeight-pHauteur;
	var pInit=Math.ceil(pSettings[pElement][0]);
	var pEndHidden=pInit+pHauteur;
	document.getElementById(pElement).style.top='-'+pInit+'px';
	document.getElementById(pElement).style.clip='rect('+pInit+'px 431px '+pEndHidden+'px 0px)';
	
	pElement="forms-create";
	pSettings[pElement][0]=document.getElementById(pElement).offsetHeight-pHauteur;
	pInit=Math.ceil(pSettings[pElement][0]);
	pEndHidden=pInit+pHauteur;
	document.getElementById(pElement).style.top='-'+pInit+'px';
	document.getElementById(pElement).style.clip='rect('+pInit+'px 431px '+pEndHidden+'px 0px)';
	
	
}

function anim_bloc() {
	animDiff-=15;
	if(animDiff<=0) {
		document.getElementById(animBloc).style.top='0px';
		document.getElementById(animBloc).style.clip='rect(0px 431px '+animEnd+'px 0px)';
		document.getElementById(pSettings[animBloc][1]).className="link linktop";
		clearInterval(monInterval);
		monInterval=null;
		openBloc=animBloc;
	}
	else {
		document.getElementById(animBloc).style.top='-'+animDiff+'px';
		document.getElementById(animBloc).style.clip='rect('+animDiff+'px 431px '+animEnd+'px 0px)';
	}
}

function hide_bloc() {
	var actualTop=parseInt(document.getElementById(animBloc).style.top);
	actualTop-=15;
	if(Math.abs(actualTop)>=animDiff) {
		document.getElementById(animBloc).style.top='-'+animDiff+'px';
		document.getElementById(animBloc).style.clip='rect('+animDiff+'px 431px '+animEnd+'px 0px)';
		document.getElementById(pSettings[animBloc][1]).className="link";
		clearInterval(monInterval);
		monInterval=null;
		if(openBlocToOpen) {
			openBloc=null;
			
			var pInit=Math.ceil(pSettings[openBlocToOpen][0]);
			var pEndHidden=pInit+pHauteur;
			
			animBloc=openBlocToOpen;
			animDiff=pInit;
			animEnd=pEndHidden;
			monInterval=setInterval(anim_bloc,10);
			
			openBlocToOpen=null;
		}
	}
	else {
		document.getElementById(animBloc).style.top=actualTop+'px';
		document.getElementById(animBloc).style.clip='rect('+Math.abs(actualTop)+'px 431px '+animEnd+'px 0px)';
	}
	
}

// Menu
function open_menu(pMenu) {
	if(document.getElementById(pMenu).style.display=="block") {
		document.getElementById(pMenu).style.display="none";
	}
	else {
		var menuTag=document.getElementById("menu");
		var menuDD=menuTag.getElementsByTagName("dd");
	
		for(var x=0; x<menuDD.length; x++) {
			menuDD[x].style.display="none";
		}
		
		document.getElementById(pMenu).style.display="block";
	}
}


//Popup
function show(scr,site,mid,winname,wid,hei,pic)
{
	var url2 = '/'+scr+'?site='+site+'&model_id='+mid+'&picture='+pic;
	var attr = 'width='+wid+',height='+hei+',top=0,left=50,menu=0,status=0,scrollbars=1,resizable=1,location=0';
	window.open(url2,winname,attr);
	return false;
}

//Verify submit sales
function verify_sale_submit()
{
	var frm = document.forms.frmSales;
	
	var auth_code = frm.auth_code.value;
	var username = frm.client_username.value;		
	var email = frm.client_email.value;
	
	var content = trim(frm.im_conversation.value);
	var dropdownIndex = document.getElementById('site').selectedIndex;
	
	
	// no site selected
	if (!dropdownIndex)
	{
		alert("Please select the site on which you made the sale. This information is mandatory.");
		return false;	
	}
	
	// missing infos
	if (!auth_code && !email && !username)
	{
		alert("You must enter one the following information: Authorization Code, Client Email, or Client Username.");
		return false;	
	}
	
	// no content in textarea
	if (!content)
	{
		alert("You cannot submit an empty conversation. Please enter a valid conversation.");
		return false;
	}
	
	frm.submit();
}

function trim(s) {
	s = s.replace(/(^\s*)|(\s*$)/gi,"");
	s = s.replace(/[ ]{2,}/gi," ");
	s = s.replace(/\n /,"\n");
	return s;
}

