﻿// JavaScript Document

function autoFill(id, v){
	$(id).css({ color: "#C4C4C4" }).attr({ value: v }).focus(function(){
		if($(this).val()==v){
			$(this).val("").css({ color: "#4F4F4F" });
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).css({ color: "#C4C4C4" }).val(v);
		}
	});
}

$(function() {
	$('input.ms-long').css({backgroundColor:"#FFFFFF"});
	$('input.ms-long').focus(function(){
		$(this).css({backgroundColor:"#B9ECFF"});
	});
	$('input.ms-long').blur(function(){
		$(this).css({backgroundColor:"#FFFFFF"});
	});
});

function isValidEmail(email) {
	strSearch = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/
	if (strSearch.test(email)) return true;
	else return false;
}

function isNumeric(string) {
	if (string.search) {
		if (( string.search(/\D/) != -1)) return false;
	}
	return true;
}

function isPhone(string)
{
	var valid = "0123456789-+() ";

	for (var i=0; i < string.length; i++) {
		//put in temp variable each character, one at a time.
		temp = "" + string.substring(i, i+1);
		//check index of a phone character in the "valid" variable.
		// if temp contains a character which is not in "valid" variable,
		//then valid.indexOf(temp) will be -1, otherwise it may be 0.1.2.3.4.5.6.7.8 or 9
	
		if (valid.indexOf(temp) == "-1") {
			//alert("Invalid characters in your phone. Please try again.")
			return false;
		}
	}
	//if all conditions are passed, then return true
	return true
}


$(document).ready(function()
{
	if(document.getElementById("g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff1_new_ctl00_ctl00_TextField")) {
		autoFill($("#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff1_new_ctl00_ctl00_TextField"), "Ime in priimek");
	}
	if(document.getElementById("g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff3_new_ctl00_ctl00_TextField")) {
		autoFill($("#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff3_new_ctl00_ctl00_TextField"), "E-poštni naslov");
	}
	if(document.getElementById("g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff4_new_ctl00_ctl00_TextField")) {
		autoFill($("#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff4_new_ctl00_ctl00_TextField"), "Telefonska številka");
	}
	
	if(document.getElementById("g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff1_new_ctl00_ctl00_TextField")) {
		document.getElementById('g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff1_new_ctl00_ctl00_TextField').select();
		document.getElementById('g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff1_new_ctl00_ctl00_TextField').blur();
	}
		
});


function submitForm() {
	
	var name = $("input#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff1_new_ctl00_ctl00_TextField").val();
	if (name == "" || name == "Ime in priimek" || name.length < 3) {
		autoFill($("#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff1_new_ctl00_ctl00_TextField"), "Ime in priimek");
		$(this).css({Color:"#FF0000"});
		alert('Vnesite: Ime in priimek!');
		var success = 'no';
		$("input#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff1_new_ctl00_ctl00_TextField").focus();
		return false;
	}
	var email = $("input#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff3_new_ctl00_ctl00_TextField").val();
	if (email == "" || email == "E-postni naslov") {
		autoFill($("#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff3_new_ctl00_ctl00_TextField"), "E-poštni naslov");
		$(this).css({Color:"#FF0000"});
		alert('Vnesite: E-postni naslov!');
		var success = 'no';
		$("input#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff3_new_ctl00_ctl00_TextField").focus();
		return false;
	}
	var email = $("input#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff3_new_ctl00_ctl00_TextField").val();
	if (!isValidEmail(email)) {
		//autoFill($("#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff3_new_ctl00_ctl00_TextField"), "Your Valid Email Address");
		$(this).css({Color:"#FF0000"});
		alert('Vnesite: E-postni naslov!\n');
		var success = 'no';
		$("input#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff3_new_ctl00_ctl00_TextField").focus();
		return false;
	}
	var phone = $("input#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff4_new_ctl00_ctl00_TextField").val();
	if (phone == "" || phone == "Telefonska stevilka" || phone.length < 6) {
		autoFill($("#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff4_new_ctl00_ctl00_TextField"), "Telefonska številka");
		$(this).css({Color:"#FF0000"});
		alert('Vnesite: Telefonska stevilka!\nstevila, +, -, (, )');
		var success = 'no';
		$("input#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff4_new_ctl00_ctl00_TextField").focus();
		return false;
	}
	var phone = $("input#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff4_new_ctl00_ctl00_TextField").val();
	if (!isPhone(phone)) {
		//autoFill($("#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff4_new_ctl00_ctl00_TextField"), "Your Phone Number");
		$(this).css({Color:"#FF0000"});
		alert('Vnesite: Telefonska stevilka!\nstevila, +, -, (, )');
		var success = 'no';
		$("input#g_d2720204_22ae_4c54_a7b0_40a2fb8a40d6_ff4_new_ctl00_ctl00_TextField").focus();
		return false;
	}
	
	return true;
};

