// JavaScript Document
//
var submitform = ['name', 'phone', 'mail', 'cv', 'message'];

function isBlank(s) {
	for(var i=0; i<s.length; i++) {
		var c = s.charAt(i);
		if((c != '') && (c != '\n') && (c != ' ')) return false;
		}	
}


function validateForm(array){
	var errs = [];
	var len = array.length;
	for(var i = 0; i < len; i++){
		e = document.getElementById(array[i]);
		//alert(e.value);
		if((e.value == null) || (e.value == '') || (isBlank(e.value))){
			//alert('Morate popuniti sva polja u formi: ' + e.id);
			errs.push(e.name);
		}
	}
	//alert('error length: ' + errs.length);
	if(errs.length != 0) {
		//alert('You have to fill in all required fields: ' + errs);
		//var err = document.getElementById('error1');
		//err.innerHTML = "";
		//err.innerHTML  = '<img src="images/layout/error_icon.gif" width="16" height="16" hspace="4" align="left"/>';
		//err.innerHTML += 
		alert('ERROR: You missed some of the required fields: ' + errs);// + '<img src="images/layout/error_ptr.gif" hspace="4" align="left"/>';
		//err.style.display = 'block';
		return false;
		//err.style.height = '600px';
	} else return true;
}

function validateForm2(array){
	var errs = [];
	var len = array.length;
	for(var i = 0; i < len; i++){
		e = document.getElementById(array[i]);
		//alert(e.value);
		if((e.value == null) || (e.value == '') || (isBlank(e.value))){
			//alert('Morate popuniti sva polja u formi: ' + e.id);
			errs.push(e.name);
		}
	}
	//alert('error length: ' + errs.length);
	if(errs.length != 0) {
		//alert('You have to fill in all required fields: ' + errs);
		var err = document.getElementById('error2');
		err.innerHTML = "";
		err.innerHTML  = '<img src="images/layout/error_icon.gif" width="16" height="16" hspace="4" align="left"/>';
		err.innerHTML += 'ERROR: You missed some of the required fields: ' + errs;// + '<img src="images/layout/error_ptr.gif" hspace="4" align="left"/>';
		err.style.display = 'block';
		err.style.height = '35px';
		return false;
		
	} else return true;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function checkStringError(str) {
	var toCheck = 'LROError';
	var ch ='';
	for(var i=0; i<8; i++) {
		ch += str.charAt(i);
	}
	alert(ch);
	if(toCheck == ch) alert(str.split(':')[1]);
}
