var requiredMajorVersion = 8;
var requiredMinorVersion = 0;
var requiredRevision = 0;
var cls = '';
var min=80;
var max=150;
var hintInterval=0;
var hintInterval1=0;
var hideDetailed=0;
var globHintTime=false;
function getSubs(parID, parVal){
	//if(parVal!=document.getElementById(parID).options[0].value)
		printersObj.getAllGroups4Parent_ajax(parVal, function(res){getSubs1(res, parID)});
	//else
	//	getSubs1(new Array(), parID);
}
function getSubs1(res, par){
	var containerID=(par.replace('sel', '')*1)+1;
	var container=document.getElementById('sel'+containerID);
	emptySelect('sel'+containerID);
	var oOpt=document.createElement('option');
	oOpt.setAttribute('value', '');
	oOpt.appendChild(document.createTextNode(all));
	container.appendChild(oOpt);
	for(var i=0; i<res.length; i++){
		var oOpt=document.createElement('option');
		oOpt.setAttribute('value', res[i]['groupID']);
		oOpt.appendChild(document.createTextNode(res[i]['title']));
		container.appendChild(oOpt);
	}
	for(var i=1; i<6; i++){
		if(i>containerID){
			emptySelect('sel'+i);
			document.getElementById('selHolder'+i).style.display='none';
		}else{
			document.getElementById('selHolder'+i).style.display='';
		}
	}
}
function emptySelect(id){
	container=document.getElementById(id);
	for(var i=container.childNodes.length-1; i>=0; i--)
		container.removeChild(container.childNodes[i]);
}


function validateContact(){
	var reMail = /^[A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\.[A-Za-z]{2,4}$/;
	if(document.getElementById("email").value==''){
		alert(ENTER_MAIL);
		document.getElementById("email").focus();
		return false;
	}else if(!reMail.exec(document.getElementById("email").value)){
		alert(WRONG_M);
		document.getElementById("email").focus();
		return false;
	}else
		return true;
}

function showPass(uID){
	if(uID && !isNaN(uID)){
		document.getElementById('uID_pass').value=uID;
	}
	document.getElementById('changePass').style.display='block';
	document.getElementById('changePassIf').style.display='block';
	document.getElementById('changePassIf').style.height=document.getElementById('changePass').offsetHeight+'px';
	document.getElementById('oldPass').focus();
}
function hidePass(){
	document.getElementById('changePass').style.display='none';
	document.getElementById('changePassIf').style.display='none';
}
function validate_pass(){
	if(document.getElementById('oldPass').value==''){
		alert(emptyVal);
		document.getElementById('oldPass').focus();
		return false;
	}else if(document.getElementById('confirm').value==''){
		alert(emptyVal);
		document.getElementById('confirm').focus();
		return false;
	}else if(document.getElementById('password').value==''){
		alert(emptyVal);
		document.getElementById('password').focus();
		return false;
	}else if(document.getElementById('password').value!=document.getElementById('confirm').value){
		alert(wrongConf);
		document.getElementById('password').focus();
		return false;
	}else if(document.getElementById('password').value.length<5){
		alert(fiveChars);
		document.getElementById('password').focus();
		return false;
	}else{
		return true;
	}
}

function showPermVauch(){
	document.getElementById('addPermVauch').style.display='block';
	document.getElementById('addPermVauchIf').style.display='block';
	document.getElementById('addPermVauchIf').style.height=document.getElementById('addPermVauch').offsetHeight+'px';
	document.getElementById('voucherCode').focus();
}
function hideVouch(){
	document.getElementById('addPermVauch').style.display='none';
	document.getElementById('addPermVauchIf').style.display='none';
}
function validate_vauch(){
	if(document.getElementById('voucherCode').value==''){
		alert(emptyVal);
		document.getElementById('voucherCode').focus();
		return false;
	}else{
		return true;
	}
}
function setliveCart(){
	$('#setCartAddress').click(function(){
		//tova se refreshva... ;)
		$('#addressHolder').slideToggle();
	});
	$('#payForm input, #payForm select, #payForm textarea').live('change', function(){
		getSubtotal();
	}).change(function(){getSubtotal();});
}
$(document).ready(function(){
	
	$('#detailedVoteInfo').mouseover(function(){
		clearTimeout(hideDetailed);
	})
	$('#payment_type').change(function(e){
		$('#ptHintTrg').attr('showHint', 'hint'+this.value);
		$('div[id^=hint]').hide();
		$('#hint'+this.value).fadeIn();
// 		showHint(e, $('#'+$('#ptHintTrg').attr('showHint')).html(), $(this));
	});
	$('#showDetailed').mouseover(function(){
		$('#detailedVoteInfo').fadeIn();
	}).mouseout(function(e){
		hideDetailed=setTimeout("$('#detailedVoteInfo').fadeOut();", 100);
	});
	$('#delPermVauch').click(function(){
		if(confirm(DellCommetConf))
			$.post('#', { delConstVoucher: "1"}, function(d){
				$('#permVauchHldr').html($('#permVauchHldr', d).html());
				$('#messages').html($('#messages', d).html());
			});
	});
	$('#taggleSuggest').click(function(){
		$('#suggestFormHolder').slideToggle();
	});
	$('#rateMap area').mouseover(function(){
		rateID=$(this).attr('alt');
		$('#rateImg').attr('src', "img/public/rate"+rateID+".gif");
	}).mouseout(function(){
		var im=document.getElementById('rateImg');
		$('#rateImg').attr('src', "img/public/rate"+Math.round($('#rateImg').attr('initSrc'))+".gif");
	}).click(function(){
		rateID=$(this).attr('alt');
		Obj.doVoteProduct_ajax(pID, rateID, $('#rateImg').attr('initSrc'), listRating);
	});
	setliveCart();
	setShowHints();
});
function listRating(res){
	if(!res['bool'])
		alert('Error occured while saving results!');
	$('#rateImg').attr( { src: "img/public/rate"+Math.round(res['newAvgStars'])+".gif", useMap: '', initSrc: res['newAvgStars']});
	$('#rateInfo').html(res['newAvgStars']);
}
function validate(formID){
	if(!formID)
		formID='userReg';
	var reMail = /^[A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\.[A-Za-z]{2,4}$/;
	var inputs=document.getElementById(formID).elements;

	for(var i=0; i<inputs.length; i++){
		if(inputs[i].id.indexOf('_ob') >-1 || true){
			matchLang=/_\d/;
			var lID_a=matchLang.exec(inputs[i].name);
			if(lID_a!=null){
				var lID=lID_a[0].replace('_', '');
				if(!document.getElementById('goto'+lID) || (document.getElementById('goto'+lID) && !document.getElementById('goto'+lID).checked))
					continue;
			}
				
			if(inputs[i].id.indexOf('_ob')  >-1 && inputs[i].value==''){
				alert(emptyVal);
				inputs[i].focus();
				return false;
			}else if(inputs[i].id.indexOf('_em')>-1 && !reMail.exec(inputs[i].value)){
				alert(wrongMail);
				inputs[i].focus();
				return false;
			}else if(inputs[i].id.indexOf('_n')>-1 && isNaN(inputs[i].value)){
				alert(wrongDigit);
				inputs[i].focus();
				return false;
			}else if(formID=='userReg' && inputs[i].name=='e_mail' && checkVal('EMail', inputs[i].value, -2)){
				alert(wrongE_Mail);
				inputs[i].focus();
				return false;
			}else if(formID=='userReg' && inputs[i].name=='username' && checkVal('User', inputs[i].value, -2)){
				alert(wrongUser);
				inputs[i].focus();
				return false;
			}else if(formID!='userReg' && inputs[i].name=='e_mail' && checkVal('EMail', inputs[i].value, document.getElementById('uID1').value)){
				alert(wrongE_Mail);
				inputs[i].focus();
				return false;
			}else if(formID!='userReg' && inputs[i].name=='username' && checkVal('User', inputs[i].value, document.getElementById('uID1').value)){
				alert(wrongUser);
				inputs[i].focus();
				return false;
			}
		}
	}
	if(ii==0){
		if(document.getElementById('confirm').value==''){
			alert(emptyVal);
			document.getElementById('confirm').focus();
			return false;
		}else if(document.getElementById('password').value==''){
			alert(emptyVal);
			document.getElementById('password').focus();
			return false;
		}else if(document.getElementById('password').value!=document.getElementById('confirm').value){
			alert(wrongConf);
			document.getElementById('password').focus();
			return false;
		}else if(document.getElementById('password').value.length<5){
			alert(fiveChars);
			document.getElementById('password').focus();
			return false;
		}
	}
	return true;
}
function checkVal(prop, val, uID){
	return eval('usersObj.check'+prop+"_ajax('"+val+"', "+uID+");");
}
function dynCheckMail(){
	if(usersObj.checkEMail_ajax(document.getElementById('e_mail_ob_em').value, -2)){
		document.getElementById('EMSpan').innerHTML='<img src="'+path+'img/public/hint.jpg" border="0" style="display: inline; height: 18px;"/>';
		document.getElementById('e_mail_ob_em').style.width='116px';
		document.getElementById('e_mail_ob_em').style.color='#ff0000';
	}else{
		document.getElementById('EMSpan').innerHTML='<img src="'+path+'img/public/active.jpg" border="0" style="display: inline; height: 18px;"/>';
		document.getElementById('e_mail_ob_em').style.width='116px';
		document.getElementById('e_mail_ob_em').style.color='#009933';
	}
}
function dynCheckUser(){
	if(usersObj.checkUser_ajax(document.getElementById('username_ob').value, -2)){
		document.getElementById('UsSpan').innerHTML='<img src="'+path+'img/public/hint.jpg" border="0" style="display: inline; height: 18px;"/>';
		document.getElementById('username_ob').style.width='116px';
		document.getElementById('username_ob').style.color='#ff0000';
	}else{
		document.getElementById('UsSpan').innerHTML='<img src="'+path+'img/public/active.jpg" border="0" style="display: inline; height: 18px;"/>';
		document.getElementById('username_ob').style.width='116px';
		document.getElementById('username_ob').style.color='#009933';
	}
}
function dynCheckMail1(){
	if(usersObj.checkEMail_ajax(document.getElementById('e_mail1_ob_em').value, document.getElementById('uID1').value)){
		document.getElementById('EMSpan1').innerHTML='<img src="'+path+'img/public/hint.jpg" border="0" style="display: inline; height: 18px;"/>';
		document.getElementById('e_mail1_ob_em').style.width='116px';
		document.getElementById('e_mail1_ob_em').style.color='#ff0000';
	}else{
		document.getElementById('EMSpan1').innerHTML='<img src="'+path+'img/public/active.jpg" border="0" style="display: inline; height: 18px;"/>';
		document.getElementById('e_mail1_ob_em').style.width='116px';
		document.getElementById('e_mail1_ob_em').style.color='#009933';
	}
}
function dynCheckUser1(){
	if(usersObj.checkUser_ajax(document.getElementById('username1_ob').value, document.getElementById('uID1').value)){
		document.getElementById('UsSpan1').innerHTML='<img src="'+path+'img/public/hint.jpg" border="0" style="display: inline; height: 18px;"/>';
		document.getElementById('username1_ob').style.width='116px';
		document.getElementById('username1_ob').style.color='#ff0000';
	}else{
		document.getElementById('UsSpan1').innerHTML='<img src="'+path+'img/public/active.jpg" border="0" style="display: inline; height: 18px;"/>';
		document.getElementById('username1_ob').style.width='116px';
		document.getElementById('username1_ob').style.color='#009933';
	}
}
function delPicBrock(){
	if(confirm(delPic)){
		usersObj.delPicBrock_ajax(document.getElementById('uID1').value, showBrock1);
	}
}
function setLangs(){
	for(var i=0; i<allLangs.length; i++){
		if(lID!=allLangs[i]){
			if(document.getElementById('goto'+allLangs[i]).checked){
				document.getElementById('orgLangHolder'+allLangs[i]).style.display='';
				document.getElementById('infoLangHolder'+allLangs[i]).style.display='';
				document.getElementById('nameLangHolder'+allLangs[i]).style.display='';
			}else{
				document.getElementById('orgLangHolder'+allLangs[i]).style.display='none';
				document.getElementById('infoLangHolder'+allLangs[i]).style.display='none';
				document.getElementById('nameLangHolder'+allLangs[i]).style.display='none';
			}
		}
	}
}
function copy(to, from){
	if(!from)
		var from=0;
	var copyWhat=new Array('countryID','address','PK','city','street','zonaID');
	for(var j=0; j<copyWhat.length; j++){
	//	alert(copyWhat[j]);
		if(document.getElementById(copyWhat[j]+'_'+from))
			document.getElementById(copyWhat[j]+'_'+to).value=document.getElementById(copyWhat[j]+'_'+from).value;
		else if(document.getElementById(copyWhat[j]+'_'+from+'_ob'))
			if(document.getElementById(copyWhat[j]+'_'+to+'_ob'))
				document.getElementById(copyWhat[j]+'_'+to+'_ob').value=document.getElementById(copyWhat[j]+'_'+from+'_ob').value;
			else
				document.getElementById(copyWhat[j]+'_'+to).value=document.getElementById(copyWhat[j]+'_'+from+'_ob').value;
		else if(document.getElementById(copyWhat[j]+'_'+from+'_ob_n'))
			if(document.getElementById(copyWhat[j]+'_'+to+'_ob_n'))
				document.getElementById(copyWhat[j]+'_'+to+'_ob_n').value=document.getElementById(copyWhat[j]+'_'+from+'_ob_n').value;
			else
				document.getElementById(copyWhat[j]+'_'+to).value=document.getElementById(copyWhat[j]+'_'+from+'_ob_n').value;
		if(copyWhat[j]=='countryID')
			countryChanged(document.getElementById(copyWhat[j]+'_'+from).value, copyWhat[j]+'_'+to);
	}
}
function countryChanged(countryID, selid){
	var rID=selid.split('_')[1];
	var sel=document.getElementById('zonaID_'+rID);
	var zones=usersObj.zona_getByCountryID_ajax(countryID);
	for(var i=sel.childNodes.length-1; i>=0; i--){
		sel.removeChild(sel.childNodes[i]);
	}
	for(var i=0; i<zones.length; i++){
		var oOpt=document.createElement('option');
		oOpt.setAttribute('value', zones[i]['zonaID']);
		oOpt.appendChild(document.createTextNode(zones[i]['zona']));
		sel.appendChild(oOpt);
	}
}

function trim(str){
	if(typeof(str)!='string') 
		return '';
	str=str.replace(/\s+$/,'');
	str=str.replace(/^\s+/,'');
	return str;
}
function clearSearch(input){
	if (input.value == "Search") 
		input.value="";
}

function showImage_mazno(path){
	document.getElementById('dHolder1').innerHTML='<img src="img/dots.gif" id="dHolder" border="0" onClick="javascript: hideImage_mazno();"/>';
	document.getElementById('tint').style.display='block';
	document.getElementById('mazenHolder').src='modules/make_thumbs.php?name=./'+path+'&maxnw=600';
}
function hideShow(){
	var wid=document.getElementById('mazenHolder').width*1;
	document.getElementById('wait_messHolder').style.width=wid+'px';
	document.getElementById('wait_messHolder').style.height=document.getElementById('mazenHolder').height*1+'px';
	document.getElementById('wait_messHolder').style.marginLeft='-'+wid/2+'px';
	document.getElementById('mazenHolder').style.display='inline';
	document.getElementById('wait_messHolder').style.display='block';
	document.getElementById('dHolder1').style.display='none';
}
function hideImage_mazno(){
	document.getElementById('tint').style.display='none';
	document.getElementById('dHolder1').style.display='inline';
	document.getElementById('wait_messHolder').style.display='none';
	document.getElementById('mazenHolder').style.display='none';
	//document.getElementById('mazenHolder').src='img/dots.gif';
}


function printIT(id){
	newWin = window.open('','a','width=780,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
	var html = '&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;&lt;html&gt;&lt;head&gt;&lt;meta name="description" content="ClearWare print tool"/&gt;&lt;meta name="keywords" content="k"/&gt;&lt;meta name="author" content="office@clearware.eu"/&gt;&lt;link href="css/pub_print.css" rel="stylesheet"/&gt;&lt;/head&gt;&lt;body&gt;'+document.getElementById(id).innerHTML+'&lt;/body&gt;&lt;/html&gt;';
	//alert(html);
	newWin.document.write(html);
	newWin.print();
}
function increaseFontSize() {
	var p = document.getElementById('mutant_text');
	//for(i=0;i&lt;p.length;i++) {
		if(p.style.fontSize) {
			var s = parseInt(p.style.fontSize.replace("%",""));
		} else {
			var s = 100;
		}
		if(s < max) {
			s += 10;
		}
		p.style.fontSize = s+"%";
	//}
}
function decreaseFontSize() {
	var p = document.getElementById('mutant_text');
	if(p.style.fontSize) {
		var s = parseInt(p.style.fontSize.replace("%",""));
	} else {
		var s = 100;
	}
	if(s > min) {
		s -= 10;
	}
	p.style.fontSize = s+"%";
}

function setShowHints(){
	$("*[showHint]").hover(function(e){
		showHint(e, $('#'+$(this).attr('showHint')).html(), $(this));
	},
	function(e){
		hideHint(e);
	});
}
function showHint(e, ht, this1){
	if(globHintTime){
		clearTimeout(globHintTime);
		//return;
	}
// 	e.preventDefault();
// 	document.getElementById('infoLogger').innerHTML+='<b>vliza v show</b><br/>';
	var myPos=this1.offset();
	$("#hintContHolder").html(ht);
	$("#hintWindow").css({ top:myPos.top+'px', left:myPos.left+26+'px', display:'block' });
// 	$("#hintWindow").slideDown("normal", function(){
// 		$(this).attr( {isBeingAnimated:0} );
// 		$(this).css({opacity:''});
// 		var myThis=$(this);
	$(document).mousemove(function(e){
		if(!$(e.target)==$("#hintWindow"))
			hideHint(e);
	});
// 	});
}
function hideHint(e){
	globHintTime=setTimeout('hideHint1();', 100);
}
function hideHint1(){
	$("#hintWindow").stop();
// 	$("#hintWindow").slideUp("fast");
	$("#hintWindow").css('display', 'none');
	$(document).unbind('mousemove');
	globHintTime=false;
}
function delRow(rowID){
	if(confirm(delCart))
		usersObj.del_plashtane_ajax(rowID, refreshRows);
}
function getSubtotal(){
	var datad=createFormArray1('payForm');
	for(var i in datad)
		if(i.indexOf('qty_')==0 && datad[i]==0){
			alert(nonzero);
			document.getElementById(i).focus();
			return false;
		}
	usersObj.edit_quantity_ajax(datad, refreshRows)
}
function refreshRows(res){
	$('#cartHolder').html(res);
	setliveCart();
}
function createFormArray1(form_id){
	myForm = document.getElementById(form_id);
	inputs = myForm.elements;
	var out = new Array();
	for (var i=0; i<inputs.length; i++){
		if(inputs[i].name && inputs[i].name!=''){
			if(inputs[i].name.indexOf('[]')!=-1){
				if(out[inputs[i].name.replace('[]', '')]==undefined || out[inputs[i].name.replace('[]', '')].constructor.toString().indexOf("Array") == -1){
					out[inputs[i].name.replace('[]', '')]=new Array();
				}
				if(inputs[i].type=='checkbox' || inputs[i].type=='radio'){
					if(inputs[i].checked){
						out[inputs[i].name.replace('[]', '')].push(inputs[i].value);
					}
				}else{
					out[inputs[i].name.replace('[]', '')].push(inputs[i].value);
				}
			}else if (inputs[i].type=='checkbox'){
				out[inputs[i].name]=(inputs[i].checked)?inputs[i].value:'';
			}else if(inputs[i].type=='radio'){
				if(inputs[i].checked)
					out[inputs[i].name]=inputs[i].value;
			}else if (inputs[i].type=='select-multiple'){
				out[inputs[i].name]= getMultiSelectVals(inputs[i]);
			}else{
				out[inputs[i].name]=inputs[i].value;
			}
		}
	}
	return out;
}