//window.attachEvent("onload", fixPNG);
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)){
window.attachEvent("onload", correctPNG);
}

function correctPNG()
{
    if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)){
    for(var i=0; i<document.images.length; i++)
    {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
       // alert('OK')
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle       
            var strNewHTML = "<span " + imgID + imgClass + imgTitle                + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"                + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i-1
        }
    }
    }
}


function addtoFav(){
	window.external.AddFavorite('http://www.francom.ru', 'Интернет-магазин офисной мебели Франком');
}

function submitSearchform(){
	 re = / /g;
	if (document.all('searchText').value=="" || document.all('searchText').value.replace(re,'')=="")
	 	return false;
	else
		return true;
}

function submitLoginform(){
	 re = / /g;
	if (document.all('frmlogin').value=="" || document.all('frmlogin').value.replace(re,'')=="" || document.all('frmpass').value=="" || document.all('frmpass').value.replace(re,'')=="")
		return false;
	else
		return true;
}

function toRegistration(){
	if (opener.window.name=='Item'){
		opener.window.opener.location.href='/pages/registration.php'
	}
	else
		opener.window.location.href='/pages/registration.php'
}

function showImage(id,fld,alt){
	a=window.open('/pages/showImage.php?id='+id+'&fld='+fld+'&alt='+alt,'Image',"height=600,width=500,status=no,toolbar=no,menubar=no,location=no,left=50,top=50");
}

function defineval(obj){
if (!isNaN(obj.value)){
if (obj.name=='usd'){
	document.all('rur').value=roundval(obj.value*(new Number(document.all('rur_usd').value)),2)
	document.all('eur').value=roundval(obj.value*document.all('rur_usd').value/document.all('rur_eur').value,2)
}
if (obj.name=='rur'){
	document.all('usd').value=roundval(obj.value/document.all('rur_usd').value,2)
	document.all('eur').value=roundval(obj.value/document.all('rur_eur').value,2)
}
if (obj.name=='eur'){
	document.all('rur').value=roundval(obj.value*(new Number(document.all('rur_eur').value)),2)
	document.all('usd').value=roundval(obj.value/document.all('rur_usd').value*document.all('rur_eur').value,2)
}
}
}

function validate(key,obj){
	//alert(key)
if (!((key>47&&key<58)||(key>95&&key<106) || (key==8)))
return false
else{

	if(key>95){
	key=key-48
	}
	if (key==8 && obj.value.length>0){
		//alert(key)
	//	alert(obj.value.substring(0,obj.value.length-2))
		obj.value=obj.value.substring(0,obj.value.length-1)
		defineval(obj)
	}
	else{
		obj.value=obj.value+String.fromCharCode(key)
		defineval(obj)
	}
return false
}
}

function showItem(id){
		a=window.open('/pages/Item.php?add&id='+id,'Item',"height=600,width=400,status=no,toolbar=no,menubar=no,location=no");
}

function showItemK(id){
		a=window.open('/pages/ItemK.php?add&id='+id,'Item',"height=600,width=400,scroolbars=yes,status=no,toolbar=no,menubar=no,location=no, scrollbars=yes");
}


function addToBusket(id,color){
alert('--')
	a=window.open('/pages/busket.php?add&id='+id+'&count='+document.all('count'+id).value+'&color='+color,'Busket',"height=600,width=780,status=no,toolbar=no,menubar=no,location=no");
}

function addToBusket(id,color,add_color){
	a=window.open('/pages/busket.php?add&id='+id+'&count='+document.all('count'+id).value+'&color='+color+'&add_color='+add_color,'Busket',"height=600,width=780,status=no,toolbar=no,menubar=no,location=no");
}

function showBusket(){
	a=window.open('/pages/busket.php','Busket',"height=600,width=780,status=no,toolbar=no,menubar=no,location=no");
}

function change_color_value(obj){
	document.all.color_val.value=obj.value
}

function change_color_der_value(obj){
	document.all.color_der_val.value=obj.value
}


function validateRegForm() {

	flag=true;
	if (validate_english_text("login","Логин")!=''){
		document.all.TDLogin.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
	}
	else
		document.all.TDLogin.innerHTML='';
	if (validate_english_text("pass","Логин")!=''){
		document.all.TDPass.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
	}
	else
		document.all.TDPass.innerHTML='';
	
	if (validate_confirm("pass###pass1","Логин")!=''){
		document.all.TDPass1.innerHTML='<BR><SPAN class="warning">Пароли не совпадают</SPAN>';
		flag=false
	}
	else
		document.all.TDPass1.innerHTML='';
		
	if (validate_text("name","Логин")!=''){
		document.all.TDName.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
	}
	else
		document.all.TDName.innerHTML='';
		
	flag1=true
	if (validate_text("email","Логин")!=''){
		document.all.TDEmail.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
		flag1=false
	}
	if (validate_email("email","Логин")!=''){
		document.all.TDEmail.innerHTML='<BR><SPAN class="warning">Неверный адрес электронной почты</SPAN>';
		flag=false
		flag1=false
	}
	if (flag1)
		document.all.TDEmail.innerHTML='';
	re1 =  /^\+\d+ \(\d+\) (\d)+$/;
	if (validate_text("phone","Логин")!=''){
		document.all.TDPhone.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
	}
	else
	if (validate_pattern("phone","Логин",re1)!=''){
		document.all.TDPhone.innerHTML='<BR><SPAN class="warning">Неверный телефонный номер</SPAN>';
		flag=false
	}
	else
		document.all.TDEmail.innerHTML='';
	//+validate_text("pass","Пароль")+validate_confirm("pass###pass1","Пароли не совпадают")+validate_text("name","Контактное лицо")+validate_email("email","Адрес электронной почты")+validate_text("email","Адрес электронной почты")+validate_text("phone","Телефон");
	if  (flag)
		document.all.form1.submit()
}

function validateCataologForm() { 
	
	flag=true;
		
	if (validate_text("name","Логин")!=''){
		document.all.TDName.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
	}
	else
		document.all.TDName.innerHTML='';
		
	if (validate_text("company","Логин")!=''){
		document.all.TDCompany.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
	}
	else
		document.all.TDCompany.innerHTML='';
		
	if (validate_text("index","Логин")!=''){
		document.all.TDIndex.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
	}
	else
		document.all.TDIndex.innerHTML='';
		
	if (validate_text("adress","Логин")!=''){
		document.all.TDAdress.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
	}
	else
		document.all.TDAdress.innerHTML='';
	flag1=true
	if (validate_text("email","Логин")!=''){
		document.all.TDEmail.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
		flag1=false
	}
	if (validate_email("email","Логин")!=''){
		document.all.TDEmail.innerHTML='<BR><SPAN class="warning">Неверный адрес электронной почты</SPAN>';
		flag=false
		flag1=false
	}
	if (flag1)
		document.all.TDEmail.innerHTML='';
	re1 =  /^\+\d+ \(\d+\) (\d)+$/;
	if (validate_text("phone","Логин")!=''){
		document.all.TDPhone.innerHTML='<BR><SPAN class="warning">Поле обязательно для заполения</SPAN>';
		flag=false
	}
	else
	if (validate_pattern("phone","Логин",re1)!=''){
		document.all.TDPhone.innerHTML='<BR><SPAN class="warning">Неверный телефонный номер</SPAN>';
		flag=false
	}
	else
		document.all.TDEmail.innerHTML='';


	if  (flag)
		document.all.form1.submit()
}

function validate_text(name,string){
	 re = / /g;
	var msg
	msg=''
	 if (document.all(name).value=="" || document.all(name).value.replace(re,'')=="")
	    msg+="- "+string+"\n"
	 return msg
}

function validate_english_text(name,string){
	re = /([a-z]+[0-9]*[_]*)/g;
	var msg
	msg=''
    if (document.all(name).value=="" || document.all(name).value.replace(re,'')!="")
	    msg+="- "+string+"\n"
	 return msg
}

function validate_email(name,string){
	re = / /g;
	var msg
	msg=''
	 if ((document.all(name).value!="") && (document.all(name).value.indexOf("@",1)==-1 || document.all(name).value.indexOf(".",3)==-1))
	    msg+="- "+string+"\n"
	 return msg
}

function validate_confirm(name,string){
	 re = / /g;
	var msg
	arr= name.split("###")
	msg=''
	if (document.all(arr[0]).value!=document.all(arr[1]).value)
	   msg+="- "+string+"\n"
	return msg
}

function validate_pattern(name,string,pattern){
	var msg
	msg=''
	if (document.all(name).value.replace(pattern,'')!="")
	  msg+="- "+string+"\n"
	 return msg
}
function submitForgonForm(){
	 re = / /g;
	if ((document.all.login.value!="" && document.all.login.value.replace(re,'')!="") || (document.all.email.value!="" && document.all.email.value.replace(re,'')!=""))
		document.all.forgotForm.submit()
}


function show(name){
	//status=event.srcElement.name
	el=event.srcElement.parentElement
	document.all(name).style.display="block"
	document.all(name).style.pixelTop=get_Y(el)+el.clientHeight-1
	document.all(name).style.pixelLeft=get_X(el)-20
	document.all(name).style.width=150
	event.cancelBubble =true
}

function hide(name){
	x=event.x
	y=event.y
	if (document.all(name).contains(document.elementFromPoint(x,y))==false && document.elementFromPoint(x,y).id!='popmenu')
		document.all(name).style.display="none"
	//else
		//oInterval = window.setInterval("hide1()",1000);
	
}


function get_Y(el){
X=0
X=X+el.offsetTop
if (el.offsetParent!=null){
	X=X+get_Y(el.offsetParent)
}
return X
}

function get_X(el){
X=0
X=X+el.offsetLeft
if (el.offsetParent!=null){
	X=X+get_X(el.offsetParent)
}
return X
}