// JavaScript Document

//////////////////////////////////////////////////
//												//
// copyright 2009 kuubz.com | www.kuubz.com		//
//												//
//////////////////////////////////////////////////

var baselink = "../";

function pulse() { // keep sessions alive
	setTimeout("pulse()", 60000);
	dopulse = new ajaxObject('inc/log.php', processResponse, 'pulse');
	dopulse.update();
} 

function showErrorBar(errorid,error){	
	parent.top.document.getElementById(errorid).style.display = "block";
	parent.top.document.getElementById(errorid).innerHTML= error;
	}
	
		
	function changeProdNum(num) {
	var source = 'amount'+num+'';
	var amount = document.getElementById(source).options.selectedIndex;
	var setamount= document.getElementById(source).options[amount].value;
	window.location = '?showcart&setid='+num+'&setnum='+setamount+'';		
	}
	
	
	function showCartLink(source){
		
		// show add-to-cart link if size is selected

	var subcat = document.getElementById(source).options.selectedIndex;
	var setsubcat = document.getElementById(source).options[subcat].value;
	
	if(setsubcat != '0'){
		showstuff('cartlink');
		hidestuff('dosize');
	} else {
		showstuff('dosize');
		hidestuff('cartlink');
	}	
}

function showPop(showwhat,id){

if(showwhat == 'cart'){
	
	var prodid = id;
		
	//header = 'Add Guestbook Entry';
	loadContent = new ajaxObject('inc/views.php',processResponse,'popContent');
	loadContent.update('view=cart&prodid='+prodid+'','GET');
	processWait(loadContent,'popContent','<img src=\"gfx/load.gif\" width=\"66\" height=\"66\">');
	    
    } 
	
	if(showwhat == 'cartno'){
	
	var prodid = id;
		
	//header = 'Add Guestbook Entry';
	loadContent = new ajaxObject('inc/views.php',processResponse,'popContent');
	loadContent.update('view=cartno&prodid='+prodid+'','GET');
	processWait(loadContent,'popContent','<img src=\"gfx/load.gif\" width=\"66\" height=\"66\">');
	    
    } 
	
	if(showwhat == 'wish'){
	
	var prodid = id;
		
	loadContent = new ajaxObject('inc/views.php',processResponse,'popContent');
	loadContent.update('view=wish&prodid='+prodid+'','GET');
	processWait(loadContent,'popContent','<img src=\"gfx/load.gif\" width=\"66\" height=\"66\">');
	    
    } 
	
	if(showwhat == 'access'){
	
	var url = id;
		
	loadContent = new ajaxObject('inc/views.php',processResponse,'popContent');
	loadContent.update('view=access&url='+url+'','GET');
	processWait(loadContent,'popContent','<img src=\"gfx/load.gif\" width=\"66\" height=\"66\">');
	    
    } 
	
	if(showwhat == 'photo'){
	
	var img = id;
		
	loadContent = new ajaxObject('inc/views.php',processResponse,'popContent');
	loadContent.update('view=photo&img='+img+'','GET');
	processWait(loadContent,'popContent','<img src=\"gfx/load.gif\" width=\"66\" height=\"66\">');
	    
    } 
	
	parent.top.document.getElementById('show').style.display = "block";
	parent.top.document.getElementById('pop').style.display = "block";
	//parent.top.document.getElementById('popHeader').innerHTML = header;
    
    }	

	
	// CLOSE POP
	
function hidePop() {
	document.getElementById('show').style.display = "none";
	document.getElementById('pop').style.display = "none";    
	//document.getElementById('popContent').style.display = "none";
	}
    
function showWait(){
    	
	document.getElementById('pop').style.display = "block";
	document.getElementById('pop_wait').style.display  = "block";
		
   }

function setinnerHTML(id,txt){
	document.getElementById(id).innerHTML= txt;
}

function addToCart(prodid){
	
	var setamount = '1';
	var setsize = '0';
	
	if (document.getElementById('prod_num')) { // check if element exists
	var amount = document.getElementById('prod_num').options.selectedIndex;
	var setamount = document.getElementById('prod_num').options[amount].value;
	}
	
	if (document.getElementById('prod_size')) { // check if element exists
	var size = document.getElementById('prod_size').options.selectedIndex;
	var setsize = document.getElementById('prod_size').options[size].value;
	}
	
	doAdd = new ajaxObject('inc/actions.php',processResponse,'ajaxload');
	doAdd.update('action=addToCart&prodid='+prodid+'&size='+setsize+'&amount='+setamount+'','GET');
	//doAdd.update('action=addToCart&prodid='+prodid+'&amount='+setamount+'','GET');
	processWait(doAdd,'ajaxload','');

}

function closeListItem(listid){
	
	doAdd = new ajaxObject('inc/actions.php',processResponse,'ajaxload');
	doAdd.update('action=moveToCart&listid='+listid+'','GET');
	processWait(doAdd,'ajaxload','');

}

function changeCart(){
	
	doChange = new ajaxObject('inc/views.php',processResponse,'headerContentTR');
	doChange.update('view=showcart','GET');
	processWait(doChange,'headerContentTR','');

}

function changeLogin(){
	
	doChange = new ajaxObject('inc/views.php',processResponse,'memlog');
	doChange.update('view=show_memstatus','GET');
	processWait(doChange,'memlog','');

}

function addToWishlist(prodid){
	
	doAdd = new ajaxObject('inc/actions.php',processResponse,'ajaxload');
	doAdd.update('action=addToWishlist&prodid='+prodid+'','GET');
	processWait(doAdd,'ajaxload','');

}


function loadSubcat(source){
	
	var subcat = document.getElementById(source).options.selectedIndex;
	var setsubcat= document.getElementById(source).options[subcat].value;
	
	loadMenu = new ajaxObject('inc/menus.php',processResponse,'subcat');
	loadMenu.update('menu=showSubcat&cat='+setsubcat+'','GET');
	processWait(loadMenu,'subcat','...subkategorien laden...');
	
	if(setsubcat == '3'){
		showStuff('dvd');
	} else {
		hideStuff('dvd');
	}	
}

function loadSubcat2(source){
	
	var subcat = document.getElementById(source).options.selectedIndex;
	var setsubcat= document.getElementById(source).options[subcat].value;
	
	loadMenu = new ajaxObject('inc/menus.php',processResponse,'subcat2');
	loadMenu.update('menu=showSubcat2&cat='+setsubcat+'','GET');
	processWait(loadMenu,'subcat2','...subkategorien laden...');
}

// LIMIT TEXT IN FIELDS

function counterUpdate(counttext, showcount, maxchar) {

        var field = document.getElementById(counttext);

        if (field.value.length >= maxchar) {
                field.value = field.value.substring(0, maxchar);
        }
       document.getElementById(showcount).innerHTML = maxchar - field.value.length;
}

function countCharacters(charcount,displaycount,maxchar){

	var field = document.getElementById(charcount);
	document.getElementById(displaycount).innerHTML = maxchar - field.value.length;

}

	

	// HIDE DIVS - COMBO
	
function hideCombo(id1,id2) {
	document.getElementById(id1).style.display = "none";
	document.getElementById(id2).style.display = "none";
	}
	
	// SHOW DIVS - COMBO
	
function showCombo(id1,id2) {
	document.getElementById(id1).style.display = "block";
	document.getElementById(id2).style.display = "block";
	}
	
	// HIDE DIV
	
function hidestuff(id) {
	document.getElementById(id).style.display = "none";
	}
	
	// SHOW DIV
	
function showstuff(id) {
	document.getElementById(id).style.display = "block";
	}
	
	// UNDERLINE LINK
	
function underlineLink(id1,id2){
	document.getElementById(id1).style.textDecoration='underline';
	document.getElementById(id2).style.textDecoration='none';
	}
	
	// TOGGLE STUFF
	
function togglestuff(id,stuff){
		
	if(document.getElementById(id).checked==true)
  			{
    		showstuff(stuff);
  			}  else {
			hidestuff(stuff);	
			}		
	}    

	// LIMIT TEXT IN FIELDS

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
		}
	} 
	
	// ++++++++++++++++++++++ CLEAR TEXT WHEN CLICKING IN MESSAGE FIELD
	
	function clearText(field) {
		document.getElementById(field).value = '';
	}
	
	// ++++++++++++++++++++++ AGREE TO AGB AND 18+
	
		function checkSubmit(){	
		
		document.getElementById('add_customer2').disabled=true;
		
  			if(document.getElementById('ok1').checked==true && document.getElementById('ok2').checked==true)
  				{
    			document.getElementById('add_customer2').disabled=false;
  				}  
			}
			
			// ++++++++++++++++++++++ AGREE TO 18+
	
		function checkSubmit2(){	
		
		document.getElementById('do_customer').disabled=true;
		
  			if(document.getElementById('ok1').checked==true)
  				{
    			document.getElementById('do_customer').disabled=false;
  				}  
			}
	
	// VALIDATE LOGIN
	
	function validatelogin() {
	
var theMessage = "";
var noErrors = theMessage

		if(!/\S/.test(document.getElementById('logmail').value)){
theMessage = theMessage + "Please enter your email address<br/>";
		}
		
		if(!/\S/.test(document.getElementById('logpass').value)){
theMessage = theMessage + "Please enter your password<br/>";
		}
		
		if (theMessage == noErrors) {
			doLogin = new ajaxObject('inc/actions.php', processResponse, 'login'); // create request with url
			doLogin.update(document.getElementById('loginform'),'POST'); // start request with object (the form) and type (POST), can be left empty for GET unless there are variables after ?
			processWait(doLogin,'login','<br /><img src=\"gfx/wait_s.gif\"><br /><br /><strong>please wait while you are being logged in</strong>'); // show and check while waiting for the form to be processed
	return true;

} else {
	
	showErrorBar('logError',theMessage);	
	
return false;
}
	}
	
	// VALIDATE LOGIN2
	
	function validatelogin2() {
	
var theMessage = "";
var noErrors = theMessage

		if(!/\S/.test(document.getElementById('logmail2').value)){
theMessage = theMessage + "Please enter your email address<br/>";
		}
		
		if(!/\S/.test(document.getElementById('logpass2').value)){
theMessage = theMessage + "Please enter your password<br/>";
		}
		
		if (theMessage == noErrors) {
			doLogin = new ajaxObject('inc/actions.php', processResponse, 'login2'); // create request with url
			doLogin.update(document.getElementById('loginform2'),'POST'); // start request with object (the form) and type (POST), can be left empty for GET unless there are variables after ?
			processWait(doLogin,'login2','<br /><img src=\"gfx/wait_s.gif\"><br /><br /><strong>please wait while you are being logged in</strong>'); // show and check while waiting for the form to be processed
	return true;

} else {
	
	showErrorBar('logError2',theMessage);	
	
return false;
}
	}
	
	// RESEND PASSWORD
	
	function resendpassform() {
	
			doResendForm = new ajaxObject('inc/actions.php', processResponse, 'memlog'); // create request with url
			doResendForm.update('action=resendPass','GET');
			processWait(doResendForm,'memlog','<br /><img src=\"gfx/wait_s.gif\">');

	}
	
	// SHOW LOGIN FORM
	
	function loginform() {
	
			doLoginForm = new ajaxObject('inc/actions.php', processResponse, 'memlog'); // create request with url
			doLoginForm.update('action=loginForm','GET');
			processWait(doLoginForm,'memlog','<br /><img src=\"gfx/wait_s.gif\">');

	}
	
	// VALIDATE RESEND PASSWORD
	
	function validateResendPass() {
	
var theMessage = "";
var noErrors = theMessage

		if(!/\S/.test(document.getElementById('logmail').value)){
theMessage = theMessage + "Please enter your email address<br/>";
		}
		
		if (theMessage == noErrors) {
			doLogin = new ajaxObject('inc/actions.php', processResponse, 'login'); // create request with url
			doLogin.update(document.getElementById('resendPassForm'),'POST'); // start request with object (the form) and type (POST), can be left empty for GET unless there are variables after ?
			processWait(doLogin,'login','<br /><img src=\"gfx/wait_s.gif\"><br /><br /><strong>please wait while we resend your password</strong>'); // show and check while waiting for the form to be processed
	return true;

} else {
	
	showErrorBar('logError',theMessage);	
	
return false;
}
	}
	

