﻿/*
** ANTI-ZIONISM Project
** Tabs.js Script
** By : M.Mahdavi Kia
** www.WebmasterTools.ir
*/

function check_email(str)
{
		var pattern=/(^[\-_\.a-zA-Z0-9]+)@((([0-9]{1,3}\.){3}([0-9]{1,3})((:[0-9])*))|(([a-zA-Z0-9\-]+)(\.[a-zA-Z]{2,})+(\.[a-zA-Z]{2})?((:[0-9])*)))/;
		if(str.search(pattern)==-1)
		{
			return false
		}else{
			return true;
		}
}
function checkform()
{
	var cust_name=document.getElementById('name').value;
	var cust_email=document.getElementById('email').value;
	if(cust_name=='')
	{
		alert('لطفا نام خود را وارد نمائید');		
		document.getElementById('name').focus();
		return false;
	}
	if(cust_email=='')
	{
		alert('لطفا ایمیل خود را وارد نمائید');		
		document.getElementById('email').focus();
		return false;
	}
	if(!check_email(cust_email))
	{
		alert('آدرس ایمیل وارد شده صحیح نیست');		
		document.getElementById('email').focus();
		return false;
	}
}
function checkcontact()
{
	var cust_name=document.getElementById('contact-name').value;
	var cust_email=document.getElementById('contact-email').value;
	var cust_body=document.getElementById('contact-messagebody').value;
	if(cust_name=='')
	{
		alert('لطفا نام خود را وارد نمائید');		
		document.getElementById('contact-name').focus();
		return false;
	}
	if(cust_email=='')
	{
		alert('لطفا ایمیل خود را وارد نمائید');		
		document.getElementById('contact-email').focus();
		return false;
	}
	if(!check_email(cust_email))
	{
		alert('ایمیل وارد شده صحیح نیست');		
		document.getElementById('contact-email').focus();
		return false;
	}
	if(cust_body=='')
	{
		alert('متن پیغام خالی است');		
		document.getElementById('contact-messagebody').focus();
		return false;
	}
}

function tabsOff()
{
	document.getElementById('tab-home').className='tab-home-off';
	document.getElementById('tab-about').className='tab-about-off';	
	document.getElementById('tab-news').className='tab-news-off';
	document.getElementById('tab-albums').className='tab-albums-off';
	document.getElementById('tab-contact').className='tab-contact-off';
}
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;
    }
}

function tabsEvent(id)
{
	var myString = self.location.href;
	//var culture = myString.substr(myString.length-5, 5); 	
	var queryStr=explode('=',myString);
	//alert(queryStr[1]);
	queryStr=explode('&',queryStr[1]);
	var culture=queryStr[0];
	
	var tab=document.getElementById(id);
	var nowClass=tab.className;	
	
	if(id=="tab-home" && nowClass=="tab-home-off")
	{
		tabsOff();
		tab.className='tab-home-on';
				
		ajaxpagefetcher.load('main_div_ajax','home.php?culture='+culture,true);		
	}
	if(id=="tab-about" && nowClass=="tab-about-off")
	{
		tabsOff();
		tab.className='tab-about-on';		
		ajaxpagefetcher.load('main_div_ajax','about.php?culture='+culture,true);	
	}
	if(id=="tab-news"  && nowClass=="tab-news-off")
	{
		//tab.className='tab-news-on';
		document.location.href='index.php?culture='+culture+'&html=news';
		//ajaxpagefetcher.load('main_div_ajax','news.php?culture='+culture,true);
	}
	if(id=="tab-albums" && nowClass=="tab-albums-off")
	{
		tabsOff();
		tab.className='tab-albums-on';
		ajaxpagefetcher.load('main_div_ajax','more_gallery.php?culture='+culture+'&page=1',true);
	}
	if(id=="tab-contact" && nowClass=="tab-contact-off")
	{
		tabsOff();
		tab.className='tab-contact-on';
		ajaxpagefetcher.load('main_div_ajax','contact.php?culture='+culture,true);
	}
}
function demoClose()
{
	document.getElementById('demo').style.display='none';
}
