function explode( delimiter, string, limit ) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}
$JQ = jQuery.noConflict();

function clearText(objInputText, defaultText)
{
	if (defaultText == objInputText.value)
		objInputText.value = "";
}

function restoreText(objInputText, defaultText)
{
	if (objInputText.value == "")
		objInputText.value = defaultText;
}

function changeType(objInputText, newType)
{
	if (objInputText.value == "")
		objInputText.type = newType;
}

function isEnterKey(txt, ev)
{
	var e = window.event ? window.event : ev;
	var iKeyCode = e.keyCode ? e.keyCode: e.charCode;
	return (iKeyCode == 13);
}

/*
temporar nefolosita
function showGallery(id)
{
	$JQ('#productContent'+id).hide();	
	$JQ('#productPictures'+id).show();	
	$JQ('.sliderProduct').hide('slow');
	$JQ('#productTop'+id).slideDown('slow');
	setTimeout("$JQ('.flash').show()",700);
	$JQ('#productContainer_'+id).addClass('packshot_selected');
}
*/
function testCurtain(elementClass)
{
	//	elementHeight = $JQ("#"+elementClass).children(".sliderHeight").html();
	
	//closing previous opened elements;
	/*
	$JQ(".slider[id!="+elementClass+"]").css("height","115px");
	$JQ(".aTrigger[id!="+elementClass+"Trigger]").html("Read more").attr("opened","no");
	
	var atext = $JQ("#"+elementClass+"Trigger").attr("opened");
	//alert(atext);
	if (atext=="yes")
	{
		$JQ("#"+elementClass+"Trigger").html("Read more");
		$JQ("#"+elementClass+"Trigger").attr("opened","no");
		$JQ("#"+elementClass).animate({ height: 115}, "slow");
	}
	else
	{
		elementHeight = $JQ("#"+elementClass).attr("height1");
		//alert(elementHeight);
		$JQ(".curtainTrigger").html("Read more");
		$JQ("#"+elementClass+"Trigger").html("Close");
		$JQ("#"+elementClass+"Trigger").attr("opened","yes");
		$JQ("#"+elementClass).animate({ height: elementHeight}, "slow");
	}
	*/
	$JQ(".curtainTrigger[id!="+elementClass+"Trigger]").attr("opened","no").html("Read more");
	$JQ(".slider").animate({ height: 115}, "slow");
	
	var atext = $JQ("#"+elementClass+"Trigger").attr("opened");
	if (atext=="yes")
	{
		$JQ("#"+elementClass+"Trigger").html("Read more");
		$JQ("#"+elementClass+"Trigger").attr("opened","no");
		$JQ("#"+elementClass).animate({ height: 115}, "slow");
	}
	else
	{
		elementHeight = $JQ("#"+elementClass).attr("height1");
		$JQ("#"+elementClass+"Trigger").html("Close");
		$JQ("#"+elementClass+"Trigger").attr("opened","yes");
		$JQ("#"+elementClass).animate({ height: elementHeight}, "slow");
	}
}

$JQ(document).ready(function() {	
	//alert($JQ(".slider").height());
	//$JQ(".slider").attr("height1",$JQ(this).height());
	//alert($JQ(".slider").children(".sliderHeight").html())
	$JQ(".slider").css("height","115px").css("overflow","hidden");
	//alert($JQ("#class1Height").parent().height());
	//$JQ(".sliderProduct [id!='productTop2']").hide();
//	$JQ(".sliderProduct").css("display","none");

	//menu functions
	$JQ("#menuLevel1 .inactive span").hide();
	$JQ("#menuLevel1 .inactive a").hover(function() {
		$JQ(this).children("span").fadeIn(500);
	}
	, function() {	
		$JQ(this).children("span").hide();
	});
	
	//flag rollover functions
	$JQ('#languages li[class!="activeLanguage"]').hover(function() {			
		$JQ(this).animate({left: -7},100);
	}
	, function() {				
		$JQ(this).animate({left: 0},200);
	});
	
	$JQ('#cartTab').click( function() 
	{ 
		window.location=$JQ('#basketUrl').val();
	});
	$JQ("#comparisonTriggerOff").click( function() 
	{ 
		$JQ(this).hide();
		$JQ("#comparisonTriggerOn").show();
		$JQ("#comparedata").slideUp('slow');
	});
	$JQ("#comparisonTriggerOn").click( function() 
	{ 
		$JQ(this).hide();
		$JQ("#comparisonTriggerOff").show();
		$JQ("#comparedata").slideDown('slow');
	});
	
	$JQ(".thumbEnlarger").hover(function() {
		src = $JQ(this).attr("src"); 
		src = src.replace("/thumbs", "");
		//alert (src);
		$JQ(".thumbEnlarged").html('<img src="'+src+'">').fadeIn(500);
	}
	, function() {	
		$JQ(".thumbEnlarged").hide();
	});
	
	
	//calendar
	if ($JQ('#txtDay').val())
	{
		var day0=$JQ('#txtDay').val();
		//alert (day0);
		if(day0[0]=="0")
		{
			day0=day0[1];
		}
		$JQ("#day"+day0).addClass("igcv_CurrentDay");

		$JQ(".igcv_Day").click( 
			function() 
			{	
				//alert ();
				var day1 = $JQ(this).html();
				var newday;
				if(day1.length==1)
				{
					newday="0"+day1;
				}
				else
				{
					newday=day1;
				}
				$JQ(".igcv_Day").removeClass("igcv_CurrentDay");
				$JQ(this).addClass("igcv_CurrentDay");
				$JQ('#txtDay').val(newday);
				$JQ('#CurrentDate').val( $JQ('#txtYear').val()+"-"+$JQ('#txtMonth').val()+"-"+$JQ('#txtDay').val());
				//alert ($JQ('#CurrentDate').val());
			}
		);
	}
	
	//Overlay
	$JQ('div#overlayDiv').height( $JQ('body').height()+250).fadeTo("slow", 0.8);
	
	$JQ('div#overlayDiv').click(function () { 
		$JQ('div#overlayDiv').fadeOut("fast");
		$JQ('div#overlayDivContainer').fadeOut("fast");
	});

	//old packshot functionality
	/*$JQ(".packshot").click(function () { 
		var triggerImage = $JQ(this).attr("src"); 
		triggerImage = triggerImage.replace("/packsThumbs/", "/packs/");
		$JQ('#overlayDivContainer').html('<div><a href="javascript:closeDiv()" style="float:right" title="Close"><img src="/images/close.png"></a><img src="'+triggerImage+'" style="margin:10px;"><div>');
		$JQ('div#overlayDivContainer').css("margin-left", ($JQ('body').width() - 800)/2);
		$JQ('div#overlayDiv').fadeIn("fast");
		$JQ('div#overlayDivContainer').fadeIn("fast");
	});*/
	

});


function messageClicked(param)
{
	var alreadyErased = $JQ("#txtMessage").attr("alreadyErased");
	if (alreadyErased!="yes")
	{
		$JQ("#txtMessage").attr("alreadyErased","yes");
		$JQ("#txtMessage").val("");
	}
}

function deleteEntry(param)
{
	if (window.confirm("Are you sure?"))
	{
		raiseEvent('deleteEntry',param);				
	}
}


//integrated forum login
function forumLogin(){
	var ut, ps;
	ut = $JQ("#ut").val();
	ps = $JQ("#ps").val();
	$JQ.post("/forumLogin.php", {u: ut, p: ps },
	function(data){
		$JQ('#menu_login_center').html("Loading...").hide().html(data).show("slow");
		if ( $JQ('#logged_in').val()=="yes" && ( ($JQ('#path_0').val()=="you" && $JQ('#path_1').val()=="my_edge") || $JQ('#path_0').val()=="forum"))
			window.location.href="";
	});
}
function forumTryLogin(){
	$JQ.post("/forumLogin.php", {tryAgain:1 },
	function(data){
		$JQ('#menu_login_center').html("Loading...").hide().html(data).show("slow");
	});
}
function forumLogout(){
	$JQ.post("/forumLogout.php", function(data){
		$JQ('#menu_login_center').html("Loading...").hide().html(data).show("slow");
		if ( $JQ('#logged_out').val()=="yes" && ( ($JQ('#path_0').val()=="you" && $JQ('#path_1').val()=="my_edge") || $JQ('#path_0').val()=="forum"))
			window.location.href="";
	});
}


function newsletterSaveEmail()
{
	emailAddress = $JQ("#newsletterEmailAddress").val();
	$JQ.get("/newsletterJoin.php", { email: emailAddress },
	function(data){
		$JQ('#joinNewsletter').html("Loading...").hide().css("width","0px").html(data).animate({width:400},200);
	});
}
function newsletterTryAgain()
{
	$JQ.get("/newsletterJoin.php", { showForm: "true" },
	function(data){
		$JQ('#joinNewsletter').html("Loading...").hide().css("width","0px").html(data).animate({width:400},200);
	});
}

function openProductDetails(id, limit)
{
	$JQ('#titleDiv').hide();
	$JQ('.productYou').removeClass('productSelected');
	if($JQ('#productTop'+id).css('display')!='block')
	{
		$JQ('.sliderProduct').hide('slow');
		$JQ('#productTop'+id).slideDown('slow');
//		$JQ('#youProduct_'+id).addClass('productSelected');
//		$JQ('#youProduct_'+id).css('background-image', 'url(/images/edgesSelectedBackground.png)');
		setTimeout("$JQ('.flash').show()",700);
		
	}
}

function  closeDiv()
{
	$JQ('div#overlayDiv').fadeOut('fast');
	$JQ('div#overlayDivContainer').fadeOut('fast');
}

function hideCart()
{
	$JQ('#basket').animate({ top: 26, opacity: "hide"}, 100);
}
function showCart()
{
	$JQ('#basket').animate({ top: 0, opacity: "show"}, 300);
}
function addToCart(productId,Price)
{
	//$JQ('#popupConfirmation').show();
	var left = (($JQ('body').width())-240)/2;
 	left = parseInt(left)-11;
 	$JQ('#popupConfirmation').css('left', left+'px').css('cursor','pointer');
 	$JQ('#popupConfirmation').click(function(){
 		//console.log(this);
 		location.href = $JQ('#basketUrl').val();
 	});
 	$JQ('#popupConfirmation #popClose').mousedown(function(){
 		$JQ('#popupConfirmation').unbind('click');
 	});
	$JQ.get("scripts/ajaxCart.php", { product: productId, price: Price },
	function(data){
		if (data)
		{
			hideCart();
			$JQ('#basket-main span').html(data);
			showCart();
		}
		//alert("Data Loaded: " + data);
	}
 );
}
function closePopUp(){
	$JQ('#popupConfirmation').hide();
}

// JScript File
function trainingProgramValidation()
{

	var flag=true;
	
	if ($JQ("#date").val()=="")
	{
		if ($JQ("#date").val()=="")
		{
			$JQ('#txtDate').show();
		}
		else
		{
			$JQ('#txtDate').hide();
		}
		flag = false;
	}
	else
	{
		$JQ('#txtHoursEmpty').hide();
		$JQ('#txtHoursNonInt').hide();
	}
	
	
	if ($JQ("#txtHours").val()==""||!isUnsignedInteger($JQ("#txtHours").val()) )
	{
		if ($JQ("#txtHours").val()=="")
		{
			$JQ('#txtHoursEmpty').show();
			$JQ('#txtHoursNonInt').hide();
		}
		else
		{
			$JQ('#txtHoursNonInt').show();
			$JQ('#txtHoursEmpty').hide();
		}
		flag = false;
	}
	else
	{
		$JQ('#txtHoursEmpty').hide();
		$JQ('#txtHoursNonInt').hide();
	}
	
	//Lenght flacid validation	
	if ($JQ("#txtLengthFlaccid").val()==""||!isUnsignedFloat($JQ("#txtLengthFlaccid").val()) )
	{
		if ($JQ("#txtLengthFlaccid").val()=="")
		{
			$JQ('#txtLengthFlaccidEmpty').show();
			$JQ('#txtLengthFlaccidNonFloat').hide();
		}
		else
		{
			$JQ('#txtLengthFlaccidNonFloat').show();
			$JQ('#txtLengthFlaccidEmpty').hide();			
		}
		flag = false;
	}
	else
	{
		$JQ('#txtLengthFlaccidEmpty').hide();
		$JQ('#txtLengthFlaccidNonFloat').hide();
	}
	
	//Girth flacid validation	
	if ($JQ("#txtGirthFlaccid").val()==""||!isUnsignedFloat($JQ("#txtGirthFlaccid").val()) )
	{
		if ($JQ("#txtGirthFlaccid").val()=="")
		{
			$JQ('#txtGirthFlaccidEmpty').show();
			$JQ('#txtGirthFlaccidNonFloat').hide();
		}
		else
		{
			$JQ('#txtGirthFlaccidNonFloat').show();
			$JQ('#txtGirthFlaccidEmpty').hide();			
		}
		flag = false;
	}
	else
	{
		$JQ('#txtGirthFlaccidEmpty').hide();
		$JQ('#txtGirthFlaccidNonFloat').hide();
	}
	
	//Lenght Erect validation	
	if ($JQ("#txtLengthErect").val()==""||!isUnsignedFloat($JQ("#txtLengthErect").val()) )
	{
		if ($JQ("#txtLengthErect").val()=="")
		{
			$JQ('#txtLengthErectEmpty').show();
			$JQ('#txtLengthErectNonFloat').hide();
		}
		else
		{
			$JQ('#txtLengthErectNonFloat').show();
			$JQ('#txtLengthErectEmpty').hide();			
		}
		flag = false;
	}
	else
	{
		$JQ('#txtLengthErectEmpty').hide();
		$JQ('#txtLengthErectNonFloat').hide();
	}

	//Girth Erect validation	
	if ($JQ("#txtGirthErect").val()==""||!isUnsignedFloat($JQ("#txtGirthErect").val()) )
	{
		if ($JQ("#txtGirthErect").val()=="")
		{
			$JQ('#txtGirthErectEmpty').show();
			$JQ('#txtGirthErectNonFloat').hide();
		}
		else
		{
			$JQ('#txtGirthErectNonFloat').show();
			$JQ('#txtGirthErectEmpty').hide();			
		}
		flag = false;
	}
	else
	{
		$JQ('#txtGirthErectEmpty').hide();
		$JQ('#txtGirthErectNonFloat').hide();
	}
	
	if (flag) {
		document.forms["addNewEntry"].submit();
	}
		
		///;
	
}

function partnerPlaceOrder()
{
	document.partner_shop_form.submit();
}
function partnerLogin()
{
	document.contactForm.submit();
}
function partnerLogout()
{
	document.contactForm.submit();
}

function isUnsignedInteger(s) {
	return (s.toString().search(/^[0-9]+$/) == 0);
}
function isUnsignedFloat(s) {
	//alert(s==parseFloat(s));
	//return (s==parseFloat(s));
	return (s.toString().search(/^[0-9.]+$/) == 0);
}


function editProfile()
{
	var flag=false;
	var reAlpha = /^[a-zA-Z0-9]+$/;
	//first name
	if ($JQ("#b_first_name").val()=="")
	{
		$JQ('#b_first_nameEmpty').show();
		flag = true;
	}
	else
	{
		$JQ('#b_first_nameEmpty').hide();
		if(!reAlpha.test($JQ("#b_first_name").val()))
		{
			$JQ('#b_first_nameNotAlpha').show();
			flag = true;
		}
		else
			$JQ('#b_first_nameNotAlpha').hide();
	}
	
	//last name
	if ($JQ("#b_last_name").val()=="")
	{
		$JQ('#b_last_nameEmpty').show();
		flag = true;
	}
	else
	{
		$JQ('#b_last_nameEmpty').hide();
		if(!reAlpha.test($JQ("#b_last_name").val()))
		{
			$JQ('#b_last_nameNotAlpha').show();
			flag = true;
		}
		else
			$JQ('#b_last_nameNotAlpha').hide();
	}
	
	//address
	if ($JQ("#txt_user_address").val()=="")
	{
		$JQ('#txt_user_addressEmpty').show();
		flag = true;
	}
	else
	{
		$JQ('#txt_user_addressEmpty').hide();
	}
	
	//country
	if ($JQ("#b_country").val()=="" || $JQ("#b_country").val()=="SELECT")
	{
		$JQ('#b_countryEmpty').show();
		flag = true;
	}
	else
	{
		$JQ('#b_countryEmpty').hide();
	}
	
	if (flag)
		return false;
	else
		document.contactForm.submit();
}

function addProfile()
{
	var flag=false;
	var reAlpha = /^[a-zA-Z0-9]+$/;
	var reAlphaSpace = /^[a-zA-Z0-9 ]+$/;
	//name
	if ($JQ("#txt_user_full_name").val()=="")
	{
	
	}
	else
	{
		$JQ('#txt_user_full_nameEmpty').hide();
		if(!reAlphaSpace.test($JQ("#txt_user_full_name").val()))
		{
			$JQ('#txt_user_full_nameNotAlpha').show();
			flag = true;
		}
		else
			$JQ('#txt_user_full_nameNotAlpha').hide();
	}
	
	//username
	if ($JQ("#txt_username").val()=="")
	{
		$JQ('#txt_usernameEmpty').show();
		flag = true;
	}
	else
	{
		$JQ('#txt_usernameEmpty').hide();
		if(!reAlpha.test($JQ("#txt_username").val()))
		{
			$JQ('#txt_usernameNotAlpha').show();
			flag = true;
		}
		else
			$JQ('#txt_usernameNotAlpha').hide();
	}
	
	//email
	//var re = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$/i;
	var re = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	var emailValue=$JQ("#txt_user_email").val();
//	alert(re.test(emailValue));
	if (!re.test(emailValue))
	{
		$JQ('#txt_user_emailEmpty').show();
		flag = true;
//		alert('email error flag : '+ flag);
	}
	else
	{
		$JQ('#txt_user_emailEmpty').hide();
	}
	
	//password
	if ($JQ("#txt_password").val()=="")
	{
		$JQ('#txt_passwordEmpty').show();
		flag = true;
	}
	else
	{
		$JQ('#txt_passwordEmpty').hide();
		if(!reAlpha.test($JQ("#txt_password").val()))
		{
			$JQ('#txt_passwordNotAlpha').show();
			flag = true;
		}
		else
			$JQ('#txt_passwordNotAlpha').hide();
	}
	
	//password2
	if ($JQ("#txt_password2").val()=="")
	{
		$JQ('#txt_password2Empty').show();
		flag = true;
	}
	else
	{
		$JQ('#txt_password2Empty').hide();
	}
	
	//password2 match
	if ($JQ("#txt_password2").val()!=$JQ("#txt_password").val())
	{
		$JQ('#txt_password2Match').show();
		flag = true;
	}
	else
	{
		$JQ('#txt_password2Match').hide();
	}
	
	/*
	//address
	if ($JQ("#txt_user_address").val()=="")
	{
		$JQ('#txt_user_addressEmpty').show();
		flag = true;
	}
	else
	{
		$JQ('#txt_user_addressEmpty').hide();
	}
	*/
	
	//country
	if ($JQ("#txt_user_country").val()=="")
	{
		$JQ('#txt_user_countryEmpty').show();
		flag = true;
	}
	else
	{
		$JQ('#txt_user_countryEmpty').hide();
	}
	
//	alert('flag='+flag);
	
	if (flag)
		return false;
	else
		document.contactForm.submit();
}

//contact form ajax
function loadContactForm(id,sub){
	$JQ(".ContactPlaceholder").html("").hide("slow");
	$JQ('#ContactPlaceholder_'+id).html("Loading...");
	$JQ.post($JQ("#webpath").val()+"/include/contactform.php", {id: id,subject: sub },
	function(data){
		$JQ('#ContactPlaceholder_'+id).hide().html(data).show("slow");
	});
}
function showtxtPass()
{
	if($JQ('[name=psDes]').val()=='Password')
	{
		$JQ('[name=psDes]').css('display','none');
		$JQ('[name=ps]').css('display','inline');
		$JQ('[name=ps]').focus();
	
	}
}
function fillFieldPass()
{
	if($JQ('[name=ps]').val()=='')
	{
		$JQ('[name=psDes]').css('display','inline');
		$JQ('[name=ps]').css('display','none');
	}
}
function emptyField(name)
{
	if($JQ('[name='+name+']').val()=='Username')
	{
		$JQ('[name='+name+']').val('');
		$JQ('[name=ut]').css('color','#FFFFFF');
	}
}
function fillField()
{
	if($JQ('[name=ut]').val()=='')
	{
		$JQ('[name=ut]').val('Username');
		$JQ('[name=ut]').css('color','#8E8E8E');
	}
}
