// --------------------------------------------------
// 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(fullform) {
	
	if ( noshipaddr == 1 ) {
	
		$('#Liefer-Anschrift').attr('checked', false); 
		$('#Liefer-Anschrift').attr('disabled', 'disabled');	
	}

	if ( $('#Liefer-Anschrift').is(':checked') ) {

		$('#os_order').css("display", "block") ;
		orderformact($('#os_order')) ;
		
		if ( fullform == 1 ) {

			if  ( $('#Versandland').val() != 'Deutschland' ) {
				
				$('#os_pack').css("display", "none") ;
				$('#Liefer-Packstation').removeAttr('checked') ;
			}
		
			if ( $('#Liefer-Packstation').is(':checked') ) {
			
				$('#os_order_pack').css("display", "block") ;
				orderformact($('#os_order_pack')) ;
				
				$('#os_order_address').css("display", "none") ;
				orderformdel($('#os_order_address')) ;
				
			} else {
	
				$('#os_order_address').css("display", "block") ;
				orderformact($('#os_order_address')) ;
				
				$('#os_order_pack').css("display", "none") ;
				orderformdel($('#os_order_pack')) ;
			}
		}
		
	} else {
		
		$('#os_order').css("display", "none") ;
		orderformdel($('#os_order')) ;
	}
}


function orderformdel(htele) {

	$(htele).find(':input').each(function() {  

       	switch(this.type) {  
         	case 'password':  
	        case 'select-multiple':  
			case 'select-one':  
			case 'text':  
			case 'textarea':  
				$(this).val('');  
				break;  
			case 'checkbox':  
			case 'radio':  
				this.checked = false;  
		}  
		
		$(this).attr("disabled",true) ; 
	});  	
}


function orderformact(htele) {

	$(htele).find(':input').each(function() {  

		$(this).removeAttr("disabled") ; 
	});  	
}


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 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_amount_change(scprice,ssuffix,schange){
	
	var newprice = scprice - 0 ;
	var dd2_10 = document.getElementById("dd2_10") ;
	var statusdel = 0 ;


	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 ;
		
		if ( fname.match(/^dd/) ) { 
		
			var fvar = new Array() ;
			
			if ( fname == 'dd1_01' ) {
				
				fvar = fvalu.split(",") ;
				
				if ( fvar[1]>0 || fvar[1]<0 ) {
					
					newprice = newprice - scprice ;
				}

				if ( schange==1 && fvar[3] ) {
					
					var dd2 = new Array() ;			
					dd2 = fvar[3].split(";") ;

					dd2_10.options.length = 1 

					for ( var y=0 ; y < dd2[y].length-1 ; y++ ) {

						var dd2val = new Array() ;
						dd2val = dd2[y].split(": ")  ;
						
						var addopt = new Option(dd2val[1],dd2[y]) ;
						dd2_10.options[y+1]=addopt ;
					}

				}
			
				if ( fvar[3] == 0 ) {

					fvar[3] = shipstdv ;
				}

				if ( fvar[3] > statusdel ) {
					
					statusdel = fvar[3] ;
				} 
				
			} else {
				
				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 ( statusdel >= 0 && statusdel <= 9 ) {
					
		var statusid = ( statusdel==0 ? shipstdv : statusdel ) ;
		document.getElementById('detailtmpdel').innerHTML = '<img src="' + syspathpics + '/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 == "NOCHOICEVAR" || 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 ;
}


function scart_ship_load() {
	
	$("#os_scart_wait").attr("src" , syspathpics + "/icon_wait.gif") ;
	$("#ORDER").css("display" ,"none") ;
	
	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();
		}	
	}
}


function ScartDetailSend(form,mode,source) {

	var fback = scart_amount_check(form) ;

	if ( fback ) {
		
		if ( mode == 2 ) {
			
			$.ajax({
   		
   				type: "POST" ,
   				cache: false ,
   				async: false ,
   				url: $(form).attr('action') + "&ajax=1&statuspop=1" ,
   				data: $(form).serialize() ,
   				error: function(jqXHR,textStatus,errorThrown){ form.submit() } ,
   				success: function(data,textStatus,jqXHR){
	   				
	   				if ( data == 'ERROR' ) {
	   					
	   					form.submit() ;
	   					
	   				} else {
	   				
						$("#os_scshort_content").html(data) ;
						$('#statuspop').slideToggle("slow") ;
						setTimeout(function(){ $('#statuspop').slideToggle("slow") } , 2500 ) ;
						$("#os_detail_butscart").attr("src" , syspathpics + "/buttons/" + syspathbuts + "/button_scart_detail.gif") ;
					}
				}
 			}) ;
 			
 		} else {
 			
 			return true ;
 		}
	} 
	
	return false ;
}


function ScartListSend(form,mode,source,button,buttid) {

	if ( mode == 2 ) {
		
		$(buttid).attr("src" , syspathpics + "/icon_wait.gif") ;
		var bstatus = 1 ;
		
		$.ajax({
   		
			type: "POST" ,
			cache: false ,
			async: false ,
			url: $(form).attr('action') + "&ajax=1&statuspop=1" ,
			data: $(form).serialize() + button ,
			error: function(jqXHR,textStatus,errorThrown){ bstatus = 1 } ,
			success: function(data,textStatus,jqXHR){
	   				
				if ( data == 'ERROR' ) {
	   				
   					bstatus = 1
					
  				} else {
 				
					$("#os_scshort_content").html(data) ;
					$('#statuspop').slideToggle("slow") ;
					setTimeout(function(){ $('#statuspop').slideToggle("slow") } , 2500 ) ;
					$(buttid).attr("src" , syspathpics + "/buttons/" + syspathbuts + "/button_inscartA.gif") ;
					bstatus = 0 ;
				}
			}
 		}) ;

 		return bstatus ; 
 			
 	} else {
 			
 		return 1 ;
 	}
}



// --------------------------------------------------
// Doppelklick verhindern : $('#form').prevDoubleSubmit();
// --------------------------------------------------

jQuery.fn.prevDoubleSubmit = function() {
	
	jQuery(this).submit(function() {
		
		if ( this.beenSubmitted ) {
      		return false ;
    	} else {
      		this.beenSubmitted = true ;
      	}
  	});
};



// --------------------------------------------------
// 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 ;
}


function epoqview(url,tar) {

	if ( url ) {

		$.get( syspathpics + '/appserv/proxy/?url=' + url ) ;
	}
	
	if ( tar ) {
			
		location.href = tar ;
		return false ;
	}
	
	return true ;
}



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


$(document).ready(function() {

	//DIV-Popup-Layer
	$('<div id="popupdivtarget" style="display:none" class="popupdivtarget"><div class="close"><img src="' + syspathpics + '/icon_detail_close.gif" border=0 /></div><iframe src="about:blank" id="popupdiviframe" class="popupdiviframe" scrolling="auto" frameborder="0"></iframe></div>').appendTo("body") ;
	
	//DIV-Popup
	var api = $("#popupdivtarget").overlay({
		
				api: true ,
				speed: 'fast' ,
				oneInstance: true, 
				top: 'center' , 
				left: 'center' ,
				mask : { color: '#c1c1c1' , opacity:0.8 , loadSpeed:0 , zIndex:10000 }
	}) ;
	
	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")) ;
	}
	
	//CCS für Validator
	$.validator.setDefaults({
		errorClass: "os_form_error" ,
		validClass: "os_form_valid" ,
		errorElement: "div"
	});
		
	//Preload-Wait-Pic
	if ( syspathpics ) {

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

	//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() ;
			}
		});
	}
	
	//Kein Doppelclick
	$('#os_order_last').prevDoubleSubmit();
	
}) ;

// --------------------------------------------------
// Bilderwechsel EKOMI
// --------------------------------------------------

var image = new Array();
var link  = new Array();

image[1] = '1.gif';
image[2] = '2.gif';
image[3] = '3.gif';
image[4] = '4.gif';
image[5] = '5.gif';
image[6] = '6.gif';
image[7] = '7.gif';
image[8] = '8.gif';
image[9] = '9.gif';
image[10] = '10.gif';

var num = Math.random();
var ran = Math.floor((image.length - 1) * num) + 1;



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

