/* init */
ns6=(document.all)? 0:1;
//Array.prototype.push=function(el){this[this.length]=el;} /* ie5 sucks * /
/* onload initialisation */
var ONLOAD_EVENTS = [];

onload = function() {
	eval( ONLOAD_EVENTS.join(';') );
	if ( window.init ) init();
}
/* onload execution */
 if (!ns6){ ONLOAD_EVENTS.push("document.execCommand('BackgroundImageCache', false, true);"); }

function showHide(id)
{	el=document.getElementById(id);
 	el.style.display=((el.style.display=="none")||(el.style.display==""))?'block':'none';
}
function doSubmit(frmName)
{	document.forms[frmName].submit();
}
function doReset(frmName)
{	frm=document.forms.frmName
	for(var i=frm.elements.length-1;i>=0;i--)
	{	frm.elements[i]='';	}
}

function openPrint()
{	if(WindowObjectReference == null || WindowObjectReference.closed){
		WindowObjectReference = window.open (document.location.href + '&mode=print', "printProd", "resizable=1, scrollbars=1, status=1, toolbar=0, width=360, height=610");
	}else{ WindowObjectReference.focus();
	}
}

function viewBigPic ( cellId ) {
	if ( typeof( currId ) == 'undefined' ) {
		currId = 'pic1';
	}

	if ( currId != cellId ) {
		$('#'+currId).removeClass();
	}

	$('#'+cellId).addClass('active');
	currId = cellId;

	if ( $('#'+cellId).attr('bigSrc') != 'no' ) {
		// flip images
		$('#flashPic').hide();

		if ( $('#'+cellId).attr('bigSrc') ) {
			tempEl 		= document.createElement("img");
			tempParent 	= document.getElementById('bigPic').parentNode;
			tempParent.replaceChild( tempEl, $('#bigPic').get(0) );

			$(tempEl).attr('id',"bigPic");
			$(tempEl).attr('src',$('#'+cellId).attr('bigSrc'));
			$(tempEl).attr('alt',"голяма снимка");
			$(tempEl).attr('title',"голяма снимка");//moz
		}
	} else {
		// show video
		$('#bigPic').hide();
		$('#flashPic').show();
	}
}

function changeSendEmail ( el, aName ) {
	if ( aName == 'company' ) {
		el.className = 'companyTab';
		document.getElementById('clientTab').className = '';
		$('#emailClientFrm').hide();
		$('#emailCompanyFrm').show();
	} else {
		el.className = 'clientTab';
		document.getElementById('companyTab').className = '';
		$('#emailCompanyFrm').hide();
		$('#emailClientFrm').show();
	}
}

function ChangeLanguage ( language_id ) {
	var current_language_id = GetCookie("LANGUAGECOOKIE");

	if ( typeof(language_id) != 'undefined' ) {
		if ( language_id != current_language_id ) {
			SetCookie("LANGUAGECOOKIE",language_id,(new Date()).setFullYear(2020,1,1),"/",GetDomain(),0);
			document.location.reload();
		}
	}
}

function GotoPage ( form_id, page_num, params ) {
   if ( typeof($(':input[name="cp"]').get(0)) == 'undefined' && typeof($(':input[name="category_id"]').get(0)) == 'undefined' ) {
      $('<input name="cp" type="hidden" value="'+page_num+'" />').appendTo('#'+form_id);
      if ( typeof(params) == 'object' ) {
         if ( typeof(params.CATEGORY_ID) != 'undefined' ) {
            $('<input name="category_id" type="hidden" value="'+params.CATEGORY_ID+'" />').appendTo('#'+form_id);
         }
         if ( typeof(params.ZONE_ID) != 'undefined' ) {
            $('<input name="zone_id" type="hidden" value="'+params.ZONE_ID+'" />').appendTo('#'+form_id);
         }
         if ( typeof(params.SEARCH_TEXT) != 'undefined' ) {
            $('<input name="search_text" type="hidden" value="'+params.SEARCH_TEXT+'" />').appendTo('#'+form_id);
         }
      }
   } else {
      $(':input[name="cp"]').val(page_num);
      if ( typeof(params) == 'object' ) {
         if ( typeof(params.CATEGORY_ID) != 'undefined' ) {
            $(':input[name="category_id"]').attr('disabled',false).val(params.CATEGORY_ID);
         }
         if ( typeof(params.ZONE_ID) != 'undefined' ) {
            $(':input[name="zone_id"]').attr('disabled',false).val(params.ZONE_ID);
         }
         if ( typeof(params.SEARCH_TEXT) != 'undefined' ) {
            $(':input[name="search_text"]').attr('disabled',false).val(params.SEARCH_TEXT);
         }
      }
   }

   $('#'+form_id).submit();
}

function ServiceCat ( cat_id ) {
	$(':input[name="cp"]').val(1);
	$(':input[name="category_id"]').val(cat_id);
	$('#nav_form').submit();
}

function SendQuestion ( form_id ) {
	if ( form_id ) {
		$.post(
			'send_question.pcgi',
			{
				"p_id":   		$(form_id).find(':input[name="p_id"]').val(),
				"p_name":   	$(form_id).find(':input[name="p_name"]').val(),
				"company":   	$(form_id).find(':input[name="company"]').val(),
				"name":   		$(form_id).find(':input[name="name"]').val(),
				"city":   		$(form_id).find(':input[name="city"]').val(),
				"address":   	$(form_id).find(':input[name="address"]').val(),
				"tel":   		$(form_id).find(':input[name="tel"]').val(),
				"email":   		$(form_id).find(':input[name="email"]').val(),
				"quest":   		$(form_id).find('textarea[name="quest"]').val()
			},
			function (data) {
				ShowSendResponse(data);
				return false;
			},
			'json'
		);
	}
}


function ShowSendResponse ( data ) {
	if ( parseInt(data["has_error"]) ) {
		alert(data["message"]);
	} else {
		$('#sendEmail').hide();
      $('#emailClientFrm').get(0).reset();
		$('#emailCompanyFrm').get(0).reset();
		alert(data["message"]);
	}
}
