﻿
setTimeout(refreshSite,15*60*1000);
function refreshSite() {
	location.href="";
}

function SelectValue(str) {

		location.href='/university/0/all/'+str+'/0/';
}

function SelectCity(str,co) {

		location.href='/university/0/all/'+co+'/'+str+'/';
}

var expand_comment_form = 'comment_form';
//Coookies
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//End Cookies
$(document).ready(function() {
	/*
	$('.submenu a.show-hide').click(function(e) {
		e.preventDefault();
		if($(this).parent().find('ul').hasClass('selected')) return;
		$(this).parent().find('ul:not(.selected)').slideToggle('normal');
		
		if($(this).find('span:first').hasClass('down-bullet'))
			$(this).find('span:first').removeClass('down-bullet');
		else
			$(this).find('span:first').addClass('down-bullet');
		
		
	}); */
	$('.medform .text').focus( function() {
		$(this).attr('value','');
	});


	
	$('.med-cat input.text').focus( function() {
		if($(this).attr('value').indexOf('Търси лекарства')==0) {
		$(this).attr('value','');
		$(this).focus();
		}
	});
	
	$('#loginform input.text').focus( function() {
		if( $(this).attr('value').indexOf('Е-mail')==0 ) {
		$(this).attr('value','');
		$(this).focus();
		}
	});
	
	$('.login input.password').focus( function() {
		if($(this).attr('type')=="text") {
			name=$(this).attr('name');
			$(this).remove();
			$('span.upass').html("<input onkeypress='checkKey(this,event,\"loginform\")' class='password' type='password' name="+name+" />");
			$('span.upass input').focus();
		}
	});
	
	try {
		if(readCookie(expand_comment_form) == null)
		{
			$('#comment-form').hide();
		}
		else
		{
			$('#comment-form').show();
		}
	} catch(e) {  }
	$('p.addcomment a').click(function() {
		$('#comment-form').slideToggle('slow');
		if(readCookie(expand_comment_form) == null)
		{
			createCookie(expand_comment_form, '1', 7);
		}
		else
		{
			createCookie(expand_comment_form, '0', -1);
		}
		return false;
	});
	//end Comment
	
	
	$("#region").change(function()
        {	
    	
    	var id=$(this).val();	
    	$("#city").removeOption(/./);	
    	$("#city").ajaxAddOption("/guide/script_getcity.php",{"id":id,"spec":1,"section":"region"},false,function(){});	
        });
    $("#country").change(function()
        {	
    	
    	var id=$(this).val();	
    	$("#city").removeOption(/./);	
    	$("#city").ajaxAddOption("/guide/script_getcity.php",{"id":id,"spec":1,"section":"country"},false,function(){});	
        });
        
});

function submitform(id) {
	document.getElementById(id).submit();
}

function shareOn(socialnetwork) {
	share=[document.title,location.href];
	//alert(share);
	if(socialnetwork.indexOf('sv')==0) {
			window.open('http://svejo.net/story/submit_by_url?url='+encodeURIComponent(share[1]));
		return;
	}
	if(socialnetwork.indexOf('fb')==0) {
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(share[1])+'&t='+encodeURIComponent(share[0]),'sharer','toolbar=0,status=0,width=626,height=436');
		return;
	}
	if(socialnetwork.indexOf('tw')==0) {
		window.open('http://twitter.com/home?status='+encodeURIComponent(share[1])+'');
		return;
	}
}

function spodelime(url,title) {
	var h=220;
	var w=315;
	var t=screen.height/2-h/2-60;
	var l=screen.width/2-w/2;
	window.open("http://spodelime.com/buttons.php?url="+url+"&title="+title, "_blank", "height="+h+",width="+w+",top="+t+",left="+l+",status=0,toolbar=0,menubar=0,scrollbars=1,location=0,resizable=0"); // address
}
function checkKey(ob,event,formid) {
	if(event.keyCode==13) {
		document.getElementById(formid).submit();
	}
}

function QuizSwitch()
{
	
	var classtab1=$("#quiz-tab1").attr("class");
	var classtab2=$("#quiz-tab2").attr("class");	
	//var ctab1=classtab1.split(" ");		
	if(classtab1=='hide')
	{        
             
        $("#quiz-tab1").attr("class","");
        $("#quiz-tab2").attr("class","hide"); 
    }
	else 
	{
        
        $("#quiz-tab1").attr("class","hide");
        $("#quiz-tab2").attr("class",""); 
	}	
}

function Quiz_vote(artid)
{
var vi=$("input[@name=voteit]:checked").val();
if(vi) $.post("/scripts/_scripts_qvote.php",{vote:vi,artid:artid},function(data) 
	{  res=data.split("|");
			
		alert(res[2]);
		
		if(parseInt(res[1])) 
		{
           
           //$("#qid1").html(parseInt(res[3]));	
           var width=0;	  
		  for(var ii=1;ii<13;ii++) 
		  {
                var ki=3+ii;	
                if(parseInt(res[ki])>0)
                    kw=100*(parseInt(res[ki])/parseInt(res[3])); 
                else  kw=0;              
                vote_p=parseInt(kw);//.toFixed(2);    
                width=parseInt(kw);            
                $("#aid"+ii).html(vote_p+"%");                                              
                $("#ans-status"+ii+" span").css("width",width+"%");                
		  }
          $("#quiz-tab1").attr("class","hide");
          $("#quiz-tab2").attr("class","");
          $("#votebutton").remove();
		  //$("#results").remove();
		  
		}
	});
else alert("Моля гласувайте!");
}
//http://svejo.net/story/submit_by_url?url=http%3A%2F%2Fpharmacybg.cre%2Farticles%2Fp3-1903-0.html
