function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}
function trim(strText){
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
    return strText;
} 
function existsEmail(text){
	var sss = text;	
	sss = trim(replace(replace(sss,'\r',' '),'\n',' '));
	if (sss=="") return false; 	
	var temp = Array();
	temp=sss.split(/[<>, ;{}\-\*\%\$\#\&\!\~]/);
	for (var i=0,n=temp.length, s=''; i<n; i++) {
		s = temp[i];
		if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) 
			return true;     	
	}		
	return false; 	
}
function checkData(){
	if (existsEmail(document.forms[0].qtext.value)) {
	  alert("Q&A sessions are monitored.\nPassing of email address or other contact details is a violation of our site rules which can result in a penalty charge.\nModify your question if you need to now.");
	  return false;
	} 	
	if (document.forms[0].qtext.value.length >2500){
	  alert("Please limit your question to 2500 characters. Currently it is "+ document.forms[0].qtext.value.length + " characters long.");
	  return false;
	}
	return true;
}
function showPic(obj){
	var oldSrc = obj.src;
	if (oldSrc.length < 9) {
		obj.src = "/img/ads/image-not-available.gif";
	} else if (oldSrc.indexOf("http://195.224.149.148/show.asp?u=") < 0 ) {
		obj.src = "http://195.224.149.148/show.asp?u=" + escape(oldSrc) ;
	}
}
function open_win(w_url,name,attr){
	if (name) {
		if (!attr)
			attr = "height=350,width=500";
		var newwindow=window.open(w_url,name,'directories=0,status=0,location=0,resizable=1,menubar=0,scrollbars=0,toolbar=0,'+attr);
		if (window.focus) {newwindow.focus()}
	} else {
		var newwindow=window.open( '/show.asp?u=' + escape(w_url), '_blank', 'directories=0,height=350,width=500,status=0,location=0,resizable=1,menubar=0,scrollbars=0,toolbar=0');
		if (window.focus) {newwindow.focus()}
	}
//	return false;
}	
function fixImgWidth (obj, wdth) {
	if (obj.width && (1*obj.width>wdth)) {
		obj.width=wdth;	
	}	
}
function glPopUp(url,name,attr){
	var newwindow=window.open(url,name,'toolbar=no,scrollbars=yes,resizable=yes,'+attr);
	if (window.focus) {newwindow.focus()}
	return false;
}
function switchClosedInfo(fl){
	var obj = document.getElementById('descrLink');
	if((fl==false) || (document.getElementById('MainIfo').style.display!='block')) {
		document.getElementById('MainIfo').style.display='block';
		document.getElementById('ItemDescr').style.display='block';
		document.getElementById('ItemQABids').style.display='block';
		document.getElementById('listOtherItems').style.display='none';
		obj.innerHTML = '<img src="/img/arrow3.gif" border="0" WIDTH=9 HEIGHT=9> <b>Check out these other items</b>';
	} else {
		document.getElementById('MainIfo').style.display='none';
		document.getElementById('ItemDescr').style.display='none';
		document.getElementById('ItemQABids').style.display='none';
		document.getElementById('listOtherItems').style.display='block';
		obj.innerHTML = '<img src="/img/arrow3.gif" border="0" WIDTH=9 HEIGHT=9> <b>View Description Details</b>';			
	}
	return false;
}
	function checkF() {
		for (var i=0;i<2;i++) {
			if (document.getElementById('variant'+i) && document.getElementById('variant'+i).value=='') {
				alert('Please choose '+document.getElementById('variant'+i).title+'!');document.getElementById('variant'+i).focus();return false;
			}
		}
		return true;
	}
	function Round(Val, Len){
		return Math.round(Math.pow(10, Len) * Val) / Math.pow(10, Len);
	}	
	var defPrice = 0;
	function variantPrice() {
		var maxPr = 0;
		if (defPrice==0) {
			defPrice = 1*document.getElementById('mbid').value;
		}
		for (var i=0; i<variantPR.length; i++) {
			if (variantPR[i] && document.getElementById('variant'+i) && 1*document.getElementById('variant'+i).value>0) {
				if (variantPR[i][1*document.getElementById('variant'+i).value] && (maxPr < 1*variantPR[i][1*document.getElementById('variant'+i).value])) {
					maxPr = 1*variantPR[i][1*document.getElementById('variant'+i).value]
				}
			}
		}
		if (maxPr == 0)
			maxPr = defPrice;
			
		document.getElementById('mbid').value = maxPr;
		if (maxPr.toFixed) 
			maxPr = maxPr.toFixed(2);

		document.getElementById('priceBlock').innerHTML = sellerVcod + maxPr;
		if (document.getElementById('priceBlockNat')) {
			maxPr = Round(maxPr/sellerKurs*kurs, 2)
			if (maxPr.toFixed) 
				maxPr = maxPr.toFixed(2);
			document.getElementById('priceBlockNat').innerHTML = vcod + maxPr;
		}
	}

