// --------------------------------------------------
// Allgemeine Shop-Funktionen
// --------------------------------------------------


function navimainhide(nid) {

	$("#nav"+nid).css("display", "none") ;
}


function navimainset(nid) {

	$("#nav"+nid).css("display", "block") ;
}


function navihide(nid) {

	$("#nav"+nid).css("visibility", "hidden") ;
}


function naviset(nid) {

	$("#nav"+nid).css("visibility", "visible") ;
}


function orderset(nid,cbox,nodiv) {

	var objre = $("#"+nid) ;

	if ( cbox.checked ) {
		
		objre.css("display", "block") ;
		
	} else {
		
		objre.css("display", "none") ;

		for ( var i=0 ; i < document.Bestellung.elements.length ; i++ ) {
			
			var objfi = document.Bestellung.elements[i] ;
  			
  			if ( objfi.name.indexOf("Liefer-Anschrift") < 0 && objfi.name.indexOf("Liefer-") >= 0 ) {
  			
  				objfi.value = '' ;
  			}
  		} 
	}
}


function wopen(link,wi,he) {
	
	var width = wi ;  
	var height = he ;
	var l = (screen.availWidth-width)/2 ;
	var t = (screen.availHeight-height)/2 ;
    wincom = window.open(link ,"oswin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+wi+",height="+he+",screenX="+l+",screenY="+t+",left="+l+",top="+t);
    
    if (wincom) {
    	wincom.focus() ;
	} else {
		alert(statustext) ;
	}
}


function wopencheck(link,wi,he) {

	var width=wi; var height=he;
	var l=(screen.availWidth-width)/2;
	var t=(screen.availHeight-height)/2;
    
    wincom=window.open(link ,"oswin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+wi+",height="+he+",screenX="+l+",screenY="+t+",left="+l+",top="+t);

	if (wincom) { 
		
		wincom.focus() 
	}
	
	return false ;
}


function dellink(link,btext) {

	Check = confirm(btext);

	if(Check == false) {
		
		return ;
		
	} else {
		
		window.open(link,'_self') ;
	}
}


function changebutton(s) {
	
    window.Bestellung.obutton.value = "Bitte warten ... und diesen Button nur 1x klicken !!!!";
    
    if (SEND==1) {
    	
    	alert("Sie haben die Bestellung bereits abgeschickt, bitte warten Sie auf Antwort des Shop-Servers !") ;
    	return false ;
    	
    } else {
    	
    	SEND=1 ;
    	return true ;
    }
}


function fielddel(f) {

	if ( f.value == f.defaultValue ) {
	
		f.value = "" ;
	}
}


function fieldset(f) {

	if ( f.value == "" ) {
		
		f.value = f.defaultValue ;
	}
}


function fieldemp(f) {

	if ( f.sbeg.value == f.sbeg.defaultValue ) {
		
		f.sbeg.value = "" ;
	}
}


function tabbgcolor(tabid,hrefid){

	if ( $("#"+tabid).length ) {

		$("#"+tabid).addClass("os_head_navi_active_cell") ;
	}
	
	if ( $("#"+hrefid).length ) {
	
		$("#"+hrefid).addClass("os_head_navi_active_href") ;
	}
} 


// --------------------------------------------------
// Varianten-Update und Check in Detailansicht
// --------------------------------------------------


function scart_help_change(stext,sid){
	
	if ( stext && sid > 0 ) {
	
		$('#os_detail_help'+sid).html(stext) ;
	}
}


function scart_amount_change(sform,scprice,ssuffix,schange,shelpid){
	
	var newprice = scprice - 0 ;
	var statusdel = 0 ;
	
	if ( sform.value ) {
		
		var fvar = new Array() ;				
		fvar = sform.value.split("#") ;
		
		if ( fvar[6] > 0 ) {
			
			if ( fvar[7] ) {
				$('#os_detail_help'+fvar[6]).html(fvar[7]) ;
			} else {
				$('#os_detail_help'+fvar[6]).html($('#os_detail_org'+fvar[6]).html()) ;
			}
		}
	}
	
	for ( i=0 ; i < document.forms['os_detail_view'].elements.length ; i++ ) {
		
		var fname = document.forms['os_detail_view'].elements[i].name ;
		var fvalu = document.forms['os_detail_view'].elements[i].value ;	
		var fleng = document.forms['os_detail_view'].elements[i].checked ;	
		
		if ( fname.match(/^dd2_/) && fvalu && ( fleng || fleng == undefined ) ) { 

			var fvar = new Array() ;				
			fvar = fvalu.split("#") ;
					
			if ( fvar[4] == 0 ) {

				fvar[4] = shipstdv ;
			}
					
			if ( fvar[4] > statusdel ) {
							
				statusdel = fvar[4] ;
			}
			
			var addprice = fvar[1] - 0 ;

			if ( addprice>0 || addprice<0 ) {

				newprice = newprice + addprice - 0 ;
			}
			
			if ( !sform.value && fvar[6] > 0 ) {
			
				if ( fvar[7] ) {
					$('#os_detail_help'+fvar[6]).html(fvar[7]) ;
				} else {
					$('#os_detail_help'+fvar[6]).html($('#os_detail_org'+fvar[6]).html()) ;
				}
			}
		}
	}
	
	if ( statusdel >= 0 && statusdel <= 9 ) {
					
		var statusid = ( statusdel==0 ? shipstdv : statusdel ) ;
		document.getElementById('detailtmpdel').innerHTML = '<img src="' + picship + '/status_' + statusid + '.gif" alt="' + shipping[statusdel] + '" align=absmiddle> ' + shipping[statusdel] ;
	}
	
	newprice = scart_amount_round(newprice) ;
	document.getElementById('detailtmpsum').innerHTML = newprice + " " + ssuffix ;
}


function scart_amount_round(x) {
	
  	var k = (Math.round(x * 100) / 100).toString();
  	k += (k.indexOf('.') == -1)? '.00' : '00';
  	var t = k.substring(0, k.indexOf('.') + 3);
	return t ;
}


function scart_amount_check(formobj) {
	
	for ( i=0 ; i < formobj.elements.length ; i++ ) {
		
		var fname = formobj.elements[i].name ;
		var fvalu = formobj.elements[i].value ;
		
		if ( fname.match(/^dd/) && ( fvalu == "XXXYYY" || fvalu == "" ) ) { 
					
			alert("Wählen Sie bitte alle Varianten aus !!") ;
			return false ;							
		}
	} 
	
	if ( $("#os_detail_butscart").length ) {
		
		$("#os_detail_butscart").attr("src" , syspathpics + "/icon_wait.gif") ;
	}
	
	return true ;
}


// --------------------------------------------------
// Scart-Funktionen
// --------------------------------------------------


function ScartShortDiv(mode) {
	
	if ( $("#os_head_scshort_all_id") ) {
	
		if ( mode == 1 ) {
			
			$("#os_head_scshort_all_id").show();
			
		} else {
			
			$("#os_head_scshort_all_id").hide();
		}	
	}
}


// --------------------------------------------------
// Image-Popup-Funktionen
// --------------------------------------------------


function ImageTrailShow(lpicid,thumbx,thumby,width,height,file) {

	if ( $("trailimageid").length ) {
	
		var xyimg  = $("#"+lpicid).offset() ;
		var xcoord = parseInt( xyimg.left + thumbx + 10 ) ;
		var ycoord = parseInt( xyimg.top ) ; //- ( ( height - thumby ) / 2 ) ) ;
		
		$("#trailimageid").css("visibility", "visible") ;
		$("#trailimageid").css("width", width + "px") ;
		$("#trailimageid").css("height", height +"px") ;
		$("#trailimageid").css("left", xcoord + "px") ;
		$("#trailimageid").css("top", ycoord + "px") ;
		
		$('#ttimg').attr('src',file) ;
	}
}


function ImageTrailHide() {
	
	if ( $("#trailimageid").length ) {
	
		$('#ttimg').src = $("#ttimg").rel ;
		$("#trailimageid").css("visibility", "hidden") ;
		$("#trailimageid").css("left", "-1000") ;
		$("#trailimageid").css("top", "0") ;
	}
}



// --------------------------------------------------
// Bilderwechsel Detailansicht
// --------------------------------------------------

var DetailStdPic = '' ;

function DetailPicChange(link,piclink) {
	
	if ( !DetailStdPic ) {
	
		DetailStdPic = $('#os_detail_pic').attr('src') ;
	}
	
	//alert($(link).attr('src')) ;
	
	if ( piclink ) {
		
		$('#os_detail_pic').attr('src',piclink) ;
		$('#os_detail_piclink').attr('href',$(this).attr('href')) ;
		
	} else {
		
		$('#os_detail_pic').attr('src',DetailStdPic) ;
	}
	
	return false ;
}



// --------------------------------------------------
// Rating-Funktionen
// --------------------------------------------------


function RateFormShow() {

	$('#os_rate').css("display","block") ;
}

function RateFormCheck(form) {

     if(!form.rate_tit.value) {
	   alert("Geben Sie bitte einen Titel ein !");
       form.rate_tit.focus();
       return false;
     }     

     if(!form.rate_txt.value) {
	   alert("Geben Sie bitte einen Text ein !");
       form.rate_txt.focus();
       return false;
     }     
}



// --------------------------------------------------
// Top-Navi mit Flyout
// --------------------------------------------------


function MenuView(subm) {

	var mlink = $(subm) ;
	
	mlink.find("a:first").addClass("act") ;
	mlink.find("ul").css("display", "block");
}


function MenuHide(subm) {
	
	var mlink = $(subm) ;
	
	mlink.find("a:first").removeClass("act") ;
	mlink.find("ul").css("display", "none");
}



// --------------------------------------------------
// URL-Parameter auslesen
// --------------------------------------------------


function getUrlVars() {

	var vars = [], hash ;
	var hashes = window.location.href.slice(window.location.href.indexOf('?')+1).split('&') ;

	for(var i = 0; i < hashes.length; i++) {        

		hash = hashes[i].split('=') ;
		vars.push(hash[0]) ;
		vars[hash[0]] = hash[1] ;
	}

	return vars ;
}



// --------------------------------------------------
// Addons
// --------------------------------------------------


function wopenTwitter(content) {
    
    var add = ( content ? content : window.location.href ) ;
    var url = "http://twitter.com/home?status=Gerade%20gesehen:%20" + add ;
    window.open(url,'_blank');
    
    return false ;
}



// --------------------------------------------------
// Status-Popup-Funktionen
// --------------------------------------------------


$(document).ready(function() {

	//DIV-Popup
	var api = $("#popupdivtarget").overlay({
		
				api: true ,
				speed: 'fast' ,
				oneInstance: false, 
				finish : { top: 'center' , left: 'center' } ,
				expose : { color: '#c1c1c1' , opacity: 0.8 , loadSpeed: 0 , closeSpeed: 0 }
	}) ;
	
	window.StatusOverlay = function(iframeurl,sizex,sizey) { 
		
		if ( $("#popupdivtarget").length ) {

			if ( $("#popupdiviframe").length ) {
	
				$("#popupdiviframe").attr("src",iframeurl) ;
			}
	
			if ( sizex > 0 && sizey > 0 ) {
	
				$("#popupdivtarget").css("width",sizex+"px") ;
				$("#popupdivtarget").css("height",sizey+"px") ;
				$("#popupdiviframe").css("height",sizey+"px") ;
			}
			
			api.load(); 			
			
			return false ;
		}
	} 
	
	//Counter-Gif
	if ( $("#os_main_shoppage").length ) {
				
		$("<img src=\"" + syspathpics + "/appserv/stats/logstats.php?referer=" + unescape(top.document.referrer) + "&resw=" + screen.width + "&resh=" + screen.height + "&color=" + screen.colorDepth + "\" width=1 height=1 border=0 alt=\"\">").appendTo($("#os_main_shoppage")) ;
	}
	
	//Detail-Init
	if ( $("#os_detail_view").length ) {
		
		$("ul.tabtabstyle").tabs("div.tabcontentstyle > div");
	
		$("a[rel][rel!=nofollow]").overlay({
		
			onBeforeLoad: function() {	$("#overlaypic").attr("src",this.getTrigger().attr("href")) ; } ,
			expose: { color: '#c1c1c1', opacity: 0.8, loadSpeed: 0, closeSpeed: 0 } ,
			speed: 'fast' ,
			close: 'img' 
		});
	}

	//Preload-Wait-Pic
	if ( syspathpics ) {

		var cacheWaitImage = document.createElement('img') ;
   		cacheWaitImage.src = syspathpics + "/icon_wait.gif" ;
   	}

	//Round-Corners
	var curvyCornersVerbose = false;
	
	//Auto-Complete
	if ( $("#sbeg").length ) {
	
		$("#sbeg").autocomplete( syspathshop + "?plugin=searchauto&wkid=" + scartsession , {
 			  		
 			width:300,
 			scrollHeight:300,
 			minChars:4,
 			max:15,
 			cacheLength:1,
 			selectFirst:false,
 			
 			formatItem: function(item) {
 				var mySplitResult = item[0].split("#",3) ;
    			return mySplitResult[1] ;
  			},
  			
  			formatResult: function(item) {
    			return $("#sbeg").val() ;
  			}
  					
		}).result(function(event, item) {
			
			var mySplitResult = item[0].split("#") ;
					
			if ( mySplitResult[0] > 0 ) {
				location.href = syspathshop + "?func=detailcall&wkid=" + scartsession + "&prodid=1&artnr=" + mySplitResult[0] ;
			} else {
				$("#os_search_form").submit() ;
			}
		});
	}

}) ;



// --------------------------------------------------
// END
// --------------------------------------------------

