//popup windows functions
function openPopUpImage(url,w,h){
	 var iwidth=w, iheight=h;
		popUpWin=window.open(url,'img','marginwidth=0,marginheight=0,leftmargin=0,topmargin=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+(iwidth)+',height='+(iheight));
}
function openPopUpZoom(url,w,h){
	 var iwidth=w, iheight=h;
		popUpWin=window.open(url,'img','marginwidth=0,marginheight=0,leftmargin=0,topmargin=0,toolbar=0,location=0,directories=0,status=0,menubars=0,scrollbars=0,resizable=0,width='+(iwidth)+',height='+(iheight));
}

//limited textarea
//<!-- Original:  Ronnie T. Moore -->
//<!-- Web Site:  The JavaScript Source -->
//<!-- Dynamic 'fix' by: Nannette Thacker -->
//<!-- Web Site: http://www.shiningstar.net -->
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
	countfield.value = maxlimit - field.value.length;
}

//only digits in input boxes
function digONLY(obj) {
	obj.value=obj.value.replace(/\D/g,'')
}
//only digits in input boxes + condition
function digONLYLimits(obj, limitMin, limitMax) {
	if(obj.value<limitMin){
		obj.value = limitMin;
		alert('minimum: '+limitMin);
	}else if(obj.value>limitMax){
		obj.value = limitMax;
		alert('maximum: '+limitMax);
	}else
		obj.value=obj.value.replace(/\D/g,'')
}
//self explain function
function ifConfirmRedirect(textConfirm, urlRedirect){
	if(confirm(textConfirm)){
		eval("window.location='"+urlRedirect+"'");
	}else
		return;
}

//increase iframe height
function increaseHeightBy(factor, level){
	if(factor!=''){
		iframeId = parent.document.getElementById('_site_files_upload');
		oldFrameHeight = iframeId.height;
		iframeNewHeight = (factor*1)+(oldFrameHeight*1);
		//alert(iframeNewHeight);
		eval(iframeId.height=iframeNewHeight);
		if(level !='' && level>1){
			mainFrameId = window.parent.frameElement;
			oldMainFrameHeight = mainFrameId.height;
			mainframeNewHeight = (factor*1)+(oldMainFrameHeight*1);
			//alert(mainframeNewHeight);
			eval(mainFrameId.height=mainframeNewHeight);
		}
	}
}


function deletePhotoPost(nr, numeForm, numeVar){
	varValue = eval("document."+numeForm+"."+numeVar);
	varValue.value = nr;
	eval("document."+numeForm+".submit()");
}

//specific -=Occasion Antilles Pro=- Functions
function searchInsideList(section){
	thisFormName = '_recherche_top';
	otherFrame = parent.document.getElementById('_ex_6_dernieres');
	thisForm = document.getElementById(thisFormName);
	var otherFrameSrc = otherFrame.src;
	var getParams = '&search_mode=1';
	
	if(section == 'vehicule'){
		getParams += '&id_marque='+thisForm.id_marque.value+'&id_model='+thisForm.id_model.value+'&prix='+thisForm.prix.value;
		getParams += '&id_departament='+thisForm.id_departament.value+'&anne_modele='+thisForm.anne_modele.value;
		/*
		if(id_marque = thisForm.id_marque.value)
			getParams += '&id_marque='+id_marque;
		if(id_modele = thisForm.id_model.value)
			getParams += '&id_model='+id_modele;
		if(prix = thisForm.prix.value)
			getParams += '&prix='+prix;
		if(thisForm.anne_modele.value!='')
			getParams += '&anne_modele='+thisForm.anne_modele.value;
		if(thisForm.id_departament.value!='')
			getParams += '&id_departament='+thisForm.id_departament.value;
		*/
	}else if (section == 'nautisme'){
		getParams += '&id_coque='+thisForm.id_coque.value+'&marque='+thisForm.marque.value;
		getParams += '&prix='+thisForm.prix.value+'&id_departament='+thisForm.id_departament.value;
	}else if (section == 'habitation'){
		getParams += '&id_categorie='+thisForm.id_categorie.value+'&nr_piese='+thisForm.nr_piese.value+'&id_type='+thisForm.id_type.value;
		getParams += '&prix='+thisForm.prix.value+'&id_departament='+thisForm.id_departament.value;
	}
	
	otherFrame.src=otherFrameSrc+getParams;
	//otherFrame.src='../site_structure/ex_6_dernieres_annonces.php?script_self=/occasion/voitures/index.php';
	//alert(otherFrameSrc);
	return;
}

function ifConfirmRedirectIframe(textConfirm, urlRedirect, objName){
	objId = parent.document.getElementById(objName);
	if(confirm(textConfirm)){
		objId.src=urlRedirect;
	}else
		return;
}

//form functions
function verifyForm(formName){
	var text_alert='';

	//define alert texts
	var text_name='Votre nom SVP.\n';
	var text_mail='Verifiez votre addrese d\'e-mail.\n';
	var text_name_friend='Le nom de votre ami SVP.\n';
	var text_mail_friend='Verifiez l\'addrese e-mail de votre ami.\n';
	var text_login='Votre pseudo SVP.\n';
	var text_pass='Votre mot de passe SVP.\n';
	var text_prix_min_max='Entrée au moins un prix.\n';
	
	//var text_search='Search string too short. Mimimum length is 4 characters.\n';
	thisForm = document.getElementById(formName);

	if(thisForm.name=='_f_login'){
		if(thisForm.login.value=='')
			text_alert += text_login;
		if(thisForm.pass.value=='')
			text_alert += text_pass;
		if(text_alert==''){
			thisForm.submit();
			return 1;
		}else
			alert(text_alert);
	}else if(thisForm.id=='_recherche_mon_compte'){
		if(thisForm.prix_min.value=='' & thisForm.prix_max.value=='')
			text_alert += text_prix_min_max;
		if(text_alert==''){
			thisForm.submit();
			return 1;
		}else
			alert(text_alert);			
	}

}

function login_pop(){
	window.opener.location.reload();
	window.close();
}

//collection of functions => hidden div to display big thumbs 
//mouse position - a part of layer with big pic onclick
function getMouseCoords(){
	var e = window.event;
	xMousePos = 0;
	yMousePos = 0;
	// Netscape
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
	// Internet Explorer
    } else if (document.all) {
        xMousePos = e.x+document.body.scrollLeft;
        yMousePos = e.y+document.body.scrollTop;
	// Netcsape 6
    } else if (document.getElementById) {
        xMousePos = 130 + window.scrollX;
        //yMousePos = event.pageY;
        yMousePos = 130 + window.scrollY;
    }
    mouseCoords = new Array (xMousePos, yMousePos);
    return mouseCoords;
}
//
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

//picture layer functions
function layerObject(thisId,left,top) {
	this.obj = document.getElementById(thisId);
	this.obj.style.left = left;
	this.obj.style.top = top;
	return this.obj;
}

function show(picLayerId, picHeight) {
	//hide first
	floatLyr = new layerObject(picLayerId, -1300, 0);
	//test if in frame
	var test_frame=document.location+"";
	var test2=test_frame.indexOf("_iframe");
	if(test2>=0){
		x_left=10;
		y_top=20;
	}else{
		var browserName=navigator.appName;
		if(browserName=="Microsoft Internet Explorer"){
			var coords=mouse_pos();
			x_left=coords[0];
			//y_top=(coords[1]-picHeightHalf);
			y_top=Math.round(coords[1]-(picHeight/2));
	
			//window.status="x: "+x_left+"y: "+y_top+" picH: "+picHeight;
			if(!isNumber(x_left) || x_left<1)
			//if(!(typeof x_left =='number') || x_left<1)
				x_left=400;
			if(!isNumber(y_top) || y_top<1)
				y_top=300;
		}else{
			var coords= new Array(200, 200);
			x_left=coords[0];
			y_top=Math.round(coords[1]-picHeight/2);
			if(y_top<60)
				y_top=60;
		}
	}
	floatLyr = new layerObject(picLayerId, x_left, y_top);
}

function show_2(picLayerId, picLayerWidth, picLayerHeight){
	obj = document.getElementById(picLayerId);
	coord = getMouseCoords();
	var windowX = document.body.clientWidth;
	var windowY = document.body.clientHeight;
	//alert(picLayerWidth+' '+picLayerHeight)
	//keep floating layer inside window :)
	if((coord[0]+picLayerWidth) > windowX)
		coord[0] = windowX-picLayerWidth;
	if((coord[1]+picLayerHeight) > windowY)
		coord[1] = windowY-picLayerHeight;
	//finnally bring floating layer into the visible part
	obj.style.left = coord[0];
	obj.style.top = coord[1];
}

function hide(picLayerId) {
	obj = document.getElementById(picLayerId);
	coord = getMouseCoords();
	obj.style.left = -1000;
	obj.style.top = -1000;
}
//end layer
//end collection of functions
