﻿//hvatac gresaka
/*function onerror(msg, URL, lineNum) {
	var errWind = window.open("","errors","HEIGHT=270,WIDTH=400")
	var wintxt = "<HTML><BODY BGCOLOR=RED>"
	wintxt += "<B>An error has occurred on this page.  Please report it to Tech Support.</B>"
	wintxt += "<FORM METHOD=POST ACTION=mailTo:support3@dannyg.com>"
	wintxt += "<TEXTAREA COLS=45 ROWS=8 WRAP=VIRTUAL>"
	wintxt += "Error: " + msg + "\n"
	wintxt += "URL: " + URL + "\n"
	wintxt += "Line: " + lineNum + "\n"
	wintxt += "Client: " + navigator.userAgent + "\n"
	wintxt += "-----------------------------------------\n"
	wintxt += "Please describe what you were doing when the error occurred:"
	wintxt += "</TEXTAREA><P>"
	wintxt += "<INPUT TYPE=SUBMIT VALUE='Send Error Report'>"
	wintxt += "<INPUT TYPE=button VALUE='Close' onClick='self.close()'>"
	wintxt += "</FORM></BODY></HTML>"
	errWind.document.write(wintxt)
	errWind.document.close()
	return true
}*/
function noError(){ return true ; }
window.onerror = noError;

//predefinisana funkcija jer getElementsByClassName ne radi u IE
function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}


function Home_VipIn(id, NewImage) {
      document.getElementById("hvip"+id).src = "/upload/logo/vip_home/"+NewImage;
}

function Home_VipOut(id, NewImage) {
      document.getElementById("hvip"+id).src = "/upload/logo/vip_home/"+NewImage;
}

function Home_TraziKeyUp(event) {
  	var keynum; 
	if (window.event)  {keynum = event.keyCode;} else if (event.which)  {keynum = event.which;}   // IE else Netscape/Firefox/Opera
    if (keynum == 13)  {Home_Izvolite();}  // enter
}

function Home_TraziClickOn () {
  var izvolite_trazi = document.getElementById('izvolite_trazi');
  var str_trazi = izvolite_trazi.value;
  var levi = str_trazi.substr(0,12);
  if (levi=='Upišite nazi') {izvolite_trazi.value = '';}
}

function Home_Izvolite () {
  var str_trazi = document.getElementById('izvolite_trazi').value;
  var levi = str_trazi.substr(0,12);
  if (levi=='Upišite nazi') {SEARCH_Exec();} else {SEARCH_Exec('', str_trazi);}
}

function HideDiv(divID)   {document.getElementById(divID).style.display="none";}
function ShowDiv(divID)   {document.getElementById(divID).style.display="block";}

//front_posetilac - naci i zameniti sa gornjim funkcijama - mozda
function showHideDiv(divID) {
    if($(divID).style.display == "none")  {$(divID).show();}  
    else  {$(divID).hide();}  
}

function DostavaCene() {
    var pars = "browser=other"; var ua= navigator.userAgent; var ualow = ua.toLowerCase();
    if(ualow.indexOf("msie 6.0") != -1)  {var pars = "browser=ie6";}
    ShowDiv("LayCommon"); 
	var myAjax = new Ajax.Updater('LayCommon', '/Front_Links/DostavaCene', {method: 'post', parameters: pars});
}

// posetilac: mojprofil, registracija
function setZipOptions(index, field) {	field.selectedIndex = index   }

// Zameniti sa kalendarskim prikazom 
function selectOrdersByPeriod(period, page)       {	document.location.href = '/Front_Posetilac/kupovine/period/' + period;  }

//provera captcha koda
function checkCaptcha(captchaKod){
    var pars = 'captchaKod=' + captchaKod;
    var url = "/Front_Links/checkCaptcha/";
	new Ajax.Request(url, {		method: 'post',		parameters: pars,
		onSuccess: function(transport) {		var captcha = transport.responseText;			$('captchaProvera').value = captcha;	}
	});
}

function KupacEmailExist(email, id){
    var pars = 'email=' + email + '&id=' + id;
    var url = '/Front_Posetilac/Email_Exist/';
	new Ajax.Request(url, {		method: 'post',		parameters: pars,
		onSuccess: function(transport) {	var checking = transport.responseText;   $('emailProvera').value = checking;		}
	} );
}

function ProdZahtevEmailExist(email, id){
    var pars = 'email=' + email;
    var url = '/Front_Links/Prodavnica_Zahtev_EmailExist/';
//    var url = '/Front_Posetilac/Email_Exist/';
	new Ajax.Request(url, {		method: 'post',		parameters: pars,
		onSuccess: function(transport) {	var checking = transport.responseText;   $('emailProvera').value = checking;		}
	} ) ;
}



// -------------------- EMAIL string verifikacija -----------------------------
function checkEmail(form) {
	if (isBlank(form.email.value) || !isEmailValid(form.email.value) ) {
		alert("Please enter a valid Email Address.\nThe email you have typed in does not appear to be valid.");
		form.email.focus();
		return false;
	}
    return true;
}

function isBlank(fieldValue) {
	var blankSpaces = / /g;
	fieldValue = fieldValue.replace(blankSpaces, "");
	return (fieldValue == "") ? true : false;
}

function isEmailValid(fieldValue) {
	var emailFilter = /^.+@.+\..{2,4}$/;
	var atSignFound = 0;
	for (var i = 0; i <= fieldValue.length; i++)
		if ( fieldValue.charAt(i) == "@" )
			atSignFound++;
	if ( atSignFound > 1 )
		return false;
	else
		return ( emailFilter.test(fieldValue) && !doesEmailHaveInvalidChar(fieldValue) ) ? true : false;
}

function doesEmailHaveInvalidChar(fieldValue) {
	var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\] ]/;
	return ( illegalChars.test(fieldValue) ) ? true : false;
}
// -------------------- end of  EMAIL string verifikacija -----------------------------



  
// AdminShop/registracija/index.tpl,  AdminAdmin/prodavnice/nova_prodavnica.tpl  
function validateShopForm(u) {     			 
	if ($('email').value.length ==0){
		alert("Morate uneti email adresu.");
		$('email').focus();
		return false; 
	}else if ($('email').value.length > 0 && !isEmailValid($('email').value)){
		alert("Potrebno je uneti ispravanu email adresu.");
		$('email').focus();
		return false; 
	}else if($('emailProvera').value == "1"){
		alert("Email koji ste uneli vec postoji u bazi.");
		$('email').focus();
		return false; 
	}else if($('lozinka').value.length ==0 || $('lozinka').value.length < 3){
		alert("Potrebno je uneti lozinku i mora biti vise od 3 karaktera.");
		$('lozinka').focus();
		return false;		 
	}else if ($('lozinka').value != $('lozinka2').value){
		alert("Vrednosti unetih lozinki se ne poklapaju.");
		$('lozinka2').focus();
		return false;
	}else if ($('naziv_prodavnice').value.length == 0){
		alert("Potrebno je uneti naziv podavnice. Polja oznacena znakom * su obavezna.");
		$('naziv_prodavnice').focus();
		return false;
	}else if ($('naziv').value.length == 0){
		alert("Potrebno je uneti naziv firme. Polja oznacena znakom * su obavezna.");
		$('naziv').focus();
		return false;  
	}else if ($('ulica').value.length == 0){
		alert("Potrebno je uneti ulicu. Ako nema ulice upisite NEMA ULICE.");
		$('ulica').focus();
		return false;  
//	}else if ($('broj_ulice').value.length == 0){
//		alert("Potrebno je uneti broj ulice. \nAko je ulica bez broja upisite bb.");
//		$('broj_ulice').focus();
//		return false; 
//	}else if ($('telefon').value.length == 0){
//		alert("Potrebno je uneti broj telefona. Polja oznacena znakom * su obavezna.");
//		$('telefon').focus();
//		return false;  
//	}else if ($('mobilni').value.length == 0){
//		$('mobilni').focus();
//		alert("Potrebno je uneti broj mobilnog telefona. Polja oznacena znakom * su obavezna.");
//		return false;
//	}else if ($('captchaProvera').value == "0"){
//		$('captchaKod').focus();
//		alert("Uneli ste pogresan kod.");
//		return false;
	}else if (u==1){
		if(!$('uslovi').checked ){
			alert("Potrebno je da prihvatite uslove saradnje.");
			return false;
		}
	}else{
		return true;
	}
}

 
  
function validateUserForm(u) {
	if ($('email').value.length ==0){
		alert("Morate uneti email adresu.");
		$('email').focus();
		return false; 
	}else if ($('email').value.length > 0 && !isEmailValid($('email').value)){
		alert("Potrebno je uneti ispravanu email adresu.");
		$('email').focus();
		return false; 
	}else if($('emailProvera').value == "1"){
		alert("Email koji ste uneli vec postoji u bazi.");
		$('email').focus();
		return false; 
	}else if($('lozinka').value.length == 0 || $('lozinka').value.length < 3){
		$('lozinka').focus();
		alert("Potrebno je uneti lozinku i mora biti vise od 3 karaktera.");
		return false;		 
	}else if ($('lozinka').value != $('lozinka2').value){
		$('lozinka2').focus();
		alert("Vrednosti unetih lozinki se ne poklapaju.");
		return false;
	}else if ($('email').value.length == 0){
		$('email').focus();
		alert("Potrebno je uneti email adresu.");
		return false;
	}else if ($('email').value.length > 0 && !isEmailValid($('email').value)){
		$('email').focus();
		alert("Potrebno je uneti ispravnu email adresu.");
		return false;
	}else if ($('ime').value.length == 0){
		$('ime').focus();
		alert("Potrebno je uneti ime. Polja oznacena znakom * su obavezna.");
		return false;
	}else if ($('prezime').value.length == 0){
		$('prezime').focus();
		alert("Potrebno je uneti prezime. Polja oznacena znakom * su obavezna.");
		return false;
	}else if ($('telefon').value.length == 0 && $('mobilni').value.length == 0){
		alert("Potrebno je uneti neki kontakt telefon.");
		return false;
	}else if ($('ulica').value.length == 0){
		alert("Potrebno je uneti ulicu. Ako nema ulice upisite NEMA ULICE.");
		$('ulica').focus();
		return false;  
	}else if ($('broj_ulice').value.length == 0){
		alert("Potrebno je uneti broj ulice. \nAko je ulica bez broja upisite bb.");
		$('broj_ulice').focus();
		return false; 
// Darko - iskljucio sam proveru Captcha dok je ne poboljsamo
//	}else if($('captchaProvera').value == "0"){
//			$('captchaKod').focus();
//			alert("Uneli ste pogresan kod.");
//			return false;
	}else if (u==1){
		if(!$('uslovi').checked ){
			alert("Potrebno je da prihvatite uslove saradnje.");
			return false;
		}
	}else{
		return true;
	}
}

  
function validateForgotPassForm(email) {			 
	if (email.value.length ==0){
		alert("Potrebno je uneti email adresu.");
		email.focus();
		return false; 
	}else if (email.value.length > 0 && !isEmailValid(email.value)){
		alert("Potrebno je uneti ispravanu email adresu.");
		email.focus();
		return false; 
    }else{
        return true;
    }     
}






// funkcije za prikaz lokacija za shop blog
function divLeave(id){
	e=document.getElementById(id);
	e.style.background = '#E9E7D5';
}

function updateLocationInfo(naziv, slika, adresa, mesto, telefon, radnidan, subota, nedelja, id ){
	e=document.getElementById(id);
	e.style.background = '#FF5100';

	var content = "";
	  content += '<div style="position:relative; top:0px; font-weight:900; color:#FF5100; font-size:14pt; border-bottom: #b4b4b4 1px solid;">' + naziv + '</div>';
	  content += '<div style="position:relative; top:3px;">' + adresa + '</div>';
	  content += '<div style="position:relative; top:3px;">' + mesto + '</div>';
	  content += '<div style="position:relative; top:5px;">' + telefon + '</div>';

	  content += '<div style="position:relative; top:20px; font-weight:900; font-size:9pt; border-bottom: #b4b4b4 1px solid;"> Radno vreme </div>';
	  if(radnidan == '') {radnidan='ne radimo'} else {radnidan +=' h'}
	  content += '<div style="position:relative; margin-top:25px;">Radnim danom: ' + radnidan + '</div>';
	  if(subota == '') {subota='ne radimo'} else {subota +=' h'}
	  content += '<div style="position:relative; margin-top:3px;">Subotom: ' + subota + '</div>';
	  if(nedelja == '') {nedelja='ne radimo'} else {nedelja +=' h'}
	  content += '<div style="position:relative; margin-top:3px;">Nedeljom: ' + nedelja + '</div>';
	  $('LokacijeInfo').update(content);

	var imgcontent = "";
	imgcontent = '<img src="/view_image.php?slika='+ slika +'&resize=400&folder=prodajno_mesto&fit=0"/>';
	if(slika != '') {$('lokacije_slika').update(imgcontent);}

}

