var browser={isKHTML: false, isGecko: false, isIE: false, isIE5: false, isOpera: false, isSafe:null};
with (browser) {
	isKHTML = navigator.userAgent.indexOf("KHTML")>=0;
	isGecko = (!isKHTML) && navigator.product == "Gecko";
	isIE = (!isGecko) && navigator.cpuClass != undefined && navigator.appName == "Microsoft Internet Explorer";
	isIE5 = isIE && (!Function.apply); ifIE55 = isIE && (document.onmousewheel == undefined);
	isOpera = (!(isIE || isGecko || isKHTML)) && document.attachEvent != undefined;
	isSafe = document.getElementById != undefined && (!isIE5) && (document.addEventListener != undefined || document.attachEvent != undefined);
}

if (browser.isIE){
	document.write('<style type="text/css">.ieshadow {background: #000; }</style>');
}

function loadFlash(f,w,h){
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'">');
document.write('<param name="movie" value="'+f+'">');
document.write('<param name="quality" value="high">');
document.write('<embed src="'+f+'" width="'+w+'" height="'+h+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
document.write('</object>');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function CheckEmail(e){
	e = e.toLowerCase();
	var ch="@";
	var count=0;
	var error=false;
	
	for (var i=0; i<e.length; i++){
		if(e.charAt(i)==ch || e.charAt(i)=="."){
			error = (count==0) ? true : error;
			ch = (ch==".") ? 0 : ch;
			ch = (e.charAt(i)=="@") ? "." : ch;
			count=0;
			continue;
		}
		count++;
	
		if((e.charAt(i)<"a" || e.charAt(i)>"z") && (e.charAt(i)<"0" || e.charAt(i)>"9") && e.charAt(i)!="_" && e.charAt(i)!="-"){
			error = true;
			break;
		}
	}
	error = (count==0) ? true : error;
	error = (ch==0) ? error : true;
	return !error;
}

function ShowPhoto(photoname, w, h) {
	url = "/showphoto.php?img="+photoname;

	Win=window.open(url, 'viewPhoto',  'toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,resizable=0,width='+w+',height='+h+',border=thin,top=50,left=50,help=0');
	Win.focus();
}
 
function ShowProduct(productid) {
	url = "http://www.merlion.ru/goods/catalog/product/" + productid + "/";

	Win=window.open(url, productid,  'toolbar=0,scrollbars=1,location=0,directories=0,status=0,menubar=0,resizable=1,width=770,height=500,border=thin,top=50,left=50,help=0');
	Win.focus();
}
 
function WriteUsFormCheck(){
	email = document.WriteUsForm["email"].value;
	name = document.WriteUsForm["name"].value;
	product = document.WriteUsForm["product"].value;
	sn = document.WriteUsForm["sn"].value;
	topic = document.WriteUsForm["topic"].value;
	problemtext = document.WriteUsForm["problemtext"].value;

	if (name != "" && topic != "" && problemtext != "" && sn != "" && product != ""){
		if (CheckEmail(email)){
			document.WriteUsForm.submit();
		}
		else{
			alert('Введите, пожалуйста, корректный e-mail.');
		}
	}
	else{
		alert('Заполнены не все обязательные для заполнения поля!');
	}
}

function JoinUsFormCheck(){
	var b = true;

	email = document.JoinUsForm["email"].value;
	companyName = document.JoinUsForm["companyName"].value;
	country = document.JoinUsForm["country"].value;
	city = document.JoinUsForm["city"].value;
	address = document.JoinUsForm["address"].value;
	phone = document.JoinUsForm["phone"].value;
	www1 = document.JoinUsForm["www1"].value;

	if (document.JoinUsForm["companyProfile1"].checked || document.JoinUsForm["companyProfile2"].checked || document.JoinUsForm["companyProfile3"].checked){}
	else{
		b = false;
	}
	if (companyName != "" && email != "" && country != "" && city != "" && address != ""  && phone != ""  && www1 != "" && b){
		if (CheckEmail(email)){
			document.JoinUsForm.submit();
		}
		else{
			alert('Введите, пожалуйста, корректный e-mail.');
		}
	}
	else{
		alert('Заполнены не все обязательные для заполнения поля!');
	}
}


 function ContactFormCheck(){
	var b = true;

	email = document.ContactForm["email"].value;
	name = document.ContactForm["name"].value;
	topic = document.ContactForm["topic"].value;
	topic = document.ContactForm["topic"].value;
	messagetext = document.ContactForm["messagetext"].value;

	if (name != "" && topic != "" && messagetext != "" && email != ""){
		if (CheckEmail(email)){
			document.ContactForm.submit();
		}
		else{
			alert('Введите, пожалуйста, корректный e-mail.');
		}
	}
	else{
		alert('Заполнены не все обязательные для заполнения поля!');
	}
}


function SubscribeFormCheck(){
	email=document.SubscribeForm["email"].value;
	if (CheckEmail(email)){
		document.SubscribeForm.submit();
	}
	else{
		alert('Введите, пожалуйста, корректный e-mail.');
	}
}

function CopyToClipboard(fldname){
	document.frm[fldname].select();
	var rng = document.selection.createRange();
    clipboardData.setData("Text",rng.text);
}

var DOM = (typeof(document.getElementById) != 'undefined'); 

function SelectAll(Name){
	if (DOM) {
		thisCheckBoxes = document.getElementsByTagName('input');

		for (i = 1; i < thisCheckBoxes.length; i++) {
			if (thisCheckBoxes[i].name == Name){
				thisCheckBoxes[i].checked = true;
			}
		}
	}
}

function UnSelectAll(Name){
	if (DOM) {
		thisCheckBoxes = document.getElementsByTagName('input');

		for (i = 1; i < thisCheckBoxes.length; i++) {
			if (thisCheckBoxes[i].name == Name){
				thisCheckBoxes[i].checked = false;
			}
		}
	}
}

function ShowCompare(Name) {
	var valid = false;
	var items = "";
	
	if (DOM) {
		thisCheckBoxes = document.getElementsByTagName('input');

		for (i = 1; i < thisCheckBoxes.length; i++) {
			if (thisCheckBoxes[i].name == Name){
				if (thisCheckBoxes[i].checked == true){
					valid = true;
					items =  items + thisCheckBoxes[i].value + ",";
				}
			}
		}
	}

	if (valid){
		var url = "/goods/catalog/compare/";

		Win=window.open(null, "hCompare",  'toolbar=0,scrollbars=1,location=0,directories=0,status=0,menubar=0,resizable=1,width=770,height=500,border=thin,top=50,left=50,help=0');

		document.forms['ProductsForm'].action = url;
		document.forms['ProductsForm'].CompareItems.value = items;
		document.forms['ProductsForm'].submit()

		Win.focus();
	}
}
 