	function setCFocus() {
		var comments = document.getElementById('rcomment') ? document.getElementById('rcomment') : null ;
		if (comments) 
		{
			if (!comments.value)
				comments.focus();
		}
	}
	function selectSearchBlock (id) {

		

		if (id!=2) {

			//var blockShow = document.getElementById("searchBlock" + id);

			//blockShow.style.display = '';

			

			//var blockHide = document.getElementById("searchBlock" + (1-id));

			//blockHide.style.display = 'none';



		}else {

			//var blockShow1 = document.getElementById("searchBlock0");

			//var blockShow2 = document.getElementById("searchBlock1");



			//blockShow1.style.display = '';

			//blockShow2.style.display = '';

		}

		

		return false;

	}	

	

	/**************************************************************

	*

	*	Search page block: switch ON|OFF all child elements in Tree

	*

	*/

	

	function switchCheckboxArray (str) {

		arr = unserialize(str);

		showArray(arr);

		return false;

	}	

	

	// Run through all Tree elements (foreach analog)

	

	function showArray(arr) {

		for (var key in arr) {

			// display message box with each array key and value

			// alert("Array key:" + key + ", value: " + arr[key]);

			swithCheckbox(key);

			swithCheckbox2(key);

			showArray(arr[key]);

		}

	}

	

	//	Change checkbox status to ON|OFF

	

	function swithCheckbox(id) {

		var diag = document.getElementById("diag" + id); 

		diag.checked = !diag.checked;		

		showSelectedAtLeft(id);

	}	

	

	function swithCheckbox2 (id) {

		var diag = document.getElementById("sdiag" + id); 

		diag.checked = !diag.checked;		

	}

	

	// Check if element is array

	

	function isArray(obj) {

		return (obj.constructor.toString().indexOf('Array') != -1);

	}

	

	// Show|Hide block of elements

	

	function showForm(id) {

		

		var m = document.getElementById(id);

		m.style.display = m.style.display  ? '' : 'none';

		

	}	

	

	function showForm2(id) {

		

		var m = document.getElementById('searchbox'+id);

		var m2 = document.getElementById('checkbox'+id);

		

		m.style.display = m.style.display  ? '' : 'none';

		m2.checked = !m2.checked;

		

	} 	

	

	function showSelectedAtLeft(id) {

		

		var divsdiag = document.getElementById("divsdiag" + id); 

		divsdiag.style.display = divsdiag.style.display  ? '' : 'none';

		

	} 

	

	function vIE(){

			return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;

	}



	// Init Form action and Run It

	function runForm(id, action) {

		

		var ie = vIE();

		//alert(ie);



		if (ie == -1) {

			

			//alert('mozilla');

			

			var m = document.getElementById(id);

			m.action = action;

			m.submit();

			

		}else{

			

			//alert('ie');

			

			var m = document.getElementById(id);

			//alert(m.action);

			

			//m.action = m.action.slice(0, -1000) + action;

			m.action = action;

			m.submit();

			

		}

	} 

	



	/*****************************************************************

	*	

	*	Regitration block: form filds validating

	*

	*/

	

	function checkForm(form, fields) {

	

		var idform = document.getElementById(form) ? document.getElementById(form) : null ;

		

		if (idform) {

			//alert(form);

			//alert(fields);

			for ( var i in fields ) {

				var f = fields[i];

				//alert(f);

				var res = checkField(f);

				if (!res) return false;

			}

			

		} else return false;

		

		idform.submit();

		

	}	

	

	function checkField(field) {

		

		var idfield = document.getElementById(field) ? document.getElementById(field) : null;

		

		/* regular fields */

		if(!idfield.value && field != 'AEmail' && field != 'BagID') {

			alert('Fill the '+field);

			idfield.focus();

			return false;

		}

		

		/* other fields */

		if(field == 'Password' && !checkPassword(idfield.value)) {

			alert('Password must be at least 6 characters long');

			idfield.focus();

			return false;

		}

		

		if(field == 'CPassword') {

			var idpassword = document.getElementById('Password') ? document.getElementById('Password') : null;

			if (idpassword) {

				if (idfield.value != idpassword.value) {

					alert('Check the Confirm password');

					idfield.focus();

					return false;

				}

			}else {

				alert('Fill the Password');

				idpassword.focus();

				return false;

			}

		}

		

		if(field == 'Email' && !checkMail(idfield.value)) {

			

			var arr = idfield.value.split(";");

			for(var i=0; i<arr.length; i++){

				if (arr[i]) var ch = checkMail(arr[i]);

			}

			if (!ch) alert('Incorrect email format'); else return true;

			idfield.focus();

			return false;

		}

		

		if (field == 'AEmail' && idfield.value && !checkMail(idfield.value)) {

			alert('Check the Confirm Email');

			idfield.focus();

			return false;

		}

	

		if(field == 'CInfo' && idfield.value == 0) {

			alert('You should apply the aggreement of receiving promo information.');

			idfield.focus();

			return false;

		}

		

		if(field == 'CEmails' && idfield.value == 0) {

			alert('You should aplly the agreement of email receiving.');

			idfield.focus();

			return false;

		}

		

		if(field == 'CTerms' && idfield.value == 0) {

			alert('You should agree with the terms of servise');

			idfield.focus();

			return false;

		}

		

		if(field == 'BagID') {

			if (!idfield.value)

			{

				alert('Please fill in the Bag ID');

				idfield.focus();

				return false;

			}

			if (idfield.value.length != 5)

			{

				alert('Bag ID is 5 character indentifier found on the tag attached to your bag');

				idfield.focus();

				return false;

			}

		}

		

		return true;

	}

	

	function checkDiagnose(fields) {

		

		for ( var i in fields ) {

			

			var field = document.getElementsByName("diag[" + fields[i] + "]");

			

			if (field[0].checked == true) return true;

			

			//for (i = 0; i < field.length; i++)

			

			//	if (field[i].checked == true) return true; 

			

		}

		

		alert("Check Diagnose!");

		

		return false;

	}	

	

	function checkMail(value) {

		re =/^[A-Za-z0-9_\-]+(\.[A-Za-z0-9_\-]+)*@([A-Za-z0-9_\-]+\.)+[A-Za-z0-9_\-]{2,3}$/;

		if(!re.test(value))

			return false;

		return true;

	}

	

	function checkPassword(value) {

		re =/^[A-Za-z0-9_\-!@#$%&*]+([A-Za-z0-9_\-!@#$%&*])$/;

		if(!re.test(value) || value.length < 6){

			return false;

		}else return true;

	}

	

	function resetForm(form) {

		var idform = $(form);

		idform.reset();

	}	

	

	/********************************************************

	* 

	*	Profile: Invite friends: Forming multi email string 

	*

	*/ 

	 

	function addEmail(id) {

		

		var email = document.getElementById(id);

		

		if (email.value) {

			

			var arr = email.value.split(";");

			

			for(var i=0; i<arr.length; i++){



				var ch = checkMail(arr[i]);

				//alert(arr[i]);

			}

			

			if (ch)	email.value = email.value + ';';

			else alert('Incorrect email format');

				

		}

		email.focus();

	}



	/***********************************************************

	*

	*	Work with images: Zooming

	*

	*/

	

	function zoom(link, title){

		

	    var win = window.open('','preview','width=50,height=50,left=0,top=0,screenX=0,screenY=0,resizable=no,scrollbar=no,status=no,menubar=no,titlebar=no,location=no,scrolling=no');

	    var winDoc = win.document;

	    var content = '<html><head><title>' + title + '</title>' + 

	    '<style>body{overflow: auto; padding:0; margin:0}img{border:0;}div{padding:5px; margin: 0 5px;}*div{padding:5px; margin: 0 5px;}html>body div {padding:0px 5px; margin: 0 5px;}</style>' + '</head><body><div><a href="javascript:self.close()">' +

	    '<img alt="' + title + '" id="image" title="Закрыть" src="' + link + '" /></a></div></body></html>';

	    win.document.write(content);

	    winDoc.body.onload = function() {

			var obj = winDoc.getElementById('image');

			var w = obj.width, h = obj.height;

			

			var iHeight= document.body.clientHeight, iWidth = self.innerWidth;

			var left = (self.opera ? iWidth : screen.availWidth)/2 - w/2;

			var top = (self.opera ? iHeight : screen.availHeight)/2 - h/2;



			win.resizeTo(w+25, h+80);

			

			win.moveTo(left, top);

	    }

	    win.onload = winDoc.body.onload; // special for Mozilla

	    // !!! Important statement: popup onload won't execute without it!

	    win.document.close();

	    win.focus();

	}

	

	

	/******************************************************

	*

	*	Work with arrays: Unserializing

	*

	*/

	

	function unserialize(data){

    // %            note: The main purpose of this function should be to ease the transport of data between php & js

    // %            note: Aiming for PHP-compatibility, we have to translate objects to arrays 

    // *       example 1: unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}');

    // *       returns 1: ['Kevin', 'van', 'Zonneveld']

    // *       example 2: unserialize('a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}');

    // *       returns 2: {firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}

    

    var error = function (type, msg, filename, line){throw new window[type](msg, filename, line);};

    var read_until = function (data, offset, stopchr){

        var buf = [];

        var chr = data.slice(offset, offset + 1);

        var i = 2;

        while(chr != stopchr){

            if((i+offset) > data.length){

                error('Error', 'Invalid');

            }

            buf.push(chr);

            chr = data.slice(offset + (i - 1),offset + i);

            i += 1;

        }

        return [buf.length, buf.join('')];

    };

    var read_chrs = function (data, offset, length){

        buf = [];

        for(var i = 0;i < length;i++){

            var chr = data.slice(offset + (i - 1),offset + i);

            buf.push(chr);

        }

        return [buf.length, buf.join('')];

    };

    var _unserialize = function (data, offset){

        if(!offset) offset = 0;

        var buf = [];

        var dtype = (data.slice(offset, offset + 1)).toLowerCase();

        

        var dataoffset = offset + 2;

        var typeconvert = new Function('x', 'return x');

        var chrs = 0;

        var datalength = 0;

        

        switch(dtype){

            case "i":

                typeconvert = new Function('x', 'return parseInt(x)');

                var readData = read_until(data, dataoffset, ';');

                var chrs = readData[0];

                var readdata = readData[1];

                dataoffset += chrs + 1;

            break;

            case "b":

                typeconvert = new Function('x', 'return (parseInt(x) == 1)');

                var readData = read_until(data, dataoffset, ';');

                var chrs = readData[0];

                var readdata = readData[1];

                dataoffset += chrs + 1;

            break;

            case "d":

                typeconvert = new Function('x', 'return parseFloat(x)');

                var readData = read_until(data, dataoffset, ';');

                var chrs = readData[0];

                var readdata = readData[1];

                dataoffset += chrs + 1;

            break;

            case "n":

                readdata = null;

            break;

            case "s":

                var ccount = read_until(data, dataoffset, ':');

                var chrs = ccount[0];

                var stringlength = ccount[1];

                dataoffset += chrs + 2;

                

                var readData = read_chrs(data, dataoffset+1, parseInt(stringlength));

                var chrs = readData[0];

                var readdata = readData[1];

                dataoffset += chrs + 2;

                if(chrs != parseInt(stringlength) && chrs != readdata.length){

                    error('SyntaxError', 'String length mismatch');

                }

            break;

            case "a":

                var readdata = {};

                

                var keyandchrs = read_until(data, dataoffset, ':');

                var chrs = keyandchrs[0];

                var keys = keyandchrs[1];

                dataoffset += chrs + 2;

                

                for(var i = 0;i < parseInt(keys);i++){

                    var kprops = _unserialize(data, dataoffset);

                    var kchrs = kprops[1];

                    var key = kprops[2];

                    dataoffset += kchrs;

                    

                    var vprops = _unserialize(data, dataoffset);

                    var vchrs = vprops[1];

                    var value = vprops[2];

                    dataoffset += vchrs;

                    

                    readdata[key] = value;

                }

                

                dataoffset += 1;

            break;

            default:

                error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype);

            break;

        }

        return [dtype, dataoffset - offset, typeconvert(readdata)];

    };

    return _unserialize(data, 0)[2];

	}