// Javascript functions



//---Hide slider function---//
/*
* @creator: @admin
* @description: hide window
* @note: NULL
*/

function hide_panel(){
	$('.hider').css({position:'relative'}).animate({
																				left: '-700px'
																			},1000,function(){
																				//complete
																				$('.show_panel').fadeIn();
																			});
}


//---Show slider function---//
/*
* @creator: @admin
* @description: hide window
* @note: NULL
*/

function show_panel(){
	$('.show_panel').fadeOut();
	$('.hider').animate({
							left: '0px'
						},1000,function(){
							//complete
						});
}

//---Peloader function---//
/*
* @creator: @admin
* @description: Show preloader
* @note: NULL
*/

var img = "";

function show_preloader(loading,subject,text){
	//create image
	if(loading){
		img = 'images/preloader.gif';
	}else{
		img = 'images/preloader-disabled.gif';
	}
	
	//constucting layout
	$('.loading-img').html('<img src="'+img+'" title="loading" class="site-preloader" />');
	$('.loading-subject').html(subject);
	$('.loading-text').html(text);
	
	$('.site-preloader').ready(function(){
		$top = $('#preloader_container').css('top');
			$('#preloader_container').show().animate({
																							opacity: 0.8,
																							top: 0
																						},'slow',function(){
																							//animation complete
																					});
	});
	
}

function hide_preloader(){
	$('#preloader_container').delay(500).animate({
																					opacity: 0,
																					top: '-100px'
																				},'slow');
}


//---Explode function---//
/*
* @creator: @admin
* @description: explode string 
* @note: NULL
*/


function explode( delimiter, string, limit ) {
    // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.  
    // 
    // version: 810.114
    // discuss at: http://phpjs.org/functions/explode
    // +     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;
    }
}



//---Explode function---//
/*
* @creator: @admin
* @description: explode string 
* @note: NULL
*/

function change_bg(img){
	var imageId  = Math.random().toString().replace(/./g, "" );
	// alert( img );
	var newImage  = "<img src='" + img + "' id='" + imageId + "' style='position:absolute; left:-1000px;display:none' width='1px' height='1px' />";
	$(newImage).appendTo( "body" );
	old_img = $('#img-bg').attr('src');
	if(old_img != img){
	$('#img-bg').animate({
								opacity: 0
							},'fast',function(){
								//animation complete
								// $(this).hide().attr('src',img);
								$(this).hide().attr('src',img);
								$(this).load(function(){
															$(this).show().animate({
																							opacity: 1
																						});
														});
							});
	}
}



//---Hide slider function---//
/*
* @creator: @admin
* @description: hide window
* @note: NULL
*/

function show_sub(sub_cl){
	$('.'+sub_cl).slideDown();
}

//---Hide slider function---//
/*
* @creator: @admin
* @description: hide window
* @note: NULL
*/

function hide_sub(sub_cl){
	$('.'+sub_cl).slideUp();
}


//---Email validator function---//
/*
* @creator: @admin
* @description: NULL
* @note: NULL
*/


function emailverify(obj){
	var email = obj;
	var passed;
	var blnRetval, intAtSign, intDot, intComma, intSpace, intLastDot, intDomain, intStrLen;
	intAtSign=email.indexOf("@");
	intDot=email.indexOf(".",intAtSign);
	intComma=email.indexOf(",");
	intSpace=email.indexOf(" ");
	intLastDot=email.lastIndexOf(".");
	intDomain=intDot-intAtSign;
	intStrLen=email.length;
	// *** CHECK FOR BLANK EMAIL VALUE
	
	if (email == ""){
		passed = 'Email is required *';
	}else if (intAtSign == -1){
		passed = "Your email address is missing the \"@\".";
	}else if (intComma != -1){
		passed = 'Email address cannot contain a comma.';
	}else if (intSpace != -1){
		passed = 'Email address cannot contain spaces.';
	}else if ((intDot <= 2) || (intDomain <= 1)  || (intStrLen-(intLastDot+1) < 2)){
		passed = 'Please enter a valid Email address.<br>" + email + " is invalid.';
	}else{
		passed = 'success';
	}	
	return passed;
}


//---Form validator function---//
/*
* @creator: @admin
* @description: hide window
* @note: NULL
*/

function validate_this_form(){
	
	$container = $('.me_form');
	
	name = document.getElementById('news_name');
	sname = document.getElementById('news_sname');
	email = document.getElementById('news_email');
	error = "";
	
	if(name.value == ""){
		error += "Please insert your Name"+"\n";
	}
	
	if(sname.value == ""){
		error += "Please insert your Surname"+"\n";
	}
	
	if(emailverify(email.value) != 'success'){
		error += emailverify(email.value);
	}
	
	if(error != ""){
		alert(error);
		return false;
	}

}

