function confirmPassword(pass,confirmPass)	{
	if (pass.value == confirmPass.value)	{
		return true;
	}
	alert('Confirm password');
	pass.focus();
	return false;
}

function checkBindForm(object, name, msg)
{
	for (var nCount = 0; nCount < object.elements.length; nCount ++)
	{
		if (object.elements[nCount].name.indexOf(name) != -1 && object.elements[nCount].checked)
		{
			return true;
		}
	}
	alert(msg);
	return false;
}

function passwordEqualWraper(form,obj2,obj3,obj4)
{
	return validateShow(form,obj2) && confirmPassword(obj3,obj4);
}

function checkoutValidateWrapper(form) {
	var validateCheckoutForm = true;
	validateCheckoutForm = validateShow(form,CheckoutFormArr);
	if (false == validateCheckoutForm)
	return false;
	form.attributes['name'].value = 'ShippingForm';

	var shippingAsBilling = document.getElementById('shippingAsBilling');
	var validateShippingForm = true;
	if (true != shippingAsBilling.checked) {
		validateShippingForm = validateShow(form,ShippingFormArr);
		if (false == validateShippingForm)
		return false;
	}
	form.attributes['name'].value = 'PaymentInformationsForm';
	var payByCheck = document.getElementById('payByCheck');
	var paymentValidateForm = true;
	if (true != payByCheck.checked) {
		paymentValidateForm = validateShow(form,PaymentInformationsFormArr);
	}
	return paymentValidateForm;

}


function showPopUp()
{
	var win = window.open("pop_up.html", "", "width=500, height=300, menubar=0, resizable=0, scrollbars=0, status=0");
}
function unDisable(name)
{
	var tmp = document.getElementById(name);
	tmp.disabled = false;
}
function unDisableWrapper(name,form, obj2)
{
	var tmp = document.getElementById(name);
	tmp.disabled = false;
	return validateShow(form,obj2);
}

function checkDate() {
	var tmp = document.getElementById('eventStartDate').value;
	var date_from = new Date(tmp);

	var tmp2 = document.getElementById('eventEndDate').value;
	var date_to   = new Date(tmp2);

	if(date_to.getTime() < date_from.getTime())
	{
		alert("Incorect date interval! Start date must be less than End date");
		return false;
	}
	return true;

}
function checkDateWrapper(form,obj2) {
	return validateShow(form,obj2) && checkDate();
}

function checkDateInterval(firstDate,secondDate) {
	var tmp = document.getElementById(firstDate).value;
	var date_from = new Date(tmp);

	var tmp2 = document.getElementById(secondDate).value;
	var date_to   = new Date(tmp2);
	if(date_to.getTime() < date_from.getTime())
	{
		alert("Incorect date interval!");
		return false;
	}
	return true;

}


function checkDateItervalWrapper(form,obj2,firstDate,secondDate) {
	return validateShow(form,obj2) && checkDateInterval(firstDate,secondDate);
}



function validateRegistrationManagementForm(formObj,validateElem)
{
	var isError = false;
	var errorMessages = "Error: \r\n";
	for(var i=0;i<validateElem.length;i++) {
		if (!required(formObj, validateElem[i][0])) {
			isError = true;
			errorMessages += validateElem[i][1]+": Field is required \n\r";
		}
		//alert(customRegexp);
		if (!customRegexp(formObj, validateElem[i][0], '(0[1-9]|1[012])\/(([\\d]{2})|([12][\\d]{3}))\/([\\d]{4})'))	{
			isError = true;
			errorMessages += validateElem[i][1]+": Field must contain valid US format date \n\r";
		}
	}
	if(isError)
	{
		alert(errorMessages);
		return false;
	}
	return true;
}

function eventSearchFormValidateWrapper(form,obj2) {
	var date = document.getElementById('searchDate').value;
	if (date != '') {
		return validateShow(form,obj2);
	}
	return true;
}

function showFieldsProductForm(valueType) {
	if (valueType == 'downloaded') {
		document.getElementById('furnishedGroup').style.display = 'none';
		document.getElementById('downloadGroup').style.display = 'block';
	}
	else {

		document.getElementById('furnishedGroup').style.display = 'block';
		document.getElementById('downloadGroup').style.display = 'none';
	}
}

function showFieldsProductFormCategory(valueType) {
	if (valueType != 'whitepapers') {
		document.getElementById('categoryType').style.display = 'none';
		
	}
	else {
		document.getElementById('categoryType').style.display = 'block';
	}
	
	if ('books' == valueType) {
		//document.getElementById('otherSubCat').disabled = true;
		document.getElementById('other_sub_cat').style.display = 'none';
		
		//document.getElementById('bookSubCat').disabled = false;
		document.getElementById('book_sub_cat').style.display = 'block';		
	}else {
		//document.getElementById('otherSubCat').disabled = false;
		document.getElementById('other_sub_cat').style.display = 'block';
		
		//document.getElementById('bookSubCat').disabled = true;
		document.getElementById('book_sub_cat').style.display = 'none';		
	}
	
}

function showFieldsAdvertisementForm(valueType) {
	if (valueType == 'graphics') {
		document.getElementById('textGroup').style.display = 'none';
		document.getElementById('rssGroup').style.display = 'none';
		document.getElementById('graphicsGroup').style.display = 'block';
	}
	else
	if (valueType == 'text') {
		document.getElementById('graphicsGroup').style.display = 'none';
		document.getElementById('textGroup').style.display = 'block';
		document.getElementById('rssGroup').style.display = 'none';
	}
	else {
		document.getElementById('graphicsGroup').style.display = 'none';
		document.getElementById('textGroup').style.display = 'none';
		document.getElementById('rssGroup').style.display = 'block';
	}
}

function setAdsPlace(valueTemplateId) {
	ads = document.getElementsByName('ads');

	plaseSel = document.getElementById('adsId');
	while (plaseSel.options.length) {
		plaseSel.options[0] = null;
	}

	buf = new Array();
	bufVar = '0';
	j = 0;

	for (i = 0; i < ads.length; i++) {
		uniqueName = 'ads' + '_' + ads[i].value + '_' + valueTemplateId;
		uniqueId = document.getElementsByName(uniqueName);

		if ((typeof(uniqueId[0]) != 'undefined')) {
			if (bufVar != uniqueId[0].value) {
				buf[j] = uniqueId[0].value;
				bufVar = uniqueId[0].value;
				j++;
			}
		}
	}

	for (k = 0; k < buf.length; k++) {
		uniqueName = 'ads' + '_' + buf[k] + '_' + valueTemplateId + '_id';
		nameo = document.getElementsByName(uniqueName);
		plaseSel.options.add(new Option(nameo[0].value, buf[k], false, false));
	}

	if (!plaseSel.options.length) {
		plaseSel.options.add(new Option('no places', '', false, false));
	}
}
function setAdsBanner(valueUserId) {
	advertisements = document.getElementsByName('advertisement');
	bannerSel = document.getElementById('advertisementId');

	while (bannerSel.options.length) {
		bannerSel.options[0] = null;
	}

	for (i = 0; i < advertisements.length; i++) {
		uniqueName = 'advertisement' + '_' + advertisements[i].value;
		uniqueId = document.getElementsByName(uniqueName);

		if (uniqueId[0].value == valueUserId) {
			uniqueName = 'advertisement' + '_' + advertisements[i].value + '_id';
			uniqueId = document.getElementsByName(uniqueName);
			bannerSel.options.add(new Option(advertisements[i].value, uniqueId[0].value, false, false));
		}
	}

	if (!bannerSel.options.length) {
		bannerSel.options.add(new Option('no banners', '', false, false));
	}
}

function writeVideoObject(scr) {
	document.write("<OBJECT  ID='mediaPlayer' width='320' height='330' CODEBASE='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' STANDBY='Loading Microsoft Windows Media Player components...'  TYPE='application/x-oleobject'>");
	document.write("<PARAM NAME='url' VALUE='"+scr+"}'/>");
	document.write("<PARAM NAME='autoStart' VALUE='true'/>");
	document.write("<PARAM NAME='showControls' VALUE='true'/>");
	document.write("<PARAM NAME='TransparentatStart' VALUE='false'/>");
	document.write("<PARAM NAME='AnimationatStart' VALUE='true'/>");
	document.write("<PARAM NAME='StretchToFit' VALUE='true'/>");
	document.write("<EMBED src='{$videoUrl}' type='application/x-mplayer2' name='mediaPlayer' autostart='1' showcontrols='1' showstatusbar='1' autorewind='1' width='320' height='309'></EMBED>");
	document.write("</OBJECT>");
}

var ads_place = new Array();
var advert_show_index = new Array();

function showBaners()
{	
	for(var i = 0; i < ads_place.length; i++)
	{
		if (ads_place[i] instanceof Array) 
		{
			for (var j = 0; j < ads_place[i].length; j++)
			{
				$("div."+ads_place[i][j]).hide();				
			}			
			if (advert_show_index[i] >= ads_place[i].length)
			{
				advert_show_index[i] = 0;				
			}
			$("div."+ads_place[i][advert_show_index[i]]).show();
			advert_show_index[i] += 1;					
		}	
	}	
}
try
{
	$(document).ready(showBaners);
	setInterval("showBaners()",30000);
}
catch(err)
{
}