$(document).ready(function(){
	$(".slide_me").click(function () {
		$("#"+this.className.replace(" slide_me ", "").replace("slide_me ", "")).toggle();
	});
	
	if($('.swf')){
		$('.swf').flash({
			swf: 'player_stop.swf',
			width: 640,
			height: 360,
			flashvars: {
				urlu: $('.swf').attr('url'),
				flvu: 'swf/'+$('.swf').attr('swf')+'.flv'
			}
		});
	}
});

function martie(){
		$('.no_swf').height(388);
		$('.no_swf').flash({
			swf: 'FLVPlayer.swf',
			width: 640,
			height: 360,
			flashvars: {
				flvu: 'swf/martie.flv'
			}
		});
	}

function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
		//alert("Invalid E-mail Address")
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)===0 || str.indexOf(at)==lstr){
		//alert("Invalid E-mail Address")
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)===0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail Address")
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		//alert("Invalid E-mail Address")
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("Invalid E-mail Address")
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		//alert("Invalid E-mail Address")
		return false;
	}
	if (str.indexOf(" ")!=-1){
		//alert("Invalid E-mail Address")
		return false;
	}
	return true;
}

function check_email(f){
	if(echeck(f.email.value) && f.email.value!=''){
		f.submit();
	} else if(f.email.value!='') {
		alert('Trebuie sa introduceti o adresa de email valida!');
		return false;
	} else if(f.email.value==''){
		return false;
	}
}

function ChangeSelectByValue(ddlID, value) {
     var ddl = document.getElementById(ddlID);
     for (var i = 0; i < ddl.options.length; i++) {
         if (ddl.options[i].value == value) {
             if (ddl.selectedIndex != i) {
                 ddl.selectedIndex = i;
             }
             break;
         }
     }
 }
 
function preloader()
{
     // counter
     var i = 0;

     // create object
     imageObj = new Image();

     // set image list
     images = new Array;
     images[0]="but_1.jpg";
     images[1]="but_2.jpg";
     images[2]="but_3.jpg";
     images[3]="but_over.jpg";
     images[4]="but_sub.jpg";

     // start preloading
     for(i=0; i<=4; i++) 
     {
          imageObj.src=images[i];
     }
}

function ajaxStart(){
	if (navigator.appName=="Microsoft Internet Explorer")
	    return new ActiveXObject("Microsoft.XMLHTTP");
	else
		return new XMLHttpRequest();
}

function ajaxGet(link){
	var objHTTP=ajaxStart();
	objHTTP.open('GET',link,false);
	objHTTP.send(null);
	return objHTTP.responseText;
}

function delete_message(id){
	if(confirm('Esti sigur ca vrei sa stergi acest mesaj?')){
		res = ajaxGet('delete_message.php?id='+id);
		if(res=='ok'){
			window.location.reload();
		} else {
			alert(res);
		}
	}
}

function delete_sp(id){
	if(confirm('Esti sigur ca vrei sa stergi aceasta lucrare?')){
		res = ajaxGet('delete_sp.php?id='+id);
		if(res=='ok'){
			window.location.reload();
		} else {
			alert(res);
		}
	}
}

function delete_raport(id){
	if(confirm('Esti sigur ca vrei sa stergi acest raport?')){
		res = ajaxGet('delete_raport.php?id='+id);
		if(res=='ok'){
			window.location.reload();
		} else {
			alert(res);
		}
	}
}

function delete_forum(id){
	if(confirm('Esti sigur ca vrei sa stergi acest mesaj?')){
		res = ajaxGet('delete_forum.php?id='+id);
		if(res=='ok'){
			window.location.reload();
		} else {
			alert(res);
		}
	}
}

function delete_acs(id){
	if(confirm('Esti sigur ca vrei sa stergi acest ACS?')){
		res = ajaxGet('delete_acs.php?id='+id);
		if(res=='ok'){
			window.location.reload();
		} else {
			alert(res);
		}
	}
}

function delete_cerinta(id){
	if(confirm('Esti sigur ca vrei sa stergi aceasta cerinta?')){
		res = ajaxGet('delete_cerinta.php?id='+id);
		if(res=='ok'){
			window.location.reload();
		} else {
			alert(res);
		}
	}
}

function delete_ev(id){
	if(confirm('Esti sigur ca vrei sa stergi aceasta evaluare?')){
		res = ajaxGet('delete_evaluare.php?id='+id);
		if(res=='ok'){
			window.location.reload();
		} else {
			alert(res);
		}
	}
}

function validateForm(ids, fields)
{
	if (ids.length > 0)
	{
		for (var key in ids)
		{
			if (!isValid(document.getElementById(ids[key])))
			{
				alert("Campul " + fields[key] + " este obligatoriu");
				return false;
			}
		}
	}
	return true;
}

function isValid(obj)
{
	if (obj.value.length == 0)
	{
		return false;
	}
	return true;
}


preloader();

