function ViewForgotDiv()
{
	el = document.getElementById('divforgot');
	if (el.style.display == 'none')
		el.style.display  = "block";
	else	
		el.style.display  = "none";

}

function ChangeLang()
{
	document.changeLang.submit();
}

function MakeOn(url)
{
//	var expand = document.getElementById('expand');
//	url = url+"&expand="+expand.value;
	location.href=url;
}

function DopImg()
{
        targetId="dopimg";
        targetElement = document.getElementById(targetId);
	if (targetElement.style.display == "none")
	        targetElement.style.display= "";
	else targetElement.style.display = "none";
	location.href = "#dopimg";
}

function open_window(url)
{
	cwin = window.open(url,"attach","width=350,height=400,toolbar=no,resizable=yes");
}

function ViewResume(id)
{
	var targetId = "res"+id;
	var buf = document.getElementById(targetId);
	if (buf.style.visibility == "")
	{
		buf.style.visibility = "hidden";
		buf.style.display = "none";		
	}
	else 
	{
		buf.style.visibility = "";
		buf.style.display = "";		
	}
}

var done = 0;
function Upload(id, module)
{
	document.getElementById('bs').disabled = true;
	document.getElementById('br').disabled = true;
	document.getElementById('info_'+id).innerHTML = "Loading...";
	done = 1;
	var upl = document.getElementById(id);
	setTimeout('checkUpload(\''+id+'\')', 1000);
	JsHttpRequest.query('include/upload.php',{upl: upl, module: module}, 
	function(result, errors) {UploadDone(result, id);}, true);
	return false;
}

function UploadDone(result, id)
{
	done = 0;
	var temp = new Array();
	temp = result.split('#');
	var res = document.getElementById('info_'+id);
	if (temp[0] == "-2")
	{
		alert('Файл с таким именем уже существует на сервере! Будет подключен существующий');	
		res.innerHTML = 'Файл с таким именем уже существует на сервере! Будет подключен существующий';
		document.getElementById('hidden_'+id).value = temp[1];		
	}
	else if (temp[0] == "-1")
	{
		alert('При загрузке файла на сервер возникла ошибка! Попробуйте еще раз!');	
		res.innerHTML = 'При загрузке файла на сервер возникла ошибка! Попробуйте еще раз!';
	}
	else
	{	
		document.getElementById('hidden_'+id).value = temp[1];		
		res.innerHTML = 'Файл успешно загружен!';
	}
	document.getElementById('bs').disabled = false;
	document.getElementById('br').disabled = false;	
}

function checkUpload(id)
{
	JsHttpRequest.query('include/checkUpload.php',{}, 
	function(result, errors) {checkUploadDone(result, id);}, true);
	return false;
}

function checkUploadDone(result, id)
{
	if (done == 1)
	{
		document.getElementById('info_'+id).innerHTML = result;	
		setTimeout('checkUpload(\''+id+'\')', 2000);
	}
}

function clearFile()
{
//	var f = document.forms[0] 
	var f = document.getElementById('form1');
	for (var i=0;i<f.elements.length; i++) 
	{ 		
		if (f.elements[i].type == "file")
		{
			var temp = new Array();
			temp = f.elements[i].name.split('_');
			if (temp[0] == "file")
				f.elements[i].disabled = true;				
		}
	}
}

function set_visible(id,show)
{
	var buf = document.getElementById(id);
	if (!buf) return;
	if (show)
	{
		buf.style.visibility = "";
		buf.style.display = "";		
	}
	else 
	{
		buf.style.visibility = "hidden";
		buf.style.display = "none";		
	}
}

function set_visibleSelf(id)
{
	var buf = document.getElementById(id);
	if (!buf) return;
	if (buf.style.display == "none")
	{
		buf.style.visibility = "";
		buf.style.display = "";		
	}
	else 
	{
		buf.style.visibility = "hidden";
		buf.style.display = "none";		
	}
}

function set_html(id,text)
{
	var buf = document.getElementById(id);
	if (buf) buf.innerHTML = text;
}

function set_src(id,src)
{
	var buf = document.getElementById(id);
	if (buf) buf.src = src;
}

function set_href(id,href)
{
	var buf = document.getElementById(id);
	if (buf) buf.href = href;
}

function set_value(id,value)
{
	var buf = document.getElementById(id);
	if (buf) buf.value = value;
}

function get_value(id)
{
	var buf = document.getElementById(id);
	if (buf) return buf.value;
	return false;
}

function swap(id)
{
	pic	= document.getElementById(id);
	if (pic.style.display)
	{
		pic.style.visibility = "";
		pic.style.display = "";		
	}
	else 
	{
		pic.style.visibility = "hidden";
		pic.style.display = "none";		
	}
}

function update_type(result)
{
	if (!result) return;
	set_html('types',result['types']);
}

function select_type(id)
{
	JsHttpRequest.query(
		'/include/core/ajax_file.php',
		{id:id,action:'insert'},
		function(result, errors) {update_type(result);},
		true);
}

function  changeDesc(id, oid)
{
	var buf = document.getElementById(id);
	var desc = document.getElementById('description_'+oid);	
	desc.innerHTML = buf.innerHTML;
	
	var buf = document.getElementById('li_fck_body_'+oid);
	if (buf)
	{
		buf.style.background = "none";
		buf.style.border = "none";
		buf.style.borderBottom = "1px solid #dbc7a1";	
	}
	var buf = document.getElementById('a_fck_body_'+oid);
	if (buf)
	{	
		buf.style.fontWeight = "normal";
		buf.style.textDecoration = "underline";
	}
	var buf = document.getElementById('li_fck_body2_'+oid);
	if (buf)
	{	
		buf.style.background = "none";
		buf.style.border = "none";
		buf.style.borderBottom = "1px solid #dbc7a1";	
	}
	var buf = document.getElementById('a_fck_body2_'+oid);
	if (buf)
	{
		buf.style.fontWeight = "normal";
		buf.style.textDecoration = "underline";
	}
	var buf = document.getElementById('li_fck_body3_'+oid);
	if (buf)
	{	
		buf.style.background = "none";
		buf.style.border = "none";
		buf.style.borderBottom = "1px solid #dbc7a1";	
	}
	var buf = document.getElementById('a_fck_body3_'+oid);
	if (buf)
	{
		buf.style.fontWeight = "normal";
		buf.style.textDecoration = "underline";
	}
	var buf = document.getElementById('li_'+id);
	if (buf)
	{
		buf.style.background = "#f7efe0";
		buf.style.border = "1px solid #dbc7a1";
		buf.style.borderBottom = "none";
	}
	var buf = document.getElementById('a_'+id);
	if (buf)
	{
		buf.style.fontWeight = "bold";
		buf.style.textDecoration = "none";
	}
}

function addInCart(id)
{	
	var qty = document.getElementById('quantity_'+id);
	if (qty)
		qty = qty.value;
	else qty = 1;
	if (qty > 0)
	{
		JsHttpRequest.query('/ajax/addInCart.php', {id:id,qty:qty},
		function(result, errors) {addInCartDone(result);},
		true);	
	}
}

function addInCartDone(result)
{
	if (result['count'] > 0)
	{
		var str = result['count']+' item total $'+result['price'];		
		var cart_info = document.getElementById('cart_info');
		cart_info.innerHTML = str;
		alert('Thank you\nYour product has been added to your shopping bag.');
	}	
}

function change2()
{
	var shipping_firstname = document.getElementById('shipping_firstname');
	var shipping_phone = document.getElementById('shipping_phone');
	var shipping_lastname = document.getElementById('shipping_lastname');
	var shipping_email = document.getElementById('shipping_email');
	var shipping_address = document.getElementById('shipping_address');
	var shipping_city = document.getElementById('shipping_city');
	var shipping_state = document.getElementById('shipping_state');
	var shipping_zip = document.getElementById('shipping_zip');

	var billing_firstname = document.getElementById('billing_firstname');
	var billing_phone = document.getElementById('billing_phone');
	var billing_lastname = document.getElementById('billing_lastname');
	var billing_email = document.getElementById('billing_email');
	var billing_address = document.getElementById('billing_address');
	var billing_city = document.getElementById('billing_city');
	var billing_state = document.getElementById('billing_state');
	var billing_zip = document.getElementById('billing_zip');
	
	shipping_firstname.value = billing_firstname.value;
	shipping_phone.value = billing_phone.value;
	shipping_lastname.value = billing_lastname.value;
	shipping_email.value = billing_email.value;
	shipping_address.value = billing_address.value;
	shipping_city.value = billing_city.value;
	shipping_state.value = billing_state.value;
	shipping_zip.value = billing_zip.value;
}

function change1()
{
	var shipping_firstname = document.getElementById('shipping_firstname');
	var shipping_phone = document.getElementById('shipping_phone');
	var shipping_lastname = document.getElementById('shipping_lastname');
	var shipping_email = document.getElementById('shipping_email');
	var shipping_address = document.getElementById('shipping_address');
	var shipping_city = document.getElementById('shipping_city');
	var shipping_state = document.getElementById('shipping_state');
	var shipping_zip = document.getElementById('shipping_zip');
	
	shipping_firstname.value = "";
	shipping_phone.value = "";
	shipping_lastname.value = "";
	shipping_email.value = "";
	shipping_address.value = "";
	shipping_city.value = "";
	shipping_state.value = "";
	shipping_zip.value = "";
}
