/***** SCRIPTING*****/

/*
Methods to check the EMPTY Fields.
*/
function focusGainTxt(field){									
	var a = document.getElementById(field);
	if (a.value == "dd/mm/yyyy")
	{
		a.value = '';
	}
}

function focusLostTxt(field){									
	var a = document.getElementById(field);
	if (a.value == "")
	{
		a.value = a.defaultValue;		
		a.style.color='#999999';
	}
	else
	{		
		a.style.color='#000000';	
	}
}


function checkEmpty(field, txt){
	var comp = document.getElementById(field);
	if(comp.value == ""){
		comp.focus(showError(comp));
		showTxt(txt);
		return true;		
	}else{
		return false;
	}
}

function checkEmpty(field, txt){
	var comp = document.getElementById(field);
	if(comp.value == ""){
		comp.focus(showError(comp));
		showTxt(txt);
		return true;		
	}else{
		return false;
	}
}

function checkImage(field, txt){
	var comp = document.getElementById(field);
	if(comp.disabled == false){
		if(comp.value == ""){
			comp.focus(showError(comp));
			showTxt(txt);
			return true;
		}
	}
}

function checkList(field, txt){
	var comp = document.getElementById(field);
	if(comp.selectedIndex == 0){
		comp.focus(showError(comp));
		showTxt(txt);
		return true;
	}
}

function checkDateField(field, txt){
	var comp = document.getElementById(field);
	if(comp.value == "dd/mm/yyyy"){
		showError(comp);
		showTxt(txt);
		return true;		
	}else{
		return false;
	}
}

function showError(attribute){
	attribute.style.borderWidth='thin';
	attribute.style.borderColor='#FF0000';
	attribute.style.borderStyle='groove';
}

function showTxt(txt){
	var msg = document.getElementById("Error");
	msg.style.display='block';
	msg.innerHTML = txt;
	msg.style.color='#FF0000';
}

function clearTxt(field){
	var msg = document.getElementById("Error");
	msg.style.display='none';
	msg.innerHTML = "";
	document.getElementById(field).style.borderWidth='thin';
	document.getElementById(field).style.borderColor='#CCCCCC';
	document.getElementById(field).style.borderStyle='groove';	
}


function checkRadioValues(field, txt){
	var comp = document.getElementById(field);
	comp.style.borderWidth='1';
	comp.style.borderColor='#FF0000';
	comp.style.borderStyle='solid';
	showTxt(txt);
}

function normalRadio(field1, field2){
	var comp = document.getElementById(field1).checked;
	if(comp == true)
	{
		var obj = document.getElementById(field2);
		obj.style.borderWidth='0';
		showTxt("");
	}
}

function normal_all(field){
	var attribute = document.getElementById(field);
	attribute.style.borderWidth='1';
	attribute.style.height='16px';
	attribute.style.borderColor='#7F9DB9';
	attribute.style.borderStyle='solid';
	showTxt("");
}

function normal(field){
	var attribute = document.getElementById(field);
	attribute.style.width='250px';
	attribute.style.borderWidth='1';
	attribute.style.height='18px';
	attribute.style.borderColor='#7F9DB9';
	attribute.style.borderStyle='solid';
	showTxt("");
}

function normalSmall(field){
	var attribute = document.getElementById(field);
	attribute.style.width='132px';
	attribute.style.borderWidth='1';
	attribute.style.height='16px';
	attribute.style.borderColor='#7F9DB9';
	attribute.style.borderStyle='solid';
	showTxt("");
}

function normalBox(field){
	var attribute = document.getElementById(field);
	attribute.style.borderWidth='1';
	attribute.style.height='84px';
	attribute.style.width='252px';
	attribute.style.borderColor='#7F9DB9';
	attribute.style.borderStyle='solid';
	showTxt("");
}

function normalImage(field){
	var attribute = document.getElementById(field);
	attribute.style.borderWidth='1';
	attribute.style.height='18px';
	attribute.style.borderColor='#7F9DB9';
	attribute.style.borderStyle='solid';
	showTxt("");
}

/*
Methods to find the Numbers
*/
function checkNumber(field){
	var str = field.value;
	var patt= /\D/;
	var check = patt.test(str);	
	return check;
}

/* DATE FUNCTIONS*/
function checkDate(field, txt){
	var a = document.getElementById(field);
	var str = a.value;
	var patt= new RegExp("^(((((0[1-9])|(1\\d)|(2[0-8]))\\/((0[1-9])|(1[0-2])))|((31\\/((0[13578])|(1[02])))|((29|30)\\/((0[1,3-9])|(1[0-2])))))\\/((20[0-9][0-9])|(19[0-9][0-9])))|((29\\/02\\/(19|20)(([02468][048])|([13579][26]))))$");
	var check = patt.test(str);	
	if(check){
		return false;
	}else{
		a.focus(showError(a));
		showTxt(txt);
		return true;
	}	
}

function checkEmail(field, txt){
	var a = document.getElementById(field);
	var str = a.value;
	var patt= /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	var check = patt.test(str);	
	if(check){
		return false;
	}else{
		a.focus(showError(a));
		showTxt(txt);
		return true;
	}
}

function checkFileType(fileName, fileTypes, txt) {
	var comp = document.getElementById(fileName);
	var a = comp.value;
	dots = a.split(".")
	fileType = "." + dots[dots.length-1];
	if(fileTypes.join(".").indexOf(fileType) != -1) 
	{ 
		// if value Matches with given inputs
		return false;
	}else{
		// Wrong File
		comp.focus(showError(comp));
		showTxt(txt);
		return true;
	}
}
/*
On Mouse Over the color of the button changes.
*/
function mouseOn(bid){
	document.getElementById(bid).style.backgroundColor='#3E647E';	
}

function mouseOut(bid){
	document.getElementById(bid).style.backgroundColor='#7F9DB9';	
}

