// JavaScript Document
// JavaScript Document

var img=new Array();
var email_error=1;
var pass_error=1;
var pass_c_error=1;
var confirm_error=1;

var host= "http://"+location.host;
if(host.search("karijera")==-1){
	host+="/karijera";
}

function preloadImg(){
	img['mingl_logo']=new Image();
	img['mingl_logo'].src='/slike/main/header/mingl-logo.jpg';
	img['mingl_logo_shine']=new Image();
	img['mingl_logo_shine'].src='/slike/main/header/mingl-logo_shine.jpg';
	img['in_progres']=new Image();
	img['in_progres'].src='/slike/main/in-progress2.gif';
}

function imgReplace(img_id,img_sub){
	document.getElementById(img_id).src=img[img_sub].src;
}

function getHTTPObject(){
	if (window.XMLHttpRequest) return new XMLHttpRequest();
	else if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
	else {
		alert("Your browser does not support AJAX.");
      	return null;
   }
}

function showBox(div_id,ref){
	document.getElementById(div_id).style.display="block";
}

function hideBox(div_id,ref){
	document.getElementById(div_id).style.display="none";
}

function loading(l_container,c_container){
	document.getElementById(l_container).innerHTML="<img src='/img/in-progress.gif' border='0' height='30'/>";
	if(document.getElementById(c_container)) document.getElementById(c_container).innerHTML="";
}

function validate_name(field,button){
	var name=document.getElementsByName(field.name).item(0).value;
	if(name=="" && name!="unesite ime"){
		document.getElementsByName(button).item(0).disabled="disabled";
		document.getElementsByName(field.name).item(0).style.border="solid 1px #900";
	}
	else{
		document.getElementsByName(button).item(0).disabled="enabled";
		document.getElementsByName(field.name).item(0).style.border="solid 1px #090";
	}
}

function validate_email(field,button){
	var alerttxt="Pogrešno unet imejl!";
	with (field){
	  apos=value.indexOf("@");
	  dotpos=value.lastIndexOf(".");
	  if (apos<1||dotpos-apos<2){
		  email_error=1;
		  document.getElementsByName(field.name).item(0).style.border="solid 1px #900";
		  document.getElementsByName(field.name).item(0).value="pogrešan imejl";
		  document.getElementsByName(button).item(0).disabled="disabled";
	  }
	  else{
		  if(email_error){
			  document.getElementsByName(field.name).item(0).style.border="solid 1px #ccc";
		  }
		 email_error=0;
		 document.getElementsByName(button).item(0).disabled="";
	  }
	}
}

function validate_password(field,button){
	var pword=document.getElementsByName(field.name).item(0).value;
	if(pword==""){
		pass_error=1;
 		document.getElementsByName(field.name).item(0).style.border="solid 1px #900";
	}
	else{
		pass_error=0;
		document.getElementsByName(field.name).item(0).style.border="solid 1px #ccc";
	}
}

function validate_email_c(field,field_c,button){
	var alerttxt="Pogrešno unet imejl!";
	with (field_c){
	  email_c=email=document.getElementsByName(field_c.name).item(0).value;
	  email=document.getElementsByName(field).item(0).value;
	  if(email!=email_c && email.length>2){
		  confirm_error=1;
		  document.getElementsByName(field_c.name).item(0).value="pogrešna potvrda imejla";
		  document.getElementsByName(field_c.name).item(0).style.border="solid 1px #900";
	  }
	  else confirm_error=0;
	  
	  if(!confirm_error){
		  document.getElementsByName(field).item(0).style.border="solid 1px #090";
		  document.getElementsByName(field_c.name).item(0).style.border="solid 1px #090";
	  }  
   }
}

function validate_password_c(field,field_c,button){
	pword_c=email=document.getElementsByName(field_c.name).item(0).value;
	pword=document.getElementsByName(field).item(0).value;
	if(pword!=pword_c){
	  pass_error=1;
	  document.getElementsByName(field_c.name).item(0).style.border="solid 1px #900";
	  document.getElementsByName(button).item(0).disabled="disabled";
  	}
	else pass_c_error=0;
  	if(!pass_c_error){
		document.getElementsByName(field).item(0).style.border="solid 1px #090";
		document.getElementsByName(field_c.name).item(0).style.border="solid 1px #090";
		document.getElementsByName(button).item(0).disabled="";
	}
}

function checkRegister(form){
	
}

function initpage(){
	var page= document.location.href.split("#/");
	var last_slash=page[0].lastIndexOf("/")+1;
	var page_view=page[0].substring(last_slash,page[0].length);
	
	if(page[1]){
		var detail_show=page[1].split("/");
		//alert(detail_show);
		switch(page_view){
			case "profil":
				eval("profil_show('profile_details','"+detail_show[0]+"','"+detail_show[1]+"');");
			break;
			case "zanimanja":
				
				eval("showZanimanja(\"zanimanja_loading\",\"zanimanja_show_info\",\""+detail_show[0]+"\",\""+detail_show[1]+"\")");
			break;
		}
	}
}

function checkDate(elem,value){
	var datum=ReplaceAll(value,".","/");
	datum=datum.substr(0,10);
	var dmg=datum.split("/");
	var date=new Date();
	var y=date.getFullYear();
	document.getElementsByName(elem.name).item(0).value=datum;
	if(dmg[0]>31 || dmg[1]>12 || dmg[2]>y-10){
		alert("Datum rodjenja koji ste uneli je neispravan!!!");
	}
}

function ReplaceAll(Source,stringToFind,stringToReplace){
  var temp = Source;
  var index = temp.indexOf(stringToFind);
  while(index != -1){
  	temp = temp.replace(stringToFind,stringToReplace);
    index = temp.indexOf(stringToFind);
  }
  return temp;
}

function rgbToHex(rgb) { 
		if (rgb.match(/^#[0-9A-Fa-f]{6}$/)) {
       		return rgb;
    	}
		var rgbvals = /rgb\((.+),(.+),(.+)\)/i.exec(rgb);
		if (!rgbvals) {
			return rgb;
		}
		var rval = parseInt(rgbvals[1]);
		var gval = parseInt(rgbvals[2]);
		var bval = parseInt(rgbvals[3]);
		var pad = function(value) {
			return (value.length < 2 ? '0' : '') + value;
		};
		return '#' + pad(rval.toString(16)) + pad(gval.toString(16)) + pad(bval.toString(16));
}

function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value+"; path=/";
}
function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  x=x.replace(/^\s+|\s+$/g,"");
	  if (x==c_name)
		{
		return unescape(y);
		}
	  }
	 return false;
}

