// JavaScript Document
hs.graphicsDir = SITE_ROOT + 'highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
//hs.numberPosition = 'caption';
hs.dimmingOpacity = 0.5;



function ajax_get($switch, parameters) {
	parameters = jQuery.extend(true, {
		data: {
			lang: LANG,
			'switch': $switch
		}
	}, parameters);
	$.ajax({
		url: SITE_ROOT+'ajax.php',
		data: parameters.data,
		dataType: 'html',
		success: function (responseText, responseCode, xhr) {
			if (parameters.target) {
				$('#'+parameters.target).html(responseText);
			}
			if (parameters.success) {
				parameters.success(responseText, responseCode, xhr);
			}
		}
	});
}




function ajah_get($switch, parameters) {
	parameters = jQuery.extend(true, {
		data: {
			lang: LANG,
			'switch': $switch
		},
		target: ''
	}, parameters);
	$.ajax({
		url: SITE_ROOT+'ajax.php',
		data: parameters.data,
		dataType: 'html',
		success: function (responseText, responseCode, xhr) {
			if (parameters.target) {
				$('#'+parameters.target).html(responseText);
			}
			if (parameters.success) {
				parameters.success(responseText, responseCode, xhr);
			}
		},
		error: function (xhr, responseCode) {
			if (parameters.error) {
				parameters.error(xhr, responseCode);
			} else {
				1;//alert('Something went wrong... Err code: '+responseCode);
			}
		}
	});
}




(function($) {
	$.stickr = function(o) {
		var o = $.extend({   // настройки по умолчанию
			time:5000, // количество мс, которое отображается сообщение
			speed:'slow', // скорость исчезания
			note:null, // текст сообщения
			className:null, // класс, добавляемый к сообщению
			sticked:false, // не выводить кнопку закрытия сообщения
			position:{top:0,right:0} // позиция по умолчанию - справа сверху
		}, o);
		var stickers = $('#jquery-stickers'); // начинаем работу с главным элементом
		if (!stickers.length) { // если его ещё не существует
			$('body').prepend('<div id="jquery-stickers"></div>'); // добавляем его
			var stickers = $('#jquery-stickers');
		}
		//stickers.css('position','fixed').css({right:'auto',left:'auto',top:'auto',bottom:'auto'}).css(o.position); // позиционируем
		stickers.css('position','absolute').css({right:'auto',left:'auto',top:'auto',bottom:'auto'}).css(o.position); // позиционируем
		var stick = $('<div class="stick"></div>'); // создаём стикер
		stickers.append(stick); // добавляем его к родительскому элементу
		if (o.className) stick.addClass(o.className); // если необходимо, добавляем класс
        stick.html(o.note); // вставляем сообщение
		if (o.sticked) { // если сообщение закреплено
			var exit = $('<div class="exit"></div>');  // создаём кнопку выхода
			stick.prepend(exit); // вставляем её перед сообщением
			exit.click(function(){  // при клике
				stick.fadeOut(o.speed,function(){ // скрываем стикер
					$(this).remove(); // по окончании анимации удаляем его
				});
			});
		} else { // если же нет
			setTimeout(function(){ // устанавливаем таймер на необходимое время
				stick.fadeOut(o.speed,function(){ // затем скрываем стикер
					$(this).remove(); // по окончании анимации удаляем его
				});
			}, o.time);
		}
	};
})(jQuery);

function searchIn(n)
{
    var objIn = document.getElementById('search-in');
    if (objIn)
    {
        var items = objIn.getElementsByTagName('li');
        for (var i=0; i<items.length; i++)
        {
            if (items[i].id == 'search-in-' + n)
            {
                items[i].className = 'selected';
            }
            else
            {
                items[i].className = '';
            }
        }
    }
}

function trim(str)
{ 
	return str.replace(/^\s+|\s+$/g, '');
}

function number_format( number, decimals, dec_point, thousands_sep )
{
	var i, j, kw, kd, km, minus = '';

	if(number < 0){
		minus = '-';
		number = number*-1;
	}

	// input sanitation & defaults
	if( isNaN(decimals = Math.abs(decimals)) ){
		decimals = 2;
	}
	if( dec_point == undefined ){
		dec_point = ",";
	}
	if( thousands_sep == undefined ){
		thousands_sep = ".";
	}

	i = parseInt(number = (+number || 0).toFixed(decimals)) + "";

	if( (j = i.length) > 3 ){
		j = j % 3;
	} else{
		j = 0;
	}

	km = (j ? i.substr(0, j) + thousands_sep : "");
	kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
	//kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
	kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");

	return minus + km + kw + kd;
}


// Tabs
function SelectTab (n, tabs) {
	for (var i=1; i<=tabs; i++) {
		if (n == i) {
			jQuery('#tab_'+i).addClass('selected');
			jQuery('#content_tab_'+i).show();
		} else {
			jQuery('#tab_'+i).removeClass('selected');
			jQuery('#content_tab_'+i).hide();
		}
	}
}

function pagesMenuOver(obj)
{
	obj.oldClass = obj.className;
	obj.className = 'selected';
}

function pagesMenuOut(obj)
{
	if (obj.oldClass && obj.oldClass != '')
	{
		obj.className = obj.oldClass;
	}
	else
	{
		obj.className = '';
	}
}

function contactSubmit()
{
	var is_submit = true;
	
	// Name
	if ( trim(document.frmContact.txtName.value).length == 0 )
	{
		document.frmContact.txtName.className = 'input-error';
		document.frmContact.txtName.focus();
		document.frmContact.txtName.select();
		is_submit = false;
	}
	else
	{
		document.frmContact.txtName.className = 'input';
	}
	
	// Phone
	if ( trim(document.frmContact.txtPhone.value).length == 0 )
	{
		document.frmContact.txtPhone.className = 'input-error';
		document.frmContact.txtPhone.focus();
		document.frmContact.txtPhone.select();
		is_submit = false;
	}
	else
	{
		document.frmContact.txtPhone.className = 'input';
	}

	// Email
	if ( !emailCheck(document.frmContact.txtEmail.value) )
	{
		document.frmContact.txtEmail.className = 'input-error';
		document.frmContact.txtEmail.focus();
		document.frmContact.txtEmail.select();
		is_submit = false;
	}
	else
	{
		document.frmContact.txtEmail.className = 'input';
	}
	
	// Subject
	if ( trim(document.frmContact.txtSubject.value).length == 0 )
	{
		document.frmContact.txtSubject.className = 'input-error';
		document.frmContact.txtSubject.focus();
		document.frmContact.txtSubject.select();
		is_submit = false;
	}
	else
	{
		document.frmContact.txtSubject.className = 'input';
	}
	
	// security_code
	if ( trim(document.frmContact.security_code.value).length == 0 )
	{
		document.frmContact.security_code.className = 'input-error';
		document.frmContact.security_code.focus();
		document.frmContact.security_code.select();
		is_submit = false;
	}
	else
	{
		document.frmContact.security_code.className = 'input';
	}
	
	//
	if (is_submit)
	{
		document.frmContact.submit();
	}
}

function supportSubmit()
{
	var is_submit = true;
	
	if ( !emailCheck(document.frmSupport.txtEmail.value) )
	{
		document.frmSupport.txtEmail.className = 'input-error';
		document.frmSupport.txtEmail.focus();
		document.frmSupport.txtEmail.select();
		is_submit = false;
	}
	else
	{
		document.frmSupport.txtEmail.className = 'input';
	}
	
	if (is_submit)
	{
		document.frmSupport.submit();
	}
}

/* Products */
function getProducts()
{
	var area_url 		= 0;
	var group_url		= 0;
	var subgroup_url	= 0;
	var assortment_url	= 0;
	var firm_url		= 0;
	var type_url		= 0;
	var model_url		= 0;
	var color_url		= 0;
	
	if (document.getElementById('area_url'))
	{
		area_url = document.getElementById('area_url').value;
	}
	if (document.getElementById('group_url'))
	{
		group_url = document.getElementById('group_url').value;
	}
	if (document.getElementById('subgroup_url'))
	{
		subgroup_url = document.getElementById('subgroup_url').value;
	}
	if (document.getElementById('assortment_url'))
	{
		assortment_url = document.getElementById('assortment_url').value;
	}
	if (document.getElementById('firm_url'))
	{
		firm_url = document.getElementById('firm_url').value;
	}
	if (document.getElementById('type_url'))
	{
		type_url = document.getElementById('type_url').value;
	}
	if (document.getElementById('model_url'))
	{
		model_url = document.getElementById('model_url').value;
	}
	if (document.getElementById('color_url'))
	{
		color_url = document.getElementById('color_url').value;
	}
	document.location = SITE_ROOT + LANG + '/gproducts/' + area_url + '/' + group_url + '/' + subgroup_url + '/' + assortment_url + '/' + firm_url + '/' + type_url + '/' + model_url + '/' + color_url + '/';
}

function UserNameCheck(UserName)
{
	var UserNamePat = /^([a-zA-Z0-9._-]+)/;	
	var matchArray = UserName.match(UserNamePat);
	
	if ( matchArray == null )
	{
		return false;	
	}
	else if ( matchArray[0] != UserName )
	{
		return false;
	}
	else
	{
		return true;	
	}
}

function emailCheck(emailStr)
{
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format. It also is used to separate the username
	from the domain. */

	//var emailPat=/^(.+)@(.+)$/
	var emailPat=/^([a-zA-Z0-9._-]+)@(.+)$/;
	/* The following string represents the pattern for matching all special
	characters. We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	/* The following string represents the range of characters allowed in a 
	username or domainname. It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]";
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes). E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")";
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names. E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	/* The following string represents an atom (basically a series of
	non-special characters.) */
	var atom=validChars + '+';
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")";
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	
	/* Finally, let's start trying to figure out if the supplied address is
	valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)
	{
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		//alert("Wrong Email!");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	// See if "user" is valid 
	if (user.match(userPat)==null)
	{
		// user is not valid
		//alert("Wrong Email!");
		return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		// this is an IP address
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
				//alert("Wrong Email!");
				return false;
			}
		}
		return true;
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat);
	if (domainArray==null)
	{
		//alert("Wrong Email!");
		return false;
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	three-letter word (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	
	/* Now we need to break up the domain to get a count of how many atoms
	it consists of. */
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
	{
		// the address must end in a two letter or three letter word.
		//alert("Wrong Email!");
		return false;
	}
	
	// Make sure there's a host name preceding the domain.
	if (len<2)
	{
		//alert("Wrong Email!");
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}

function showGalleryImage(img)
{
	obj = document.getElementById('image_big');

	if (obj)
	{
		obj.src = SITE_ROOT + 'thumbnails/images/gallery/550x412/0/0/' + img + '';
	}
}

function loginFocus(obj)
{
	if ( !obj.init )
	{
		obj.initValue = obj.value;
		obj.value = '';
		obj.init  = true;
	}
	else if ( obj.value == obj.initValue )
	{
		obj.value = '';
	}
}

function loginBlur(obj)
{
	if ( obj.value == '' )
	{
		obj.value = obj.initValue;
	}
}

function loginPasswordFocus(obj)
{
	obj.style.display = 'none';
	
	if (obj.type && obj.type == 'text')
	{
		obj_1 = document.getElementById('login_password');
	}
	else
	{
		obj_1 = document.getElementById('login_password_text');
	}
	obj_1.style.display = 'block';
	obj_1.focus();
}

function loginPasswordBlur(obj)
{
	if (obj.type && obj.type == 'text')
	{
		obj.style.display = 'none';
		obj_1 = document.getElementById('login_password');
		obj_1.style.display = 'block';
	}
	else
	{
		if (obj.value == '')
		{
			obj.style.display = 'none';
			obj_1 = document.getElementById('login_password_text');
			obj_1.style.display = 'block';
		}
	}
}

function signupStep1()
{
	var is_submit = true;
	
	// txtFirstName
	if ( trim(document.frmSignUp.txtFirstName.value).length == 0 )
	{
		document.frmSignUp.txtFirstName.className = 'input-error';
		document.frmSignUp.txtFirstName.focus();
		document.frmSignUp.txtFirstName.select();
		is_submit = false;
	}
	else
	{
		document.frmSignUp.txtFirstName.className = 'input';
	}
	
	// txtLastName
	if ( trim(document.frmSignUp.txtLastName.value).length == 0 )
	{
		document.frmSignUp.txtLastName.className = 'input-error';
		document.frmSignUp.txtLastName.focus();
		document.frmSignUp.txtLastName.select();
		is_submit = false;
	}
	else
	{
		document.frmSignUp.txtLastName.className = 'input';
	}
	
	// txtEmail
	if ( !emailCheck(document.frmSignUp.txtEmail.value) )
	{
		document.frmSignUp.txtEmail.className = 'input-error';
		document.frmSignUp.txtEmail.focus();
		document.frmSignUp.txtEmail.select();
		is_submit = false;
	}
	else
	{
		document.frmSignUp.txtEmail.className = 'input';
	}
	
	// ddlOperator
	if ( document.frmSignUp.ddlOperator.value == 0 )
	{
		document.frmSignUp.ddlOperator.focus();
		is_submit = false;
	}

	//
	if (is_submit)
	{
		document.frmSignUp.submit();
	}
}

function signupStep3()
{
	var is_submit = true;
	
	verifyFormField(document.frmSignUp.txtFirstName) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmSignUp.txtLastName) == false ? is_submit = false : is_submit = is_submit;
	verifyFormEmailField(document.frmSignUp.txtEmail) == false ? is_submit = false : is_submit = is_submit;
	
	// ddlOperator
	if ( document.frmSignUp.ddlOperator.value == 0 )
	{
		document.frmSignUp.ddlOperator.focus();
		is_submit = false;
	}
	
	verifyFormConfirmField(document.frmSignUp.txtEmail, document.frmSignUp.txtConfirmEmail) == false ? is_submit = false : is_submit = is_submit;
	verifyFormUsernameField(document.frmSignUp.txtUserName) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmSignUp.txtPassword) == false ? is_submit = false : is_submit = is_submit;
	verifyFormConfirmField(document.frmSignUp.txtPassword, document.frmSignUp.txtConfirmPassword) == false ? is_submit = false : is_submit = is_submit;
	
	//
	if (is_submit)
	{
		document.frmSignUp.submit();
	}
}

function signupStep4()
{
	var is_submit = true;
	
	verifyFormField(document.frmPayment.txtCreditCardName) == false ? is_submit = false : is_submit = is_submit;
	
	// ddlCreditCard
	if ( document.frmPayment.ddlCreditCard.value == 0 )
	{
		document.frmPayment.ddlCreditCard.focus();
		is_submit = false;
	}
	
	// ddlCreditCardExpireMonth
	if ( document.frmPayment.ddlCreditCardExpireMonth.value == 0 )
	{
		document.frmPayment.ddlCreditCardExpireMonth.focus();
		is_submit = false;
	}
	
	// ddlCreditCardExpireYear
	if ( document.frmPayment.ddlCreditCardExpireYear.value == 0 )
	{
		document.frmPayment.ddlCreditCardExpireYear.focus();
		is_submit = false;
	}
	
	verifyFormField(document.frmPayment.txtCreditCardNumber) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmPayment.txtCreditCardCode) == false ? is_submit = false : is_submit = is_submit;
	
	verifyFormField(document.frmPayment.txtBillingFirstName) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmPayment.txtBillingLastName) == false ? is_submit = false : is_submit = is_submit;
	
	// ddlBillingCountry
	if ( document.frmPayment.ddlBillingCountry.value == 0 )
	{
		document.frmPayment.ddlBillingCountry.focus();
		is_submit = false;
	}
	
	verifyFormField(document.frmPayment.txtBillingCity) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmPayment.txtBillingStreet) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmPayment.txtBillingZIP) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmPayment.txtBillingPhone) == false ? is_submit = false : is_submit = is_submit;
	
	if ( !document.frmPayment.chkPolicy.checked )
	{
		document.frmPayment.chkPolicy.focus();
		is_submit = false;
	}
	
	if ( !document.frmPayment.chkTerms.checked )
	{
		document.frmPayment.chkTerms.focus();
		is_submit = false;
	}
	
	// 
	if (is_submit)
	{
		document.frmPayment.submit();
	}
}

// Проверка поля в форме
function verifyFormField(field)
{
	if (field)
	{
		if ( trim(field.value).length == 0 )
		{
			field.className = 'input-error';
			field.focus();
			field.select();
			return false;
		}
		else
		{
			field.className = 'input';
			return true;
		}
	}
	return false;
}

// Проверка поля Email в форме
function verifyFormEmailField(field)
{
	if (field)
	{
		if ( !emailCheck(field.value) )
		{
			field.className = 'input-error';
			field.focus();
			field.select();
			return false;
		}
		else
		{
			field.className = 'input';
			return true;
		}
	}
	return false;
}

// Проверка поля Username в форме
function verifyFormUsernameField(field)
{
	if (field)
	{
		if ( !UserNameCheck(field.value) )
		{
			field.className = 'input-error';
			field.focus();
			field.select();
			return false;
		}
		else
		{
			field.className = 'input';
			return true;
		}
	}
	return false;
}

// Проверка совпадения 2-х полей в форме
function verifyFormConfirmField(field, confirm_field)
{
	if (field && confirm_field)
	{
		if ( trim(field.value) != trim(confirm_field.value) )
		{
			confirm_field.className = 'input-error';
			confirm_field.focus();
			confirm_field.select();
			return false;
		}
		else
		{
			confirm_field.className = 'input';
			return true;
		}
	}
	return false;
}

function signupSelectOperator()
{
	var operator_id = document.getElementById('ddlOperator').value;
	if (operator_id != '0')
	{
		destination.push('skuku_operetor_status');
		script_name = SITE_ROOT + "ajax.php?lang=" + LANG;
		ajax_req = 'switch=skuku_operetor_status&operator_id=' + operator_id;
		cache.push(ajax_req);
		getAjaxRequest();
	}
	else
	{
		document.getElementById('skuku_operetor_status').innerHTML = 'Choose your network operator / country';
	}
}

function setProductsQuantity(id, action)
{
	var obj = document.getElementById(id);
	if (obj)
	{
		if (isNaN(obj.value))
		{
			obj.value = 1;
		}
		
		if (action == '-' && parseInt(obj.value) > 1)
		{
			obj.value = parseInt(obj.value) - 1;
		}
		else if (action == '+')
		{
			obj.value = parseInt(obj.value) + 1;
		}
	}
}

// Refresh DIV to show Shopping Cart
function showShoppingCart()
{
	var obj = document.getElementById('shopping_cart');
	if (obj)
	{
		destination.push('shopping_cart');
		script_name = SITE_ROOT + "ajax.php?lang=" + LANG;
		ajax_req = 'switch=b2b_shopping_cart';
		cache.push(ajax_req);
		getAjaxRequest();
	}
}

//
function OrderNow(product_id)
{
	
}

// Add selected product to Shopping Cart
function addToShoppingCart(product_id, obj)
{
	//if ( confirm('Add to Shopping Cart ?') )
	//{
		var quantity = 1;

		if ( document.getElementById('product_qty_' + product_id) )
		{
			quantity = parseInt(document.getElementById('product_qty_' + product_id).value);
		}

		destination.push('shopping_cart');
		script_name = SITE_ROOT + "ajax.php?lang=" + LANG;
		ajax_req = 'product_id=' + product_id + '&quantity=' + quantity + '&switch=b2b_addToShoppingCart';
		cache.push(ajax_req);
		getAjaxRequest();

		// Refresh Shopping Cart
		showShoppingCart();

		var posLeft = $(obj).position().left;
		var objW = $(obj).width();
		var stickW = 230;

		if (objW > stickW)
		{
			posLeft = posLeft + (objW - stickW)/2;
		}
		else
		{
			posLeft = posLeft - (stickW - objW)/2;
		}

		$.stickr({
			note:'Товар добавлен в корзину',
			className:'classic',
			position:{
				left:posLeft,
				top:$(obj).position().top-72},
			time:2000,
			speed:300
		});

	//}
}

// Remove product from shopping cart
function removeFromShoppingCart(cart_id)
{
	//if ( confirm('Remove from Shopping Cart ?') )
	//{
		destination.push('shopping_cart');
		script_name = SITE_ROOT + "ajax.php?lang=" + LANG;
		ajax_req = 'cart_id=' + cart_id + '&switch=b2b_removeFromShoppingCart';
		cache.push(ajax_req);
		getAjaxRequest();
		
		// Refresh Shopping Cart
		showShoppingCart();
	//}
}

//
function getCountryZones(obj, div, sw)
{
	var country_id = parseInt(obj.value);
	
	destination.push(div);
	script_name = SITE_ROOT + "ajax.php?lang=" + LANG;
	ajax_req = 'country_id=' + country_id + '&switch=' + sw;
	cache.push(ajax_req);
	getAjaxRequest();
}

//
function copyBillingAddress(obj)
{
	if (obj.checked)
	{
		document.frmPayment.txtShippingFirstName.value = document.frmPayment.txtBillingFirstName.value;
		document.frmPayment.txtShippingLastName.value = document.frmPayment.txtBillingLastName.value;
		document.frmPayment.txtShippingCity.value = document.frmPayment.txtBillingCity.value;
		document.frmPayment.txtShippingStreet.value = document.frmPayment.txtBillingStreet.value;
		document.frmPayment.txtShippingZIP.value = document.frmPayment.txtBillingZIP.value;
		document.frmPayment.txtShippingPhone.value = document.frmPayment.txtBillingPhone.value;
		
		document.frmPayment.ddlShippingCountry.selectedIndex = document.frmPayment.ddlBillingCountry.selectedIndex;
		
		var country_id = document.frmPayment.ddlBillingCountry.value;
		var sw = 'b2b_payment_shipping_state';
		
		destination.push('div_shipping_state');
		script_name = SITE_ROOT + "ajax.php?lang=" + LANG;
		ajax_req = 'country_id=' + country_id + '&switch=' + sw;
		cache.push(ajax_req);
		getAjaxRequest();
		
		//document.frmPayment.ddlShippingState.selectedIndex = document.frmPayment.ddlBillingState.selectedIndex;
		
	}
}



function loginSubmit()
{
	var is_submit = true;
	
	verifyFormField(document.frmLogin.login_username) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmLogin.login_password) == false ? is_submit = false : is_submit = is_submit;
	
	return is_submit;
}

function createAccountSubmit()
{
	var is_submit = true;
	
	verifyFormField(document.frmRegistration.txtFirstName) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmRegistration.txtLastName) == false ? is_submit = false : is_submit = is_submit;
	verifyFormEmailField(document.frmRegistration.txtEmail) == false ? is_submit = false : is_submit = is_submit;
	
	if ( document.frmRegistration.txtUserName )
	{
		verifyFormUsernameField(document.frmRegistration.txtUserName) == false ? is_submit = false : is_submit = is_submit;
		verifyFormField(document.frmRegistration.txtPassword) == false ? is_submit = false : is_submit = is_submit;
		verifyFormConfirmField(document.frmRegistration.txtPassword, document.frmRegistration.txtConfirmPassword) == false ? is_submit = false : is_submit = is_submit;
	}	
	
	return is_submit;
}

function registrationSubmit()
{
	var is_submit = true;
	
	verifyFormField(document.frmRegistration.txtFirstName) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmRegistration.txtLastName) == false ? is_submit = false : is_submit = is_submit;
	verifyFormEmailField(document.frmRegistration.txtEmail) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmRegistration.txtPhoneCell) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmRegistration.txtCity) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmRegistration.txtAddress) == false ? is_submit = false : is_submit = is_submit;
	
	if ( document.frmRegistration.txtUserName )
	{
		verifyFormUsernameField(document.frmRegistration.txtUserName) == false ? is_submit = false : is_submit = is_submit;
		verifyFormField(document.frmRegistration.txtPassword) == false ? is_submit = false : is_submit = is_submit;
		verifyFormConfirmField(document.frmRegistration.txtPassword, document.frmRegistration.txtConfirmPassword) == false ? is_submit = false : is_submit = is_submit;
	}	
	
	return is_submit;
}

function OrderNowSubmit()
{
	var is_submit = true;

	verifyFormField(document.frmOrderNow.txtFirstName) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmOrderNow.txtLastName) == false ? is_submit = false : is_submit = is_submit;
	verifyFormEmailField(document.frmOrderNow.txtEmail) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmOrderNow.txtPhoneCell) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmOrderNow.txtCity) == false ? is_submit = false : is_submit = is_submit;
	verifyFormField(document.frmOrderNow.txtAddress) == false ? is_submit = false : is_submit = is_submit;

	return is_submit;
}


function showGalleryCaruselImage(id, url)
{
	var big_image = document.getElementById('gallery_carusel_image');
	var big_image_url = document.getElementById('gallery_carusel_image_url');

	if (big_image && big_image_url)
	{
		big_image.src = SITE_ROOT + 'thumbnails/images/gallery/300x225/0/0/' + id + '';
		big_image_url.href = url;
	}

}

function OpenMenu(id)
{
	if ( document.getElementById('menu_' + id) )
	{
		if ( document.getElementById('menu_' + id).open )
		{
			document.getElementById('menu_' + id).style.display = 'none';
			document.getElementById('menu_icon_' + id).src = TPL_PATH +'images/icon_help_close.gif';
			document.getElementById('menu_bullet_' + id).src = TPL_PATH + 'images/icon_tree_close.gif';
		}
		else
		{
			document.getElementById('menu_' + id).style.display = 'block';
			document.getElementById('menu_icon_' + id).src = TPL_PATH + 'images/icon_help_open.gif';
			document.getElementById('menu_bullet_' + id).src = TPL_PATH + 'images/icon_tree_open.gif';
		}
		
		document.getElementById('menu_' + id).open = !document.getElementById('menu_' + id).open;
	}
}

function goSearch(objForm)
{
	document.location = SITE_ROOT + LANG + '/search/?q=' + encodeURIComponent(objForm.q.value);
	return false;
}

function homeCollageSelect(obj)
{
	menu = document.getElementById('home-collage-menu');
	items = menu.getElementsByTagName('li');

	for (i = 0; i < items.length; i++)
	{
		n = i + 1;
		image = document.getElementById('home-collage-image-0' + n);

		if (items[i] == obj)
		{
			items[i].className = 'selected';
			items[i].backgroundImage = TPL_PATH + 'images/home_collage_menu_0' + n + '_selected.png';
			image.style.display = 'block';
			homeCollageSelectedItem = n;
		}
		else
		{
			items[i].className = '';
			items[i].backgroundImage = TPL_PATH + 'images/home_collage_menu_0' + n + '.png';
			image.style.display = 'none';
		}
	}
}

function selectPage(block_paging_id, block_content_id, obj, page)
{
    var block = document.getElementById(block_paging_id);
    if (block)
    {
        var items = block.getElementsByTagName('li');
        for(i=0; i<items.length; i++)
        {
            var item = items[i];
            if (trim(item.className) != 'next-page' && trim(item.className) != 'prev-page')
            {
                var links = item.getElementsByTagName('a');
                var link = links[0];
                if (link && link == obj)
                {
                    // Selected item
                    item.className = 'selected';
                }
                else
                {
                    item.className = '';
                }
            }
		}
    }

    var articlesContent = document.getElementById(block_content_id);
    if (articlesContent)
    {
        var articles = articlesContent.getElementsByTagName('li');
        for (i=0; i<articles.length; i++)
        {
            var article = articles[i];
            if (article.className.indexOf('page-') > -1)
            {
            	if (trim(article.className) == trim('page-' + page) || trim(article.className) == trim('page-' + page) + ' big-template')
                {
                    article.style.display = 'block';
                }
                else
                {
                    article.style.display = 'none';
                }
            }
        }
    }
}

function nextPage(block_paging_id, block_content_id)
{
    var page = 1;
    var pages = 0;

    var block = document.getElementById(block_paging_id);
    if (block)
    {
        var items = block.getElementsByTagName('li');
        for(i=0; i<items.length; i++)
        {
            var item = items[i];
            if (trim(item.className) != 'next-page' && trim(item.className) != 'prev-page')
            {
                var links = item.getElementsByTagName('a');
                var link = links[0];
                pages++;

                if (item.className == 'selected')
                {
                    page = parseInt(link.className.replace('page-', ''));
                }
            }
        }

        var next_page = page + 1;
        if (next_page <= pages)
        {
            for(i=0; i<items.length; i++)
            {
                var item = items[i];
                if (trim(item.className) != 'next-page' && trim(item.className) != 'prev-page')
                {
                    var links = item.getElementsByTagName('a');
                    var link = links[0];
                    if (trim(link.className) == trim('page-' + next_page))
                    {
                        item.className = 'selected';
                    }
                    else
                    {
                        item.className = '';
                    }
                }
            }

            var articlesContent = document.getElementById(block_content_id);
            if (articlesContent)
            {
                var articles = articlesContent.getElementsByTagName('li');
                for (i=0; i<articles.length; i++)
                {
					var article = articles[i];
					//if (trim(article.className) == trim('page-' + next_page))
					if (trim(article.className) == trim('page-' + next_page) || trim(article.className) == trim('page-' + next_page) + ' big-template')
                    {
                        article.style.display = 'block';
                    }
                    else
                    {
                        article.style.display = 'none';
                    }
                }
            }
        }
    }
}

function prevPage(block_paging_id, block_content_id)
{
    var page = 1;
    var pages = 0;

    var block = document.getElementById(block_paging_id);
    if (block)
    {
        var items = block.getElementsByTagName('li');
        for(i=0; i<items.length; i++)
        {
            var item = items[i];
            if (trim(item.className) != 'next-page' && trim(item.className) != 'prev-page')
            {
                var links = item.getElementsByTagName('a');
                var link = links[0];
                pages++;

                if (item.className == 'selected')
                {
                    page = parseInt(link.className.replace('page-', ''));
                }
            }
        }

        var prev_page = page - 1;
        if (prev_page >= 1)
        {
            for(i=0; i<items.length; i++)
            {
                var item = items[i];
                if (trim(item.className) != 'next-page' && trim(item.className) != 'prev-page')
                {
                    var links = item.getElementsByTagName('a');
                    var link = links[0];
					if (trim(link.className) == trim('page-' + prev_page))
                    {
                        item.className = 'selected';
                    }
                    else
                    {
                        item.className = '';
                    }
                }
            }

            var articlesContent = document.getElementById(block_content_id);
            if (articlesContent)
            {
                var articles = articlesContent.getElementsByTagName('li');
                for (i=0; i<articles.length; i++)
                {
                    var article = articles[i];
                    //if (trim(article.className) == trim('page-' + prev_page))
                    if (trim(article.className) == trim('page-' + prev_page) || trim(article.className) == trim('page-' + prev_page) + ' big-template')
                    {
                        article.style.display = 'block';
                    }
                    else
                    {
                        article.style.display = 'none';
                    }
                }
            }
        }
    }
}


function fieldFocus(obj)
{
	if ( !obj.init )
	{
		obj.initValue = obj.value;
		obj.value = '';
		obj.init = true;
	}
	else if ( obj.value == obj.initValue )
	{
		obj.value = '';
	}
}

function fieldBlur(obj)
{
	if ( obj.value == '' )
	{
		obj.value = obj.initValue;
	}
}

function toggleFAQ(id)
{
	var faq = document.getElementById('faq_' + id);
	if (faq)
	{
		if (faq.open)
		{
			faq.className = 'faq-container';
		}
		else
		{
			faq.className = 'faq-container selected';
		}
		faq.open = !faq.open;
	}
}

function homeCollageAnimation()
{
	if (isHCA)
	{
		menu = document.getElementById('home-collage-menu');
		items = menu.getElementsByTagName('li');

		for (i = 0; i < items.length; i++)
		{
			n = i + 1;
			image = document.getElementById('home-collage-image-0' + n);

			if ((homeCollageSelectedItem == items.length && n == 1) || (homeCollageSelectedItem < items.length && n == homeCollageSelectedItem + 1))
			{
				items[i].className = 'selected';
				items[i].backgroundImage = TPL_PATH + 'images/home_collage_menu_0' + n + '_selected.png';
				image.style.display = 'block';
				cn = n;
			}
			else
			{
				items[i].className = '';
				items[i].backgroundImage = TPL_PATH + 'images/home_collage_menu_0' + n + '.png';
				image.style.display = 'none';
			}
		}

		homeCollageSelectedItem = cn;
	}
	setTimeout(homeCollageAnimation, 3000);
}

function homeCollageOver()
{
	isHCA = false;
}

function homeCollageOut()
{
	isHCA = true;
}

function quickRequestChange()
{
	if ($('#ddlInsuranceType').val() == 'ddlInsuranceServices')
	{
		$('#ddlFinancialServices').hide();
		$('#ddlInsuranceServices').show();
	}
	else
	{
		$('#ddlInsuranceServices').hide();
		$('#ddlFinancialServices').show();
	}
}


