/** JavaScript Document

 * Project: "OPL" (http://www.opticalprescriptionlab.com)

 *

 * @version			1.0

 * @create_date		20.01.2008

 * @changed_date	20.01.2008

 */



function changeOtherStatus(obj)

{

	if ($(obj).value == 'Other') {

		$('other_ecp_type').up('td').previous('th').removeClassName('disabled');

		$('other_ecp_type').enable();

	} else {

		$('other_ecp_type').up('td').previous('th').addClassName('disabled');

		$('other_ecp_type').disable();

	}

}



// preloadImg, currentPosition, imgCount, interval, opacityInterval, currentOpacity, 

// imgObjUp, imgObjDown  -  in file '/templates/default/img_rotator.tpl'

function startRotator()

{

	imgObjUp	= $('rotateUp');
	

	imgObjDown	= $('rotateDown');

//	Without Prototype
	/*

	imgObjUp	= document.getElementById('rotateUp');

	imgObjDown	= document.getElementById('rotateDown');

	imgObjUp.src	= preloadImg[currentPosition].src;

	currentPosition	++;

	imgObjDown.src	= preloadImg[currentPosition].src;

	currentPosition ++;

	hide();*/

}



function hide()

{

	if(currentOpacity == 1) {

		currentOpacity = 10;

		replaceImg();

	} else {

		if (navigator.appName != 'Microsoft Internet Explorer') {

			imgObjUp.style.opacity = (currentOpacity - 1) * 0.1;

		} else {

			imgObjUp.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + (currentOpacity - 1) * 10 + ')';

		}

		currentOpacity--;

		setTimeout('hide();', opacityInterval);

	}

}



function replaceImg()

{

	imgObjUp.src = imgObjDown.src;

	if (navigator.appName != 'Microsoft Internet Explorer') {

		imgObjUp.style.opacity = currentOpacity * 0.1;

	} else {

		imgObjUp.style.filter = '.' + currentOpacity * 10 + ')';

	}

	//imgObjDown.src = preloadImg[currentPosition].src;

	if(currentPosition >= imgCount-1) {

		currentPosition = 0;

	} else {

		currentPosition ++;

	}

	imgObjDown.src = preloadImg[currentPosition].src;

	setTimeout('hide();', interval);

}





function hideAlarm(inputObj) 

{

	inputObj = $(inputObj);

	if (inputObj.hasClassName('alarm') && (inputObj.value != '')) {

		inputObj.removeClassName('alarm');	

	}

}



function checkForm(formObj) 

{

	fieldsArray = new Array ('customer', 'company', 'street', 'city', 'state', 'zip', 'owners_name', 'phone', 'contact_name', 'email', 'password', 'confirm_password');

	fieldsArrayLen = fieldsArray.length;

	ind = true;

	for (i = 0; i < fieldsArrayLen; i++) {

		inputObj = $(fieldsArray[i]);

		if (inputObj && (inputObj.disabled == false) && (inputObj.value == '')) {

			inputObj.addClassName('alarm');

			ind = false;

		}

	}

	alertString = '';

	if (!ind) {

		alertString += 'The selected fields should not be empty!\n';	

	}

	if (($('password').disabled == false) && $('password').value && ($('password').value.length < 5)) {

		ind = false;

		$('password').addClassName('alarm');

		$('confirm_password').addClassName('alarm');

		alertString += 'Password must have 5 characters at least!\n';	

	}

	if (($('password').disabled == false) && $('password').value != $('confirm_password').value) {

		ind = false;

		$('password').addClassName('alarm');

		$('confirm_password').addClassName('alarm');

		alertString += 'Password must be equal!';

	}

	if (!ind) {

		alert(alertString);

	}

	return (ind ? true : false);

//	var re = /^\w+([\.-]?\w+)*@(((([a-z0-9]{2,})|([a-z0-9][-][a-z0-9]+))[\.][a-z0-9])|([a-z0-9]+[-]?))+[a-z0-9]+\.([a-z]{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|ru|su))$/i;

//	if(!re.))

}



function checkMiniForm()

{

	ind = true;

	alertString = '';

	if ($('email_mini').value == '' || $('email_mini').value == 'customer email') {

		alertString += "'Customer email' field must be filled\n";

		ind = false;

	}

	if ($('password_mini').value == '') {

		alertString += "'Password' field must be filled";

		ind = false;	

	}

	if (ind == false) {

		alert(alertString);

	}

	return ind;

}



function miniLoginEmail(action, inputObj)

{

	if ((action == 'focus') && ($(inputObj).value == 'customer email')) {

		$(inputObj).value = ''; 

		$(inputObj).removeClassName('start-state');

	} else if ((action == 'blur') && ($(inputObj).value == '')) {

		$(inputObj).value = 'customer email'; 

		$(inputObj).addClassName('start-state'); 

	}

}



function miniLoginPassword(action, inputObj)

{

	if (action == 'focus') {

		$(inputObj).hide(); 

		$(inputObj).disable(); 

		$('password_mini').enable(); 

		$('password_mini').show(); 

		$('password_mini').focus();

	} else if ((action == 'blur') && ($(inputObj).value == '')) {

		$(inputObj).hide(); 

		$(inputObj).disable(); 

		$('pseudo-password_mini').enable(); 

		$('pseudo-password_mini').show(); 

	}

}



function changeECPPassword(inputObj)

{

	if ($(inputObj).checked) {

		$('password').disabled = false;

		$('password').up('td').previous('th').removeClassName('disabled');

		$('confirm_password').disabled = false;

		$('confirm_password').up('td').previous('th').removeClassName('disabled');

	} else {

		$('password').disabled = true;

		$('password').up('td').previous('th').addClassName('disabled');

		$('confirm_password').disabled = true;

		$('confirm_password').up('td').previous('th').addClassName('disabled');

	}

}
