function clearInput(obj) {
	if(obj.value == "1") {
		obj.value = "";
	}
}

if(navigator.appName == 'Netscape') {
	document.write('<style> div.mmlist { width: 150px; } </style>');
}

function PasswordFieldChange(obj,utyped) {
	/*if((utyped == 'password') && (obj.value == 'Password')) {
		obj.value='';
		obj.type=utyped;
	}

	if((utyped == 'text') && (obj.value == '')) {
		obj.value='Password';
		obj.type=utyped;
	} */

	if(utyped == 'password') {
		obj.className='field_blank';
		obj.style.backgroundImage='none';
	} else {
		if(obj.value.length == 0) {
			obj.className='passwd_password';
			obj.style.backgroundImage='url("'+passwordBG+'")';
		}
	}

	return true;
}


function LoginFieldChange(obj,utyped) {
	/*if((utyped == 'password') && (obj.value == 'Password')) {
		obj.value='';
		obj.type=utyped;
	}

	if((utyped == 'text') && (obj.value == '')) {
		obj.value='Password';
		obj.type=utyped;
	} */

	if(utyped == 'login') {
		obj.className='field_blank';
		obj.style.backgroundImage='none';
	} else {
		if(obj.value.length == 0) {
			obj.className='lggn_password';
			obj.style.backgroundImage='url("'+loginBG+'")';
		}
	}

	return true;
}

/*
function LoginFieldChange(obj,act) {
	if((act == 'hide') && (obj.value == 'Login'))
		obj.value='';
	else
		if((act == 'show') && (obj.value.length == 0))
			obj.value='Login';

	return true;
}*/

function SearchFieldChange(obj,act) {
	if((act == 'hide') && (obj.value == searchTip))
		obj.value='';
	else
		if((act == 'show') && (obj.value.length == 0))
			obj.value=searchTip;

	return true;
}

function CheckValidLoginForm(obj) {
	var login = true;
	var password = true;
	if(obj.login.value == 'Login')
		login=false;

	if(obj.password.value == 'Password')
		password=false;

	if(password && login)
		return true;
	else {
		alert('enter username and password');
		return false;
	}
}

var lastOpenedId='0';
var hlited=false;
var currentOpenedId='0';

function getElementTop(obj) {
	var ret_val = 0;
	ret_val = obj.offsetTop;
	objHTMLelement = obj.offsetParent;
	while (objHTMLelement != null) {
		ret_val += objHTMLelement.offsetTop;
		objHTMLelement = objHTMLelement.offsetParent;
	}
	return ret_val;
}

function getElementLeft(obj) {
	var ret_val = 0;
	ret_val = obj.offsetLeft;
	objHTMLelement = obj.offsetParent;
	while (objHTMLelement != null) {
		ret_val += objHTMLelement.offsetLeft;
		objHTMLelement = objHTMLelement.offsetParent;
	}
	return ret_val;
}

function get_father_id(id) {
	fid="";
	m=0;
	while(id[m] != "i") {
		fid+=id[m];
		m++;
	}
	return fid;
}

function getIdFromName(n_name) {
	n_id="";
	i=0;

	while(n_name[i] != ":") {
		n_id+=n_name[i];
		i++;
	}

	if(n_name[(i+1)] == "h")
		n_id+="i0";
		// если планируется переход в айтем, но не в хэндлер

	return n_id;
}

function getTypeFromName(n) {
	n_type="";
	i=0;

	while(n[i] != ":")
		i++;

	for(k=(i+1);k<n.length;k++)
		n_type+=n[k];

	return n_type;
}
/*
function hideHandlers(current_id) {
	current_name=document.getElementById(current_id).name;
	alert(current_name);
	if(current_name != "top_level") {
		next_id=getIdFromName(current_name);
		next_type=getTypeFromName(current_name);
		if(next_type == "handle") {
			document.getElementById(next_id).style.display="none";
		}
		hideHandlers(next_id);
	}
}

function hideMenus() {
	hideHandlers("m16i0");
}
*/
function draw_submenu(obj,id,leftOffset) {
	hide_last_submenu();
	lastOpenedId=id;
	subm=document.getElementById(id);
	subm.style.left=getElementLeft(obj)+leftOffset;
	subm.style.top=getElementTop(obj)+23;
	subm.style.display='block';
}

function hide_last_submenu() {
	//subm.document.getElementById(obj.id);
/*	var idToClose=currentOpenedId;
	while(document.getElementById(idToClose).name != "top_level") {
		document.getElementById(idToClose).style.display='none';
		idToClose=document.getElementById(idToClose).name;
	}*/
	if((lastOpenedId != '0') && (!hlited))
		document.getElementById(lastOpenedId).style.display='none';
}

function subm_h(obj) {
	hlited=true;
	obj.className='list_h';
	currentOpenedId=obj.id;
	document.getElementById(obj.id+'l').className='list_l_h';
	document.getElementById(obj.id+'r').className='list_r_h';
}
function subm_n(obj) {
	hlited=false;

	//if(lastOpenedId != obj.id)
	//	hide_last_submenu();

	//setTimeout('hide_last_submenu()',2000);
	obj.className='list';
	document.getElementById(obj.id+'l').className='list_l';
	document.getElementById(obj.id+'r').className='list_r';
}

function SearchChangeColor(obj) {
	if(obj.value == "0")
		document.getElementById("search_color").style.background='none';
	else
		if(obj.value == "assorti")
			document.getElementById("search_color").style.background='#ffffff url(\'./img/colorspecial_assorti.jpg\') no-repeat center center scroll';
		else
			document.getElementById("search_color").style.background='#'+obj.value+' url(\'./img/transparent.gif\') no-repeat center center scroll';
}


function HighlightCell(id) {
	document.getElementById(id).style.backgroundColor='#ffcccc';
}
function CheckValidRegisterForm(obj) {
	errors_exists = false;
	/*
	if(obj.register_cperson_login.value.length < 1) {
		document.getElementById("register_cperson_login").style.backgroundColor='#ffcccc';
		errors_exists = true;
	}
	if(obj.register_infbusiness_title.value.length < 1) {
		document.getElementById("register_infbusiness_title").style.backgroundColor='#ffcccc';
		errors_exists = true;
	}
	if(obj.register_cperson_namesurname.value.length < 1) {
		document.getElementById("register_cperson_namesurname").style.backgroundColor='#ffcccc';
		errors_exists = true;
	}
	if(obj.register_cperson_phone.value.length < 1) {
		document.getElementById("register_cperson_phone").style.backgroundColor='#ffcccc';
		errors_exists = true;
	}
	if(obj.register_cperson_fax.value.length < 1) {
		document.getElementById("register_cperson_fax").style.backgroundColor='#ffcccc';
		errors_exists = true;
	}
	if(obj.register_cperson_email.value.length < 1) {
		document.getElementById("register_cperson_email").style.backgroundColor='#ffcccc';
		errors_exists = true;
	}
	if(obj.register_cperson_login.value.length < 1) {
		document.getElementById("register_cperson_login").style.backgroundColor='#ffcccc';
		errors_exists = true;
	}
	if(obj.register_cperson_password.value.length < 1) {
		document.getElementById("register_cperson_password").style.backgroundColor='#ffcccc';
		errors_exists = true;
	}
	if(obj.register_cperson_password_a.value.length < 1) {
		document.getElementById("register_cperson_password_a").style.backgroundColor='#ffcccc';
		errors_exists = true;
	}
	if(obj.register_cperson_password_a.value != obj.register_cperson_password.value) {
		document.getElementById("register_cperson_password_a").style.backgroundColor='#ffcccc';
		document.getElementById("register_cperson_password").style.backgroundColor='#ffcccc';
		errors_exists = true;
	} */

	if(errors_exists) {
		return false;
	} else {
		obj.submit();
		return true;
	}
}

function cleanForm(obj) {
	for(i=0;i<obj.elements.length;i++) {
		clname=document.getElementById(obj.elements[i].name).className;
		if(clname.substring(clname.length-2,clname.length) == '_h') {
			document.getElementById(obj.elements[i].name).style.backgroundColor="#F0FAFB";
		} else {
			document.getElementById(obj.elements[i].name).style.backgroundColor="#FAFEFD";
		}
		obj.elements[i].value='';
	}
	return true;
}

function make_corner(id) {
	document.getElementById("m_ind_"+id).className="vmenu_1_indent_l";
	document.getElementById("m_it_"+id).className="vmenu_1_l";
}

function ow_zoom(url){
	if(!url)
		return false;

	w = 830;
	h = 800;
	l = ( screen.width - w )/2;
	t = ( screen.height - h )/2;

	window.open( url, "_blank", "toolbar=0,scrollbars=1,resizable=1,left="+l+",top="+t+",width="+w+",height="+h );
}

function ow(url){
	if(!url)
		return false;

	w = 600;
	h = 550;
	l = ( screen.width - w )/2;
	t = ( screen.height - h )/2;

	window.open( url, "_blank", "toolbar=0,scrollbars=1,resizable=1,left="+l+",top="+t+",width="+w+",height="+h );
}

function ow_pass(url){
	if(!url)
		return false;

	w = 400;
	h = 200;
	l = ( screen.width - w )/2;
	t = ( screen.height - h )/2;

	window.open( url, "_blank", "toolbar=0,scrollbars=1,resizable=1,left="+l+",top="+t+",width="+w+",height="+h );
}

function showHideColorTable() {
	if(document.getElementById("color_table").style.display == 'block') {
		document.getElementById("color_table").style.display = 'none';
	} else {
		document.getElementById("color_table").style.display = 'block';
	}
	return true;
}

function changeColorSelection(color_id) {
	if(color_id == "assorti")
		document.getElementById("search_color").style.background='#ffffff url(\'./img/colorspecial_assorti.jpg\') no-repeat center center scroll';
	else
		document.getElementById("search_color").style.background='#'+color_id+' url(\'./img/transparent.gif\') no-repeat center center scroll';

	document.getElementById("color_id").value=color_id;
}

function alert_must_log_in() {
	ow_pass('./pop_must_login.php');
	return false;
}

function faq_showhide(id) {
	if(document.getElementById(id).style.display == 'block') {
		document.getElementById(id).style.display = 'none';
	} else {
		document.getElementById(id).style.display = 'block';
	}
	return true;
}

function showMenu(obj_id,obj) {
	subm=document.getElementById(obj_id);

	if(obj.tagName == "A") {
		subm.style.left=getElementLeft(obj);
		subm.style.top=getElementTop(obj)+23;
		subm.style.marginLeft='0px';
	} else {
		subm.style.top=getElementTop(obj)-140;
	}

	subm.style.display='block';
}
function hideMenu(obj) {
	setTimeout('document.getElementById("' + obj.id + '").style.display=\'none\';',5000);
	//obj.style.display='none';
}

function hideAllMenus() {
	divs=document.getElementsByTagName("div");
	for(i=0;i<divs.length;i++) {
		if(divs[i].id[0] == "m") {
			divs[i].style.display="none";
		}
	}
}



function show_menu(srcTag)
{
	inTag = srcTag.getElementsByTagName('div')[0];
	if(inTag)
		inTag.style.display = 'block';
}

function hide_menu(srcTag)
{
	inTag = srcTag.getElementsByTagName('div')[0];
	if(inTag)
		inTag.style.display = 'none';
}

function AlertIfNotEnough(Amount, StockRest, Message)
{
	if(Amount > StockRest)
	{
		return confirm(Message);
	}
	return true;
}















function ConfirmIfOverLimit(Sum, LimitLeft)
{
	if(Sum > LimitLeft)
	{
		if(!confirm('Jūsu pasūtījuma summa (' + Sum + ') ir virs jūsu mēnešlimita atlikumu (' + LimitLeft + '), vai turpināt ar šo pasūtījumu?'))
			return false;
	}
	
	document.forms.editcart.subaction.value='send';
	document.forms.editcart.submit();
}

var ZoomCurrObj = null;
function setzoomimg(PCode, ImageObj)
{
	if(ZoomCurrObj)
		ZoomCurrObj.style.borderColor = '#909790';
	
	ZoomCurrObj = ImageObj;
	
	ImageObj.style.borderColor = '#5C9FD6';
	
	document.getElementById('imgplaceholder').src = '/data/xlarge/xlarge_' + PCode + '.jpg';
}
