
//PAGEMANAGER JAVASCRIPT FUNKTIONS

///////////////////////////////////////////////////////////////////////////////////////////////////////

//validateImage

function validateImage(element)
	{
	var extensions = new Array("jpg","jpeg","gif","png","bmp");
	
	var image_file = $(element).value;
	
	var image_length = $(element).value.length;
	
	var pos = image_file.lastIndexOf('.') + 1;
	
	var ext = image_file.substring(pos, image_length);
	
	var final_ext = ext.toLowerCase();
	
	for (k = 0; k < extensions.length; k++)
	{
	    if(extensions[k] == final_ext)
	    {
	    return true;
	    }
	}
	
	return false;
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////

//validateImage

function validateMP3(element)
	{
	var extensions = new Array("mp3");
	
	var image_file = $(element).value;
	
	var image_length = $(element).value.length;
	
	var pos = image_file.lastIndexOf('.') + 1;
	
	var ext = image_file.substring(pos, image_length);
	
	var final_ext = ext.toLowerCase();
	
	for (m = 0; m < extensions.length; m++)
	{
	    if(extensions[m] == final_ext)
	    {
	    return true;
	    }
	}
	
	return false;
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////

// INFO Button

function showMouseOver(text, event, div)
    {
   
        $(div).innerHTML = text;
        
        var topPixel  = mouseY(event) + 10;
        var leftPixel = mouseX(event) + 10;

        $(div).style.top = topPixel + "px";
        $(div).style.left = leftPixel + "px";
        $(div).style.display = "block";
    
    }
///////////////////////////////////////////////////////////////////////////////////////////////////////

    function sortMedia(sort,element) {

        if(sort == 'down'){
            next = element+1;
        } else { 
            next = element-1;
        }

           tmp1 = $('mediaOrdnerSettings').getElementsByTagName('span')[element].innerHTML;
           tmp2 = $('mediaOrdnerSettings').getElementsByTagName('span')[next].innerHTML;

           $('mediaOrdnerSettings').getElementsByTagName('span')[element].innerHTML = tmp2;
           $('mediaOrdnerSettings').getElementsByTagName('span')[next].innerHTML    = tmp1;
           tmp3 = $($('mediaOrdnerSettings').getElementsByTagName('span')[element].innerHTML).value;
           tmp4 = $($('mediaOrdnerSettings').getElementsByTagName('span')[next].innerHTML).value;
           $($('mediaOrdnerSettings').getElementsByTagName('span')[element].innerHTML).value = tmp4;
           $($('mediaOrdnerSettings').getElementsByTagName('span')[next].innerHTML).value = tmp3;
           $('spinner').style.display='block';
           $( 'sort' ).submit();
        }
///////////////////////////////////////////////////////////////////////////////////////////////////////

    function showupload(elem, elemDisplay) {

        if(elem != 0){
        	    $(elemDisplay).style.display      = 'none';

                $(elemDisplay+'_2').style.display = 'block';
                $(elemDisplay+'_3').style.display = 'block';
                $(elemDisplay+'_4').style.display = 'block';
      		    $('teaser_'+elemDisplay+'_1').style.backgroundColor='#2a4171';
    	    	$('teaser_'+elemDisplay+'_1').style.color='#ffffff';
    		    $('teaser_'+elemDisplay+'_0').style.backgroundColor='#e6e6e6';
    		    $('teaser_'+elemDisplay+'_0').style.color='#000000';
                
                
            } else { 
            	$(elemDisplay).style.display      = 'block';

                $(elemDisplay+'_2').style.display = 'none';
                $(elemDisplay+'_3').style.display = 'none';
                $(elemDisplay+'_4').style.display = 'none';
      		    $('teaser_'+elemDisplay+'_0').style.backgroundColor='#2a4171';
    	    	$('teaser_'+elemDisplay+'_0').style.color='#ffffff';
    		    $('teaser_'+elemDisplay+'_1').style.backgroundColor='#e6e6e6';
    		    $('teaser_'+elemDisplay+'_1').style.color='#000000';
                
                
            }
        }
    
///////////////////////////////////////////////////////////////////////////////////////////////////////

 // INFO Button
    function hideMouseOver(div)
    {
    	if (isNaN($(div))){
        $(div).innerHTML = "";

        $(div).style.top = "0px";
        $(div).style.left = "0px";    
        $(div).style.display = "none";
    	}
    }
    
///////////////////////////////////////////////////////////////////////////////////////////////////////

 // INFO Button
    function mouseX(evt) {
    	if (evt.pageX) return evt.pageX;
    	else if (evt.clientX)
    	   return evt.clientX + (document.documentElement.scrollLeft ?
    	   document.documentElement.scrollLeft :
    	   document.body.scrollLeft);
    	else return null;
    	}
    	function mouseY(evt) {
    	if (evt.pageY) return evt.pageY;
    	else if (evt.clientY)
    	   return evt.clientY + (document.documentElement.scrollTop ?
    	   document.documentElement.scrollTop :
    	   document.body.scrollTop);
    	else return null;
    	}
    
///////////////////////////////////////////////////////////////////////////////////////////////////////

function Logout(url) {

	//FB.Facebook.apiClient.revokeAuthorization(FB.Connect.get_loggedInUser(),function(){alert("Disconnected!!");});
	FB.Connect.logoutAndRedirect('index.php?' + url + '&log=out');
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function callbackPublish(pid, mid) {

	resObjekt.open('get',
			'index.php?action=publish&pid=' + pid + '&mid=' + mid, true);
	resObjekt.send(null);

}
///////////////////////////////////////////////////////////////////////////////////////////////////////

function onNotConnected() {

    $("loginButton2").style.display = 'none';
    $("loginButton2").style.display = 'none';
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function update_user_box() { 
    var user_box = $("user"); 
    // add in some XFBML. note that we set useyou=false so it doesn't display
	// "you"
    user_box.innerHTML = "<span>" + "<fb:profile-pic uid=loggedinuser facebook-logo=true></fb:profile-pic>" + "Welcome, <fb:name uid=loggedinuser useyou=false></fb:name>. You are signed in with your Facebook account." + "</span>"; // because
																																																										// this
																																																								// the
																																																										// document
    FB.XFBML.Host.parseDomTree(); 
} 

///////////////////////////////////////////////////////////////////////////////////////////////////////

function connect() {

	FB.ensureInit( function() {
		FB.Connect.get_status().waitUntilReady( function(status) {
			switch (status) {
			case FB.ConnectState.connected:
				loggedIn = true;
				break;
			case FB.ConnectState.appNotAuthorized:
			case FB.ConnectState.userNotLoggedIn:
				FB.Connect.requireSession();
				loggedIn = false;
			}
		});
	});
	return loggedIn;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function Tabelle(c,count){ 

	k = $('urlcount'+count).value;
	if(k < 2){
	f=c.parentNode; 

	i1_text=document.createElement('input');  
	i1_text.name=i1_text.id='url'+count+'_'+k++;  
	f.appendChild(i1_text); 
	     
	$('urlcount'+count).value = k;
	}
} 

///////////////////////////////////////////////////////////////////////////////////////////////////////

function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function publishImgFormProdList( pid, title, img, mid, link, msg) {

	loggedIn = connect();
	
	if (!loggedIn)
		return;

	if (shopFBJS['page_id'] == '' || isNaN(shopFBJS['page_id'])) {

		alert('No page found!');

		return;
	}

	var attachment = {
		'name' : title,
		'href' : shopFBJS['app_url'] + '?al=1&pid=' + pid,
		'description' : msg,
		'media' : [ {
			'type' : 'image',
			'src' : 'http://images.xi-hit.com/' + img + '_prods_r_188_188',
			'href' : shopFBJS['app_url'] + '?al=1&pid=' + pid
		} ]
	};
	var actionLinks = [ {
		"text" : link,
		"href" : shopFBJS['app_url'] + '?al=1&pid=' + pid
	} ];

	FB.Facebook.apiClient
			.pages_isAdmin(
					shopFBJS['page_id'],
					function(result) {
						// permission
						if (result == false) {

							alert('You have no permissions to publish to this page! (change your Facebook Account!)');
						} else {
							// permission already
							// granted.
							FB.Connect.streamPublish('', attachment,
									actionLinks, null, title, callbackPublish(
											pid, mid), null,shopFBJS['page_id']);
						}
					});

}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function publishGallery( pid, title, img, mid, link, msg) {

	if (shopFBJS['page_id'] == '' || isNaN(shopFBJS['page_id'])) {

		alert('No page found!');

		return;
	}

	var images = new Array();
	var j = 0;

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

		if (img[i].checked) {
			images[j] = new Object();
			images[j]["type"] = "image";
			images[j]["src"] = 'http://images.xi-hit.com/' + img[i].value + '_prods_r_188_188';
			images[j]["href"] = shopFBJS['app_url'] + '?al=1&pid=' + pid;
			j++;
		}
	}

	FB.ensureInit( function() {
		FB.Connect.get_status().waitUntilReady( function(status) {
			switch (status) {
			case FB.ConnectState.connected:
				loggedIn = true;
				break;
			case FB.ConnectState.appNotAuthorized:
			case FB.ConnectState.userNotLoggedIn:
				FB.Connect.requireSession();
				loggedIn = false;
			}
		});
	});

	var attachment = {
		'name' : title,
		'href' : shopFBJS['app_url'] + '?al=1&pid=' + pid,
		'description' : msg,
		'media' : images
	};

	var actionLinks = [ {
		"text" : link,
		"href" : shopFBJS['app_url'] + '?al=1&pid=' + pid
	} ];

	FB.Facebook.apiClient
			.pages_isAdmin(
					shopFBJS['page_id'],
					function(result) {
						// permission
						if (result == false) {

							alert('You have no permissions to publish to this page! (change your Facebook Account!)');
						} else {
							// permission already
							// granted.
							FB.Connect.streamPublish('', attachment,
									actionLinks, null, title, false, false,shopFBJS['page_id']);
						}
					});
}
///////////////////////////////////////////////////////////////////////////////////////////////////////

function publishVideoFormProdList(pid, title, img, code, mid, link, msg) {

	if (shopFBJS['page_id'] == '' || isNaN(shopFBJS['page_id'])) {
		alert('No page found!');
		return;
	}

	
	FB.ensureInit( function() {
		FB.Connect.get_status().waitUntilReady( function(status) {
			switch (status) {
			case FB.ConnectState.connected:
				loggedIn = true;
				break;
			case FB.ConnectState.appNotAuthorized:
			case FB.ConnectState.userNotLoggedIn:
				FB.Connect.requireSession();
				loggedIn = false;
			}
		});
	});
	var attachment = {
		'name' : title,
		'href' : shopFBJS['app_url'] + '?al=1&pid=' + pid,
		'description' : msg,
		'media' : [ {
			'type' : 'video',
			'video_src' : code,
			'preview_img' : img,
			'video_link' : shopFBJS['app_url'] + '?al=1&pid=' + pid

		} ]
	}
	var actionLinks = [ {
		"text" : link,
		"href" : shopFBJS['app_url'] + '?al=1&pid=' + pid
	} ];

	FB.Facebook.apiClient
			.pages_isAdmin(
					shopFBJS['page_id'],
					function(result) {
						// permission
						if (result == false) {

							alert('You have no permissions to publish to this page! (change your Facebook Account!)');
						} else {
							// permission already
							// granted.
							FB.Connect.streamPublish('', attachment,
									actionLinks, null, title, callbackPublish(
											pid, mid), true, shopFBJS['page_id']);
						}
					});

}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function publishMp3(pid, p_title, title, mp3, mid, link, msg) {

	if (shopFBJS['page_id'] == '' || isNaN(shopFBJS['page_id'])) {
		alert('No page found!');
		return;
	}

	FB.ensureInit( function() {
		FB.Connect.get_status().waitUntilReady( function(status) {
			switch (status) {
			case FB.ConnectState.connected:
				loggedIn = true;
				break;
			case FB.ConnectState.appNotAuthorized:
			case FB.ConnectState.userNotLoggedIn:
				FB.Connect.requireSession();
				loggedIn = false;
			}
		});
	});

	var attachment = {
		'name' : title,
		'href' : shopFBJS['app_url'] + '?al=1&pid=' + pid,
		'description' : msg,
		'media' : [ {
			'type' : 'mp3',
			'src' : mp3,
			'title' : title
		} ]
	}
	var actionLinks = [ {
		"text" : link,
		"href" : shopFBJS['app_url'] + '?al=1&pid=' + pid
	} ];

	FB.Facebook.apiClient
			.pages_isAdmin(
					shopFBJS['page_id'],
					function(result) {
						// permission
						if (result == false) {

							alert('You have no permissions to publish to this page! (change your Facebook Account!)');
						} else {
							// permission already granted.
							FB.Connect.streamPublish('', attachment,
									actionLinks, null, p_title,
									callbackPublish(pid, mid), null,shopFBJS['page_id']);
						}
					});
}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function displayView(para) {
	if ($(para).style.display == 'none') {
		$(para).style.display = 'block';
	} else {
		$(para).style.display = 'none';
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function displaySwitch(para1, para2) {

	if ($(para1).style.display == 'none') {
		$(para1).style.display = 'block';
		$(para2).style.display = 'none';
	} else {
		$(para1).style.display = 'none';
		$(para2).style.display = 'block';
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function displaySwitchDate(para1, para2) {

	if ($(para1).style.display == 'none') {
		$(para1).style.display = 'block';
		$(para2).style.display = 'none';
		  $('AGEGROUPBG').style.backgroundColor='#2a4171';
		  $('AGEGROUPBG').style.backgroundColor='#A1ACA1';

		  
	} else {
		$(para1).style.display = 'none';
		$(para2).style.display = 'block';
		  $('NILSONBG').style.backgroundColor='#2a4171';
		  $('AGEGROUPBG').style.backgroundColor='#A1ACA1';

	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////


function count(para) {
	var num = parseInt(document.getElementsByName('count')[0].value);
	if (para == 1) {
		num++;
	} else {
		num--;
	}
	document.getElementsByName('count')[0].value = num;
	document.form.submit();

}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function getURLParam(strParamName) {
	var strReturn = "";
	var strHref = window.location.href;

	if (strHref.indexOf("?") > -1) {
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++) {
			if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1) {
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return unescape(strReturn);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function setSearchTo(stype) {
	// changing the searchtype

	// if ( stype == 'customer') {
	// $( 'sbyCuston' ).style.display = 'none';
	// $( 'sbyCustoff' ).style.display = 'inline';
	// $( 'sbyprooff' ).style.display = 'inline';
	// $( 'sbyproon' ).style.display = 'none';
	// $( 'sbyshopon' ).style.display = 'inline';
	// $( 'sbyrtitoff' ).style.display = 'none';
	// $( 'thestype' ).value = 'customer';
	//
	// } else
	if (stype == 'shop') {
		//        $( 'sbyCuston' ).style.display = 'inline';
		// $( 'sbyCustoff' ).style.display = 'none';
		$('sbyprooff').style.display = 'inline';
		$('sbyproon').style.display = 'none';
		$('sbyshopon').style.display = 'none';
		$('sbyrtitoff').style.display = 'inline';
		$('thestype').value = 'shop';

	} else if (stype == 'product') {
		//        $( 'sbyCuston' ).style.display = 'inline';
		// $( 'sbyCustoff' ).style.display = 'none';
		$('sbyprooff').style.display = 'none';
		$('sbyproon').style.display = 'inline';
		$('sbyshopon').style.display = 'inline';
		$('sbyrtitoff').style.display = 'none';
		$('thestype').value = 'shop';
		$('thestype').value = 'product';
	}

}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function textfieldDisplay(objCheckbox, objTextfeld, objTextfeld2) {

	objTextfeld.disabled = (objCheckbox.checked) ? false : true;
	objTextfeld2.disabled = (objCheckbox.checked) ? false : true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function delMedia(mId, request, id) {
	
	if (isNaN($('item'+mId))){
		if($('item'+mId).value != '') {
			alert("This media is an overview image! Select an other image and save, than you can delete.");
			return false;	
			}
		}
	
	question = window.confirm("Are you sure you want to delete?");
	if (question) {
		document.location.href = "index.php?action=media&nav=del&mid=" + mId
				+ "&" + request + "=" + id + '&goto='
				+ $('nav').value;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function deleteQuestion(request) {
	question = window.confirm("Are you sure you want to delete?");
	if (question) {
		document.location.href = request;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
function mvshopMedia(mid, dir, dis) {
	
	if(dis != 'disabled'){
		$('mvmid').value = mid;
		
		if (dir == 'up') {
			$('mvshoppic' ).value = 1;		
		} else if (dir == 'down') {
			$('mvshoppic').value = 2;
	
		}
	}
	$('nav').value = $('nav').value + '_sort';
	$('daregdataform').submit();

}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function delProds(id) {
	question = window.confirm("Are you sure you want to delete?");

	if (question) {
		document.location.href = "index.php?action=pro&nav=del&pid=" + id;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function delAdmin(id)
{
    question=window.confirm("Are you sure you want to delete?");
    if(question) {
        document.location.href="index.php?action=admadmins&admaction=k&id="+id;
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function del(goto,id)
{
    question=window.confirm("Are you sure you want to delete?");
    
    if(question)
    {
        document.location.href="index.php?action="+goto+"&nav=del&id="+id;
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function checkApp() {

    var error = false;
      for (i=0; i < mandAppFields.length; i++) {
   
        if (document.getElementsByName(mandAppFields[i])[0].value == '' ) {
          error = true;
          }
      }     
    if (error) {
      alert('There was some errors in your form. Please check you have filled in all of the required data.');
      return false;
    }
    else {

      return true;
    }
  }

///////////////////////////////////////////////////////////////////////////////////////////////////////


function changeNo ( dir ) {

    $('store').style.display = 'block';

    if ( dir == 'tl' ) {
      
      $('tl').style.display = 'block';
      $('bt').style.display = 'none';
      $('tx').style.display = 'none';

    } else if ( dir == 'bt' ) {
      $('bt').style.display = 'block';
      $('tl').style.display = 'none';
      $('tx').style.display = 'none';

    } else if ( dir == 'tx' ) {
      $('tx').style.display = 'block';
      $('bt').style.display = 'none';
      $('tl').style.display = 'none';
    } else {
      $('tx').style.display = 'none';
      $('bt').style.display = 'none';
      $('tl').style.display = 'none';
      $('store').style.display = 'none';
    }
    
  }

///////////////////////////////////////////////////////////////////////////////////////////////////////


function mvshopProds(pid, count, dir) {

	$('mvpid').value = pid;
	
	if (dir == 'up') {

		$('mvshoppic' ).value = 1;

	} else if (dir == 'down') {

		$('mvshoppic' ).value = 2;
	} else if (dir == 'level') {

		$('mvshoppic').value = 3;
	}
	$('nav').value = 'sort';
	$('daregdataform').submit();
}


///////////////////////////////////////////////////////////////////////////////////////////////////////


function checkFormProds() {
	error = false;

	end = $('ps_end').value;
	start = $('ps_start').value;

	
	if($('p_name').value == '' ){
		   error = true;
		   $('p_name').style.border='1px solid #E61818';
	}
	   
	if($('shoppic0').value != ''  ){
		   if(!validateImage('shoppic0')){
		   error = true;
		   $('shoppic0').style.border='1px solid #E61818';
		   alert("You must upload an image file with one of the following extensions: jpg, jpeg, gif, png, bmp.");
	}
	}
	// check dates
	if (start != '00.00.0000' && end != '00.00.0000'
			&& $("ps_timestamp").value == "1") {
		dateStart = start.split('.');
		endStart = end.split('.');
		sTime = new Date(dateStart[2], dateStart[1], dateStart[0]);
		eTime = new Date(endStart[2], endStart[1], endStart[0]);
			if (sTime.getTime() >= eTime.getTime()) {
				error = true;
				$('ps_start').style.border='1px solid #E61818';
				$('ps_end').style.border='1px solid #E61818';
			} else {
				error = false;
			}
	}
	if (error) {		
		//$('itemError').style.display = 'block';
		return false;
	} else {
		  $('spinner').style.display='block';
		  $('formular').submit();
		return true;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function checkFormMedia(form, typ) {
	error    = false;
	errorIMG = false;
	
	for (i = 0; i <= $('count').value; i++) {

		if($('title'+i).value == '') {	
			
			if(i == $('count').value && typ == '' && i != 0)
			   break;
			error = true;			
			$('title'+i).style.border='1px solid #E61818';
		}
	
		if (isNaN($('shoppic'+i))){

			if($('shoppic'+i).value != ''  ){
			
			   if(!validateImage('shoppic'+i)){
			   error    = true;
			   errorIMG    = true;
			   $('shoppic'+i).style.border='1px solid #E61818';			  
			   }
			}
		}
	}
	if (error) {
		
		if (errorIMG) {
		
		alert("You must upload an image file with one of the following extensions: jpg, jpeg, gif, png, bmp.");
			
		}
		
		return false;
	} else {
		  $('spinner').style.display='block'; 
		  $(form).submit();
		return true;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////


function checkFormTeaser(form) {
	error    = false;
	errorIMG = false;
	if($('fileTeaser_0_2').value != ''  ){
			   if(!validateImage('fileTeaser_0_2')){
				   error    = true;
				   errorIMG = true;
			   $('fileTeaser_0_2').style.border='1px solid #E61818';			  
			   }
			}
	if($('fileTeaser_1_2').value != ''  ){
		   if(!validateImage('fileTeaser_1_2')){
			   error    = true;
			   errorIMG = true;
		   $('fileTeaser_1_2').style.border='1px solid #E61818';			  
		   }
		}
	if (error) {
		
		if (errorIMG) {
		
		alert("You must upload an image file with one of the following extensions: jpg, jpeg, gif, png, bmp.");
			
		}
		
		return false;
	} else {
		  $('spinner').style.display='block'; 
		  $(form).submit();
		return true;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////


function checkFormMediaTitle(form, typ) {
	error    = false;

	
	for (i = 0; i <= $('count').value; i++) {

		if($('title'+i).value == '') {	
			
			if(i == $('count').value && typ == '' && i != 0)
			   break;
			error = true;			
			$('title'+i).style.border='1px solid #E61818';
		}

	}
	if (error) {
		
		return false;
	} else {
		  $('spinner').style.display='block'; 
		  $(form).submit();
		return true;
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////


function checkFormMediaMp3(form, typ) {
	error    = false;
	errorIMG = false;
	
	for (i = 0; i <= $('count').value; i++) {

		if($('title'+i).value == '') {	
			
			if(i == $('count').value && typ == '' && i != 0)
			   break;
			error = true;			
			$('title'+i).style.border='1px solid #E61818';
		}
	
		if (isNaN($('shoppic'+i))){

			if($('shoppic'+i).value != ''  ){
			
			   if(!validateMP3('shoppic'+i)){
			   error    = true;
			   errorIMG    = true;
			   $('shoppic'+i).style.border='1px solid #E61818';			  
			   }
			}
		}
	}
	if (error) {
		
		if (errorIMG) {
		
		alert("You must upload an mp3 file with the following extension: .mp3");
			
		}
		
		return false;
	} else {
		  $('spinner').style.display='block'; 
		  $(form).submit();
		return true;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function openSpace() {
	for (i = 0; i <= 9; i++) {
		if ($('table').getElementsByTagName('span')[i].innerHTML == ''
				|| $('table')
						.getElementsByTagName('span')[i].innerHTML == '00.00.0000') {
			$(i).style.display = 'none';
		}
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function checkFormProdsList(mandAppFields) {
	var error = false; 
	for (i = 0; i < mandAppFields.length; i++) {
	
		start = $('ps_start'+mandAppFields[i]).value;
		end   = $('ps_end'  +mandAppFields[i]).value;

		if (start != '00.00.0000' && end != '00.00.0000'
				&& $("ps_timestamp" + mandAppFields[i]).checked) {

			dateStart = start.split('.');
			endStart = end.split('.');
			sTime = new Date(dateStart[2], dateStart[1], dateStart[0]);
			eTime = new Date(endStart[2], endStart[1], endStart[0]);

			if (sTime.getTime() >= eTime.getTime()) {
				$('ps_start'+ mandAppFields[i]).style.border='1px solid #E61818';
				$('ps_end'+ mandAppFields[i]).style.border='1px solid #E61818';
				$('itemError').style.display = 'block';
				
				error = true;
			}
		}
	}
	if (error) {
		//alert('Please check your dates');
		return false;
	} else {
	  	  $('spinner').style.display='block';
		  $('daregdataform').submit();
		return true;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////


function displayMedia( val , pCount) {

	  if(val == 1){
		  $('display'+pCount).value = 1;
		  $('displayClassOn'+pCount).style.backgroundColor='#2a4171';
		  $('displayClassOn'+pCount).style.color='#ffffff';
		  $('displayClassOff'+pCount).style.backgroundColor='#e6e6e6';
		  $('displayClassOff'+pCount).style.color='#000000';
	 
	  } else {
		  $('display'+pCount).value = 0;
		  $('displayClassOff'+pCount).style.backgroundColor='#2a4171';
		  $('displayClassOff'+pCount).style.color='#ffffff';
		  $('displayClassOn'+pCount).style.backgroundColor='#e6e6e6';
		  $('displayClassOn'+pCount).style.color='#000000';
	  
	  }
	  }

///////////////////////////////////////////////////////////////////////////////////////////////////////


function displayProSet( val , typ , classOn, classOff) {  

	 if(!typ){
			$(val+'ClassOn').style.backgroundColor='#2a4171';
			$(val+'ClassOn').style.color='#ffffff';
			$(val+'ClassOff').style.backgroundColor='#e6e6e6';
			$(val+'ClassOff').style.color='#000000';

  		    $(val).value = 1;
  		    if (isNaN($(val+'Display')))
		    $(val+'Display').style.display = 'block';
	  } else {
			$(val+'ClassOff').style.backgroundColor='#2a4171';
			$(val+'ClassOff').style.color='#ffffff';
			$(val+'ClassOn').style.backgroundColor='#e6e6e6';
			$(val+'ClassOn').style.color='#000000';

		    $(val).value = 0;
		    if (isNaN($(val+'Display')))
		    $(val+'Display').style.display = 'none';
	  }
  }

///////////////////////////////////////////////////////////////////////////////////////////////////////


  function setProSet() {  
  
        var fields = ['ps_timestamp', 'teaser' , 'teaserTime', 'ps_show'];
        
        for (i=0; i < fields.length; i++) {

        if(fields[i] == 'teaserTime')
        {
        
                if ($(fields[i]).value == 1) {
        			$(fields[i]+'ClassOn').style.backgroundColor='#2a4171';
        			$(fields[i]+'ClassOn').style.color='#ffffff';
        			$(fields[i]+'ClassOff').style.backgroundColor='#e6e6e6';
        			$(fields[i]+'ClassOff').style.color='#000000';
        			if (isNaN($(fields[i]+'Display')))
                    $(fields[i]+'Display').style.display = 'block';
                  }else{
          			$(fields[i]+'ClassOff').style.backgroundColor='#2a4171';
        			$(fields[i]+'ClassOff').style.color='#ffffff';
        			$(fields[i]+'ClassOn').style.backgroundColor='#e6e6e6';
        			$(fields[i]+'ClassOn').style.color='#000000';
        			if (isNaN($(fields[i]+'Display')))
                    $(fields[i]+'Display').style.display = 'none';
                  }
        }
        else
        {
                if ($(fields[i]).value == 1) {
        			$(fields[i]+'ClassOn').style.backgroundColor='#2a4171';
        			$(fields[i]+'ClassOn').style.color='#ffffff';
        			$(fields[i]+'ClassOff').style.backgroundColor='#e6e6e6';
        			$(fields[i]+'ClassOff').style.color='#000000';
        			if (isNaN($(fields[i]+'Display')))
                    $(fields[i]+'Display').style.display = 'block';
                  }else{
          			$(fields[i]+'ClassOff').style.backgroundColor='#2a4171';
        			$(fields[i]+'ClassOff').style.color='#ffffff';
        			$(fields[i]+'ClassOn').style.backgroundColor='#e6e6e6';
        			$(fields[i]+'ClassOn').style.color='#000000';
        			if (isNaN($(fields[i]+'Display')))
                    $(fields[i]+'Display').style.display = 'none';
                  }
        }
        
       }     
  }
  
///////////////////////////////////////////////////////////////////////////////////////////////////////


  function erzXMLHttpRequestObject() {
  	var resObjekt = null;
  	try {
  		resObjekt = new ActiveXObject("Microsoft.XMLHTTP");
  	} catch (Error) {
  		try {
  			resObjekt = new ActiveXObject("MSXML2.XMLHTTP");
  		} catch (Error) {
  			try {
  				resObjekt = new XMLHttpRequest();
  			} catch (Error) {
  				alert("Erzeugung des XMLHttpRequest-Objekts ist nicht moeglich");
  			}
  		}
  	}
  	return resObjekt;
  }

  ///////////////////////////////////////////////////////////////////////////////////////////////////////


  function ErzeugeAJAXObjekt() {
  	this.erzXMLHttpRequestObject = erzXMLHttpRequestObject;
  }
  o = new ErzeugeAJAXObjekt();
  resObjekt = o.erzXMLHttpRequestObject();

  ///////////////////////////////////////////////////////////////////////////////////////////////////////


  function pager(page) {

  	if (page != "") {

  		resObjekt.open('get', page, true);
  		resObjekt.onreadystatechange = handleResponse;
  		resObjekt.send(null);
  	} else {
  		$("hs").style.visibility = "hidden";
  	}
  }

  ///////////////////////////////////////////////////////////////////////////////////////////////////////

function calendar(page) {

	if (page != "") {

		resObjekt.open('get', page, true);
		resObjekt.onreadystatechange = handleResponsecalendar;
		resObjekt.send(null);
	} else {
		$("calendar").style.visibility = "hidden";
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////

function handleResponsecalendar() {
	$("calendar").style.visibility = "visible";
	if (resObjekt.readyState == 4) {
		$("calendar").innerHTML = resObjekt.responseText;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////

function ajaxContent(page, div) {

	$('statItem').style.backgroundColor='#2a4171';
	$('statItem').style.color='#ffffff';
	$('statMain').style.backgroundColor='#e6e6e6';
	$('statMain').style.color='#000000';
	
	
	if (page != "") {
		resObjekt.open('get', page, true);
		resObjekt.onreadystatechange = handleResponseContent;
		resObjekt.send(null);
	} else {
		$(div).style.visibility = "hidden";
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////

function handleResponseContent(div) {
	$('stats').style.visibility = "visible";
	if (resObjekt.readyState == 4) {
		$('stats').innerHTML = resObjekt.responseText;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////


function handleResponse() {
	$("hs").style.visibility = "visible";
	if (resObjekt.readyState == 4) {
		$("hs").innerHTML = resObjekt.responseText;
	}
}
resObjekt = erzXMLHttpRequestObject();


