//--------------------------
function select_themes(theme)
{
	var str='?fun=select_themes&theme='+ theme;
	AjaxRequest.post(
		{
			'url':'user/aj_function.php',
			'queryString':str,
			'onSuccess':function select_themes(req)
						{
							temp = req.responseText;
							window.location="./user/?page=intro&theme="+theme;
						},
			'onError':function select_themes(req){alert(req.responseText)}
		});
}
//---------------------------
var xmlHttp;
var currentState = 'started';
//var explorer= EXPLORER ;

function subscribe_mail()
{
	document.getElementById("name_country").value = document.getElementById("country").options[document.getElementById("country").options.selectedIndex].text;
	document.getElementById("name_specialization").value = document.getElementById("specialization").options[document.getElementById("specialization").options.selectedIndex].text;
}



function tickerPlay(dir){
	var tickerObj = document.getElementById('tickerObj');
	var play_div = document.getElementById('play_div');
	if (dir == 1) {
		tickerObj.direction = 'left';
		tickerObj.start();
		currentState = 'stopped';
		play_div.style.display='none';
		tickerPlay(0);
	}else if(dir == -1) {
		tickerObj.direction = 'right';
		tickerObj.start();
		currentState = 'stopped';
		play_div.style.display='none';
		tickerPlay(0);
	}else {
		// save last dir, restart
		if (currentState == 'started') {
			tickerObj.stop();
			play_div.style.display='block';
			currentState = 'stopped';
		}else {
			play_div.style.display='none';
			tickerObj.start();
			currentState = 'started';
		}
	}
}

function setColock()
{
	current_time = new Date();
	secs = current_time.getSeconds();
	mins = current_time.getMinutes();
	hrs = current_time.getHours();
	year = current_time.getFullYear()
	month = current_time.getMonth()
	current_date = current_time.getDate();
	day  = current_time.getDay();
	am = AM;
	if (hrs >= 12)
	{
		if (hrs != 12)
			hrs = "0" + hrs - 12 ;
		am = PM;
	}

	if (hrs < 10)
		hrs = "0" + hrs;

	if (hrs == 00)
		hrs = 12 ;
	if (mins < 10)
		mins = "0" + mins ;
	
	if(LANG == "ar")
	document.getElementById("date").innerText = dayarray[day] + '   ' + current_date  + '  ' + montharray[month] + '  ' + year;
	else
	document.getElementById("date").innerText = dayarray[day] + '  ' + montharray[month] + '  ' + current_date + ', ' + year;

	document.getElementById("time").innerText = hrs + ':' + mins + ' ' + am;
	
}

function getAbsolutePos (el)
{
	var SL = 0, ST = 0;

	if(!el)
        return { x: 0 , y: 0 };
	else
		var is_div = /^div$/i.test(el.tagName);

	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;

	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };

	if (el.offsetParent)
	{
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

function set_play_position()
{
	dv = document.getElementById("play_div");
	td = document.getElementById("td_play");
	pos = getAbsolutePos(td);
	dv.style.left = pos.x + 10;
}

// JavaScript Document

function showPage(page_name)
{
	loading_div2 = document.getElementById("loading_div");
	loading_div2.style.display = "block";
	document.getElementById("divContent").innerHTML="";
	//alert('piogh');
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url=page_name;
	//alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=windows-1256;');
	xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		//alert(xmlHttp.responseText);
		document.getElementById("divContent").innerHTML=xmlHttp.responseText!=""?xmlHttp.responseText:"&nbsp;";
		loading_div2 = document.getElementById("loading_div");
		loading_div2.style.display = "none";
		//if(explorer)
			//InitialiseScrollableArea();	
	} 
} 

function GetXmlHttpObject()
{ 
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

function showDetailPage(page_name)
{ 
	loading_div2 = document.getElementById("loading_div");
	loading_div2.style.visibility = "visible";
	document.getElementById(div_name).innerHTML="";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url=page_name;
	xmlHttp.onreadystatechange=stateDetailChanged; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateDetailChanged() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById(div_name).innerHTML=xmlHttp.responseText;
		for(i = 0; i < 20000; i++);
		loading_div2 = document.getElementById("loading_div");
		loading_div2.style.visibility = "hidden";
	}
}


function change_category(image,url,flashurl)
{
	document.getElementById('img_sol_image').src = image ;
	document.getElementById("id_sol_flash").innerHTML='<object style="z-index:1;float:RIGHT;background:inherit " classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="" width="399" height="162" id="intro"><param id="flash" name="movie" value="'+ flashurl +'"><param name="quality" value="high"><param name="bgcolor" value="#FFFFFF"><param name="menu" value="false"><embed src="'+ flashurl +'" quality="high" bgcolor="#FFFFFF" width="399" height="162" name="intro" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></object>';
	showPage(url) ;
}

function cahang_partner(j)
{
	for(i=1;i<5;i++)
	{
		document.getElementById('header_partner_'+i).style.backgroundColor=button_inactive_bg;
		document.getElementById('header_partner_'+i).style.color=button_inactive_tx;
		document.getElementById('text_partner_'+i).style.display ="none" ;
	}
	
		document.getElementById('header_partner_'+j).style.backgroundColor=button_active_bg;
		document.getElementById('header_partner_'+j).style.color=button_active_tx;
		document.getElementById('text_partner_'+j).style.display ="block" ;
}


function change_competition(j)
{
	for(i=1;i<=2;i++)
	{
		document.getElementById('header_competition_'+i).style.backgroundColor=button_inactive_bg;
		document.getElementById('header_competition_'+i).style.color=button_inactive_tx;
		document.getElementById('text_competition_'+i).style.display ="none" ;
	}
	
		document.getElementById('header_competition_'+j).style.backgroundColor=button_active_bg;
		document.getElementById('header_competition_'+j).style.color=button_active_tx;
		document.getElementById('text_competition_'+j).style.display ="block" ;
}



// Care 

function contract_get(obj)
{

	    AjaxRequest.get(
	    {
	        'url':'./get_contract.php?account_id=' + obj,
	        'onSuccess':view_contract
	    });

}

function view_contract(req)
{	
	document.getElementById('td_contract').innerHTML = req.responseText;  
}

function  switch_tab(id_tab,image,flashurl)
{
	clicked_tab=document.getElementById(id_tab);
	td_clicked=clicked_tab.parentNode;
	parentTable=td_clicked.parentNode.parentNode;
	id_clicked=td_clicked.id;
	for(var i=1; i<=parentTable.childNodes.length; i++)
	{
		if(parentTable.childNodes[i-1].firstChild.id==id_clicked)
		{
			document.getElementById("adiv_"+i).style.display="none";
			document.getElementById("div_"+i).style.display="block";
		}
		else
		{
			document.getElementById("adiv_"+i).style.display="block";
			document.getElementById("div_"+i).style.display="none";
		}
	}
	if(document.getElementById('img_sol_image')!=null)
	{
		document.getElementById('img_sol_image').src = image ;
		document.getElementById("id_sol_flash").innerHTML='<object style="z-index:1;float:RIGHT;background:inherit " classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="" width="399" height="162" id="intro"><param id="flash" name="movie" value="'+ flashurl +'"><param name="quality" value="high"><param name="bgcolor" value="#FFFFFF"><param name="menu" value="false"><embed src="'+ flashurl +'" quality="high" bgcolor="#FFFFFF" width="399" height="162" name="intro" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></object>';
	}
}

function change_newsImage(i, count){
		setTimeout(function() {
				var last_img = document.getElementById('news_image').src;
				$('#news_image').fadeIn('slow').delay(150).fadeOut('slow', function() { $(this).hide(); document.getElementById('news_image').src=img_path+images[i % count];});
				$('#news_image').fadeOut('slow').delay(50).fadeIn('slow', function() { $(this).show(); }); 
			}, 7000);
		setTimeout("change_newsImage("+(i+1)+","+count+")",7000);
}
function change_newsText(i, count){
		setTimeout(function() {
				var text_img = $('#news_title').html();
				$('#news_title').html('');
				$('#news_title').html('<a href="./user.php?page=this_news&id='+id[i % count]+'"><strong><u><i>'+aimages[i % count]+'</i></u></strong></a>');
				$('#subContent').html('');
				$('#subContent').html(subContent[i % count]+'.....');
				var more = $('#more_news').html();
				// alert();
				// $('#more_news').html('');
				// $('#more_news').html('<a href="./user.php?page=this_news&id='+id[i % count]+'">'+more+'<a>');
			}, 7000);
		setTimeout("change_newsText("+(i+1)+","+count+")",7000);
}

function change_main_img(i, count)
	{
		setTimeout(function() {
				var last_img = document.getElementById('main_image').src;
				$('#main_image').fadeIn('slow').delay(150).fadeOut('slow', function() { $(this).hide(); document.getElementById('main_image').src=img_path1+images1[i % count];});
				$('#main_image').fadeOut('slow').delay(50).fadeIn('slow', function() { $(this).show(); }); 
			}, 7000);
		setTimeout("change_main_img("+(i+1)+","+count+")",7000);
	}
function change_text_img(i, count)
	{
		setTimeout(function() { 
			$('#news_images').fadeIn('slow').delay(150).fadeOut('slow', function() { $(this).hide('slide',{},1000); document.getElementById('news_images').src=img_path+'a'+images[i % count];});
			$('#news_images').fadeOut('slow').delay(50).fadeIn('slow', function() { $(this).show('clip',{},1000); }); 
		}, 5000);
		setTimeout("change_text_img("+(i+1)+","+count+")",5000);
	//alert('asd');
	/*$("#main_aimage").hide('slide',{},1000);
	document.getElementById('main_aimage').src=img_path+'a'+images[i % count];
	$("#main_aimage").show('clip',{},1000);
	setTimeout("change_text_img("+(i+1)+","+count+")",7000);*/
	}
	
	function scollWin(){
//$('html, body').animate({
//scrollTop: $("#scroll").offset().top
//}, 2000);
$(function() {
		$("div#scroll").smoothDivScroll({ autoScroll: "onstart", autoScrollDirection: "backandforth", autoScrollStep: 1, autoScrollInterval: 15, startAtElementId: "startAtMe", visibleHotSpots: "always"});
	});
	
}
function checkPassword(){
	var validator = new Validator();
	if (!validator.validateEmptyFields("username")){
		alert("Please Enter Your Username");
		return false;
	}
	if (!validator.validateEmptyFields("password")){
		alert("Please Enter Your Password");
		return false;
	}
	document.getElementById("password").value = hex_sha256(document.getElementById("password").value) + hex_sha256(document.getElementById("challenge").value);
}
function slideToggle_paly(id)
{
	$("#"+id).animate({height: 'toggle', opacity: 'toggle'}, 'slow');
	$.post('includes-php/_jud_ajax.php',
			{"LinkName":id},
			function(response){
				if(response.success){}
			}
	);
	$('.toggle').not("#"+id).each(function(){
		if($(this).css('display') == 'block')
			$(this).animate({height: 'toggle', opacity: 'toggle'}, 'fast');
	});
}
function goToPage(Link){
	window.location = Link;
	if(Link == './user.php?page=plan_calander')
		$.post('includes-php/_jud_ajax.php',
				{"LinkName":''},
				function(response){
					if(response.success){}
				}
		);
}
$(function(){
	$('.SecondMenu').each(function(){
		$(this).hover(function(){
						$(this).removeClass('SecondMenu');
						$(this).addClass('SecondMenuHover');
						},function(){
							$(this).removeClass('SecondMenuHover');
							$(this).addClass('SecondMenu');
		})
	});
	$('.SubMenu').each(function(){
		$(this).hover(function(){
						$(this).removeClass('SubMenu');
						$(this).addClass('SubMenuHover');
						},function(){
							$(this).removeClass('SubMenuHover');
							$(this).addClass('SubMenu');
		})
	});
	$('.Menu').each(function(){
		$(this).hover(function(){
						$(this).removeClass('Menu');
						$(this).addClass('MenuHover');
						},function(){
							$(this).removeClass('MenuHover');
							$(this).addClass('Menu');
		})
	})
})

