function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v;
    
    //alert(obj.h_display);
    //if ((obj.h_display != 'undefined')  ) {
    if ((obj.display=="none") && (v=="visible")) {
    	//alert("aaa");
    	obj.display=(obj.h_display != null?obj.h_display:"");
    }
  }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function P7_Snap() { //v2.62 by PVII
  var x,y,ox,bx,oy,p,tx,a,b,k,d,da,e,el,args=P7_Snap.arguments;a=parseInt(a);
  for (k=0; k<(args.length-3); k+=4)
   if ((g=MM_findObj(args[k]))!=null) {
    el=eval(MM_findObj(args[k+1]));
    a=parseInt(args[k+2]);b=parseInt(args[k+3]);
    x=0;y=0;ox=0;oy=0;p="";tx=1;da="document.all['"+args[k]+"']";
    if(document.getElementById) {
     d="document.getElementsByName('"+args[k]+"')[0]";
     if(!eval(d)) {d="document.getElementById('"+args[k]+"')";if(!eval(d)) {d=da;}}
    }else if(document.all) {d=da;} 
    if (document.all || document.getElementById) {
     while (tx==1) {p+=".offsetParent";
      if(eval(d+p)) {x+=parseInt(eval(d+p+".offsetLeft"));y+=parseInt(eval(d+p+".offsetTop"));
      }else{tx=0;}}
     ox=parseInt(g.offsetLeft);oy=parseInt(g.offsetTop);var tw=x+ox+y+oy;
     if(tw==0 || (navigator.appVersion.indexOf("MSIE 4")>-1 && navigator.appVersion.indexOf("Mac")>-1)) {
      ox=0;oy=0;if(g.style.left){x=parseInt(g.style.left);y=parseInt(g.style.top);
      }else{var w1=parseInt(el.style.width);bx=(a<0)?-5-w1:-10;
      a=(Math.abs(a)<1000)?0:a;b=(Math.abs(b)<1000)?0:b;
      x=document.body.scrollLeft + event.clientX + bx;
      y=document.body.scrollTop + event.clientY;}}
   }else if (document.layers) {x=g.x;y=g.y;var q0=document.layers,dd="";
    for(var s=0;s<q0.length;s++) {dd='document.'+q0[s].name;
     if(eval(dd+'.document.'+args[k])) {x+=eval(dd+'.left');y+=eval(dd+'.top');break;}}}
   if(el) {e=(document.layers)?el:el.style;
   var xx=parseInt(x+ox+a),yy=parseInt(y+oy+b);
   if(navigator.appName=="Netscape" && parseInt(navigator.appVersion)>4){xx+="px";yy+="px";}
   if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1){
    xx+=parseInt(document.body.leftMargin);yy+=parseInt(document.body.topMargin);
    xx+="px";yy+="px";}e.left=xx;e.top=yy;}}
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=490,left = 312,top = 184');");
}

function popUpG(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=700,left = 312,top = 184');");
}
	
function popUpPrint(URL) {
	//alert(URL);	
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=500,height=450,left = 312,top = 184');");
}

function popUpD(URL,w,h) {
	window.open(URL,'view', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + w + ',height=' + h + ',left = 312,top = 184');
}

function popUp2(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=690,left = 312,top = 184');");
}

// Show&Hide Funkcija za Izbiro Okvirja
function showit(box) {
	document.getElementById(box).style.display="block";
}

function closeit(box){
	document.getElementById(box).style.display="none";
}

var aktivenDiv = 0;

function pokaziDiv(obj,i) {
	closeit('div1');
	closeit('div2');
	showit('div'+i);
	
	if (i != aktivenDiv) {
		if (aktivenDiv > 0) {
			var old = document.getElementById('za'+aktivenDiv);
			old.onmouseover = old.old_onmouseover;
			old.onmouseout = old.old_onmouseout;
			old.onmouseover();
			old.onmouseout();
		}
		obj.onmouseover();
		obj.old_onmouseover = obj.onmouseover;
		obj.onmouseover = null;
		obj.old_onmouseout = obj.onmouseout;
		obj.onmouseout = null;
		aktivenDiv = i;
	}
}

function pokaziDiv1(obj,i) {
	closeit('div1');
	closeit('div2');
	showit('div'+i);
}

// *******************************************************************************

function displayBusyIndicator(img,show) 
{
	if (show) {
		document.getElementById(img).style.visibility = 'visible';
	} else {
		document.getElementById(img).style.visibility = 'hidden';
	}
}

function displayDisabledButton(btn,show) 
{	
	var btn = document.getElementById(btn);
	var btnSrc = btn.src;
	var tmpBtnSrc = document.tmpButton;	
	var srcDisabled = btn.getAttribute('srcDisabled');
	
	if (srcDisabled != null) {			
		if (!tmpBtnSrc) {		
			document.tmpButton = btnSrc;
		}
		
		if (show) {
			btn.src = srcDisabled;
		} else {
			btn.src = tmpBtnSrc;
			document.tmpButton = '';
		}	
	}
}

function disableFormElements(formName,bool) {	
	for (var i=0; i<document.forms[formName].elements.length;i++) {
		document.forms[formName].elements[i].disabled = bool;
	}
}

// *******************************************************************************
// -----------------  A J A X   L O G I N   F U N C T I O N S --------------------
function ajaxLogin(formName,redirect) 
{
	var INPUT_email = document.getElementById('INPUT_email');
	var INPUT_password = document.getElementById('INPUT_password');
	var TD_statusMsg = document.getElementById('TD_statusMsg');			
	
	if (INPUT_email.value == '') 
	{
		//error status message
		TD_statusMsg.className = 'registracijaError2';
		TD_statusMsg.innerHTML = 'Please enter your email.';				
		INPUT_email.focus();
	} 
	else if (INPUT_password.value == '')
	{
		//error status message
		TD_statusMsg.className = 'registracijaError2';
		TD_statusMsg.innerHTML = 'Please enter your password.';						
		INPUT_password.focus();
	}
	else 
	{	
		if (AjaxRequest.numActiveAjaxRequests==0) 
		{					
			//disable button & show busy indicator
			displayDisabledButton('INPUT_signIn',true);
			displayBusyIndicator('IMG_busyIndicator',true);
			
			// clear status message			
			TD_statusMsg.className = '';
			TD_statusMsg.innerHTML = '';			
			
			AjaxRequest.submit(
		    document.forms['login']
		    ,{
		    	 'onLoading':function() {
		    			disableFormElements(formName,true);
		    		}		    	
		    	 ,'onComplete':function() { 
		    	 		displayBusyIndicator('IMG_busyIndicator',false); 
		    	 		displayDisabledButton('INPUT_signIn',false); 
		    	 		disableFormElements(formName,false);
		    	 	}
		       ,'onSuccess':function(req){ 
		      		ajaxLoginCheck(req.responseText,redirect); 
		      	}    			
		       ,'onError':function(req) { 
		      		alert('Uknown error'); 
		      	}
		    }
		  );		
		}	
	}
}

function ajaxLoginCheck(responseText,redirect) 
{				
	var response;
	var statusCode;
	var statusMsg;
	var TD_statusMsg = document.getElementById('TD_statusMsg');
	var INPUT_email = document.getElementById('INPUT_email');
	var addressMsg;
  var typ = 2; // redirect
  	
	// DEBUG
	if (document.ajaxDebug) {
		alert(responseText);
	}
	
	response = responseText.split(';');
	statusCode = parseInt(response[0]);
	statusMsg = response[1];
	
	if (statusCode == -1) {
		TD_statusMsg.className = 'registracijaError2';
		TD_statusMsg.innerHTML = statusMsg;
		INPUT_email.focus();
	} else if (statusCode == 1) {
		window.location = redirect;
	} else if (statusCode == 2) // OK with dynamic redirect
	{	
		redirect = response[2];		
		if (redirect != '') {
			if (typ == 1) {
				document.forms[formName].action = redirect
				document.forms[formName].submit();
			} else if (typ == 2) {
				window.location = redirect;
			}	else {
				err = true;
				errMsg = 'Unknown error [typ]';
			}
		} else {
			err = true;
			errMsg = 'Unknown error [redirect]';
		}
	} else {
		TD_statusMsg.className = 'registracijaError2';
		TD_statusMsg.innerHTML = 'Unknown error.';
	}		
}

// *******************************************************************************
// --------------------- A J A X   F O R M   S U B M I T  ------------------------
// * Function ajaxFormSubmit (formName,redirect,typ)
// *
// * formNam.... form name ... what else? :)
// * redirect... where to submit/redirect form/page after ajax submit
// * typ........ what to do after ajax submit (1->submit, 2->redirect)
// * i.......... form number (multiple form support)
// -------------------------------------------------------------------------------
function ajaxFormSubmit(formName,redirect,typ,i) {
	
	if (AjaxRequest.numActiveAjaxRequests==0) {				
		
		// show busy indicator
		if (i) {} else { i = '';}
		
		displayBusyIndicator('IMG_busyIndicator'+i,true);				
		displayDisabledButton('INPUT_postButton'+i,true);
						
		// clear status message
		var TR_statusMsg = document.getElementById('TR_statusMsg');
		var TD_statusMsg = document.getElementById('TD_statusMsg');			
		TR_statusMsg.style.display = 'none';
		TD_statusMsg.className = '';
		TD_statusMsg.innerHTML = '';
												
		// Ajax Request
		AjaxRequest.submit(
    	document.forms[formName]
    	,{
    		'onLoading':function() {
    			disableFormElements(formName,true);
    		}
    	 	,'onComplete':function() { 
    	 		displayBusyIndicator('IMG_busyIndicator'+i,false); 
    	 		displayDisabledButton('INPUT_postButton'+i,false);
    	 		disableFormElements(formName,false);
    	 	}
      	,'onSuccess':function(req){ 
      		ajaxFormSubmitCheck(req.responseText,redirect,formName,typ,i); 
      	}
      	,'onError':function(req) { 
      		alert('Uknown error'); 
      	}
	    }
  	);		
	}	
}

function ajaxFormSubmitCheck(responseText,redirect,formName,typ,i) {	
	var response;
	var statusCode;
	var statusMsg;
	var TR_statusMsg = document.getElementById('TR_statusMsg');
	var TD_statusMsg = document.getElementById('TD_statusMsg');			
	var err = false;
	var errMsg;
			
	response = responseText.split(';');	
	statusCode = parseInt(response[0]);
	statusMsg = response[1];

	// DEBUG
	if (document.ajaxDebug) {
		alert(responseText);
	}
	//document.getElementById('TR_statusMsg').style.display = '';
	//document.getElementById('TD_statusMsg').innerHTML = '<PRE>'+responseText+'</PRE>';
	//return;

	//if (statusCode < 0 || typ == 1) {
	//	displayBusyIndicator('IMG_busyIndicator'+i,false); 
  //  displayDisabledButton('INPUT_postButton'+i,false);
  //  disableFormElements(formName,false);
	//}
	
	// *-----------------------------------------------------------------------------
	// * status codes:
	// * -1 ........ Simple error
	// * -2 ........ Error with automatic redirect
	// * -3 ........ Error with input focus
	// *  1 ........ OK
	// *  2 ........ OK with dynamic redirect
	// *  3 ........ custom function call
	// -------------------------------------------------------------------------------	
	if (statusCode == -1) // Error
	{
		err = true;
		errMsg = statusMsg;
				
	} 
	else if (statusCode == -2)  // Error with automatic redirect
	{		
		redirect = response[2];
		document.redirect = redirect;
		if (redirect != '') {
			TR_statusMsg.style.display = '';
			TD_statusMsg.className = 'registracijaError';
			TD_statusMsg.innerHTML = statusMsg;
			setTimeout('window.location = document.redirect',5000);
		} else {
			err = true;
			errMsg = 'Unknown error [redirect:2]';			
		}
	} 
	else if (statusCode == -3) // Error with input focus
	{
		fokus = response[2];		
		if (fokus != '') {					
			err = true;
			errMsg = statusMsg;
			if (document.forms[formName].elements[fokus]) {
				if (document.forms[formName].elements[fokus].length > 0) {
					document.forms[formName].elements[fokus][0].focus();
				} else {			
					document.forms[formName].elements[fokus].focus();
				}
			}
		} else {
			err = true;
			errMsg = 'Unknown error [focus]';
		}
	}
	else if (statusCode == 1) // OK
	{
		if (typ == 1) {
			document.forms[formName].action = redirect
			document.forms[formName].submit();
		} else if (typ == 2) {
			window.location = redirect;
		}		
	} 
	else if (statusCode == 2) // OK with dynamic redirect
	{	
		redirect = response[2];		
		if (redirect != '') {
			if (typ == 1) {
				document.forms[formName].action = redirect
				document.forms[formName].submit();
			} else if (typ == 2) {
				window.location = redirect;
			}	else {
				err = true;
				errMsg = 'Unknown error [typ]';
			}
		} else {
			err = true;
			errMsg = 'Unknown error [redirect]';
		}
	}	
	else if (statusCode == 3) // custom function call
	{	
		errMsg = handleAjaxResponse(statusMsg);
		if (errMsg != undefined) 			
			err = true;
	}		
	else 
	{
		err = true;
		errMsg = 'Unknown error [statusCode = ' + statusCode + '] in response: ' + responseText;
	}			
	
	if (err) // show error
	{
		TR_statusMsg.style.display = '';
		TD_statusMsg.className = 'registracijaError';
		TD_statusMsg.innerHTML = errMsg;	
		window.scrollTo(0,100);
	}	 
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function P7_hideDiv(evt) { //v1.3 by PVII
 var b,relT,mT=false; 
 if(document.layers){b=evt.target;if(b.p7aHide){
  b.visibility="hidden";b.h_display=b.display;b.display="none";}else{routeEvent(evt);}
 }else if(document.all&&!window.opera){b=event.srcElement;
  while(b!=null){if(b.tagName=="DIV" && b.p7ahD){mT=true;break;}b=b.parentElement;}
  if(!b.contains(event.toElement)){b.style.visibility="hidden";b.style.h_display=b.style.display;b.style.display="none";}
 }else if(document.getElementById){b=evt.currentTarget;relT=evt.relatedTarget;
  while(relT!=null){if(b==relT){mT=true;break;}
  relT=relT.parentNode;}if(!mT){b.style.visibility="hidden";b.style.h_display=b.style.display;b.style.display="none";}}  
}

function P7_autoHide() { //v1.3 by PVII
 var i,g,args=P7_autoHide.arguments;
 for(i=0;i<args.length;i++){if((g=MM_findObj(args[i]))!=null){
  g.p7aHide=true;if(document.layers){
  g.captureEvents(Event.MOUSEOUT);}g.onmouseout=P7_hideDiv;g.p7ahD=true;}}
}

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}

function NoFormat(obj)
{
	if (isNaN(parseInt(obj.value))) {
		obj.value = ''
	} else {
		obj.value = parseInt(obj.value);
	}
}

function authors()
{
  var w = screen.width;
  var h = screen.height;
  var ow = 290;
  var oh = 175;
  var ol = parseInt((w-ow-10)/2);
  var ot =  parseInt((h-oh-40)/2);
  if (ot < 0){ ot = 0; }
  
  var HTMLPopUp = window.open ('/jeans/authors', 'Authors', 'width='+ow+',height='+oh+',left='+ol+',top='+ot)
}


// -----------------------------------------------
// Begin cookie functions
// -----------------------------------------------
 
// getCookieData() function is called from other cookie functions
// Takes cookie label as argument, returns cookie value or null
// -----------------
function getCookieData(label) {
    var labelLen = label.length
    var cLen = document.cookie.length
    var i = 0
    var cEnd
    while (i < cLen) {
        var j = i + labelLen
        if (document.cookie.substring(i,j) == label) {
            cEnd = document.cookie.indexOf(";",j)
            if (cEnd == -1) {
                cEnd = document.cookie.length
            }
            return unescape(document.cookie.substring(j,cEnd))
        }
        i++
    }
    return null
}
 
// loadCookieData() function is called from page with the contact form
// Populates hidden form fields in the first form of the page
// -----------------
function loadCookieValues()
{		
 if (getCookieData("cookieRefURL"))
 { 	
                                     //var field1 = document.forms[1].cRefURL
  var field1 = document.getElementById('cRefURL');  
  field1.value = getCookieData("cookieRefURL")
                                    //var field2 = document.forms[1].cLandURL
  var field2 = document.getElementById('cLandURL');
  field2.value = getCookieData("cookieLandURL")
                                     //var field3 = document.forms[1].cDate
  var field3 = document.getElementById('cDate');
  field3.value = getCookieData("cookieDate")
  
 }
}
 
// cookieTreat() function is called from every page on the site
// Checks if cookies exist, if not - three cookie values are written
// -----------------
function cookieTreat() 
{
 var exp = new Date()
 var oneYearFromNow = exp.getTime() + (365 * 24* 60 * 60 * 1000)
 exp.setTime(oneYearFromNow)
 
 var today = new Date()
 
 var checkref = new String(" ")
 if(document.referrer.length > 0)
  {
  checkref = checkref + document.referrer
  }
 else
  {
  checkref = checkref + "No Referrer"
  }
 
 // set document cookie if they have not been written yet
 // if referrer cookie exists, do nothing
 // otherwise write all three cookies
 
 if (getCookieData("cookieRefURL") && getCookieData("cookieLandURL") && getCookieData("cookieDate")) { 
 }
 else {
  document.cookie = "cookieRefURL=" + checkref + "; domain=.mytruefit.com; expires=" + exp.toGMTString() + "; path=/"
  document.cookie = "cookieLandURL=" + location + "; domain=.mytruefit.com; expires=" + exp.toGMTString() + "; path=/"
  document.cookie = "cookieDate=" + today + "; domain=.mytruefit.com; expires=" + exp.toGMTString() + "; path=/"
 }
}
 
// -----------------------------------------------
// End cookie functions
// -----------------------------------------------

