/** 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');
	
	/*Without Prototype
	imgObjUp	= document.getElementById('rotateUp');
	imgObjDown	= document.getElementById('rotateDown');*/
	$('rt_0').addClassName('dots_sele');
    $('rotateUp').title=img_alt[0];	
	/*imgObjUp.src	= preloadImg[currentPosition].src;
	currentPosition	++;
	imgObjDown.src	= preloadImg[currentPosition].src;
	currentPosition ++;*/
	if(stop_img)
	{
	setTimeout('hide();', img_range[0]);
	}
}

function hide()
{

	if(stop_img)
	{
		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()
{

	if(currentPosition >= imgCount-1) {
		$('rt_'+currentPosition).removeClassName('dots_sele'); 
		currentPosition = 0;
		$('rt_'+currentPosition).addClassName('dots_sele');
		if(img_link[currentPosition]!=false)
		{
			$('link_box').href=img_link[currentPosition];
		}
		else
		{
			$('link_box').removeAttribute("href");
		}
			if(img_alt[currentPosition]!=false)
			{
				$('rotateUp').alt=img_alt[currentPosition];
                $('rotateUp').title=img_alt[currentPosition];
			}
			else
			{
					$('rotateUp').alt="";
                    $('rotateUp').title="";
			}
				if(link_type[currentPosition]!='0')
				{
					$('link_box').target='_blank';
				}
				else
				{
					$('link_box').target='_self';
				}
	} else {
		$('rt_0').removeClassName('dots_sele'); 
		$('rt_'+currentPosition).removeClassName('dots_sele'); 	
		currentPosition ++;
		$('rt_'+currentPosition).addClassName('dots_sele'); 
		if(img_link[currentPosition]!=false)
		{
			$('link_box').href=img_link[currentPosition];
		}
		else
		{	
			$('link_box').removeAttribute("href");
		}
			if(img_alt[currentPosition]!=false)
			{
				$('rotateUp').alt=img_alt[currentPosition];
                $('rotateUp').title=img_alt[currentPosition];
			}
			else
			{
					$('rotateUp').alt="";
                    $('rotateUp').title="";
			}
				if(link_type[currentPosition]!='0')
				{	
					$('link_box').target='_blank';	
				}
				else
				{
					$('link_box').target='_self';		
				}
		//alert(img_alt[currentPosition]);
		
	}
	//imgObjUp.src = imgObjDown.src;
	imgObjUp.src = preloadImg[currentPosition].src;
	
	if (navigator.appName != 'Microsoft Internet Explorer') {
		imgObjUp.style.opacity = currentOpacity * 0.1;
	} else {
		imgObjUp.style.filter = '.' + currentOpacity * 10 + ')';
	}
	if(stop_img)
	{	
	setTimeout('hide();', img_range[currentPosition]);
	}

}
function replaceImg_forcely(val)
{
		
		$('rt_'+val).addClassName('dots_sele');
		imgObjUp.src = preloadImg[val].src;
		if (navigator.appName != 'Microsoft Internet Explorer') {				
				imgObjUp.style.opacity = 10;
			} else {
				imgObjUp.style.filter = 10;
			}
		
		if(link_type[val]!='0')
		{				
			$('link_box').target='_blank';	
		}
		else
		{
			$('link_box').target='_self';		
		}
			if(img_alt[val]!=false)
			{
				$('rotateUp').alt=img_alt[val];
                $('rotateUp').title=img_alt[val];
			}
			else
			{
					$('rotateUp').alt="";
                    $('rotateUp').title="";
			}
				if(img_link[val]!=false)
				{
					$('link_box').href=img_link[val];
				}
				else
				{
					$('link_box').removeAttribute("href");
				}
		if(posti_sele!="-1")
		{
			$('rt_'+posti_sele).removeClassName('dots_sele'); 	
		}
		else
		{
				if(val!=currentPosition)
					$('rt_'+currentPosition).removeClassName('dots_sele');
		}
		posti_sele=val;
		stop_img=false;
		
		
}


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 == 'email') {
		alertString += "'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 == 'EMAIL')) {
		$(inputObj).value = ''; 
		$(inputObj).addClassName('active');
	} else if ((action == 'blur') && ($(inputObj).value == '')) {
		$(inputObj).value = 'EMAIL'; 
		$(inputObj).removeClassName('active'); 
	}
}

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');
	}
}
function changevendorPassword(inputObj)
{
	if($(inputObj).checked == true) {

		$('vendor_password').disabled = false;

		$('vendor_confirm_password').disabled = false;

	} else {

		$('vendor_password').removeClassName('alarm');

		$('vendor_confirm_password').removeClassName('alarm');

		$('vendor_password').disabled = true;

		$('vendor_confirm_password').disabled = true;

	}

}
function showRenameFolderForm (idPostfix)

{

	$('rename_folder_form_' + idPostfix).enable();

	$('rename_folder_form_' + idPostfix).show(); 

	$('rename_folder_form_' + idPostfix).previous('span').hide();

}
function hideRenameFolderForm (idPostfix)

{

	$('rename_folder_form_' + idPostfix).disable();

	$('rename_folder_form_' + idPostfix).hide(); 

	$('rename_folder_form_' + idPostfix).reset();

	$('rename_folder_form_' + idPostfix).previous('span').show();

}
function openHelp(page, rootDir) 

{

	window.open(rootDir + '/admin/help/' + page + '.html', 'help_window', 'alwaysRaised,height=400,width=600,location=no,menubar=no,personalbar=no,toolbar=no,status=no,scrollbars=yes');

	return false;

}
