﻿// JScript File

function selectListCR(){
var a = document.getElementsByTagName('a')
	for(var i=0;i<a.length;i++) {
		if(a[i].className == 'activeClick'){
			a[i].style.zIndex = 1;
		a[i].onclick = function(){
			for(var i=0;i<a.length;i++) {
				if(a[i].className == 'activeClick'){
					a[i].style.color = '#0155d2'
					a[i].style.background = ''
					a[i].style.zIndex = '1'
				}
			}
			this.style.background = '#353535'
			this.style.color = '#fff'
			this.style.zIndex = '2'
		}
		a[i].onmouseover = function(){
			if(this.style.zIndex != 2){
			this.style.color = '#fff'
			this.style.background = '#353535'
			}
		}
		a[i].onmouseout = function(){
			if(this.style.zIndex != 2){
			this.style.color = '#0155d2'
			this.style.background = ''
			}
		}
		}
	}
	
	
var d = document.getElementsByTagName('div')
	for(var i=0;i<d.length;i++) {
		if(d[i].className == 'actListCR'){
			d[i].style.zIndex = 1;
			d[i].onmouseover = function(){
				if(this.style.zIndex != 2){
				this.style.background = 'url(content/img/vkladkaCR2.gif) top left no-repeat'
				this.style.color = '#353535'
				}
			}
			d[i].onmouseout = function(){
				if(this.style.zIndex != 2){
				this.style.background = 'url(content/img/vkladkaCR1.gif) top left no-repeat'
				this.style.color = '#fff'
				}
			}
			d[i].onclick = function(){
				for(var i=0;i<d.length;i++) {
					if(d[i].className == 'actListCR'){
					d[i].style.background = 'url(content/img/vkladkaCR1.gif) top left no-repeat'
					d[i].style.zIndex = 1;
					}
				}
				this.style.background = 'url(content/img/vkladkaCR3.gif) top left no-repeat'
				this.style.color = '#fff'
				this.style.zIndex = 2;
			}
		}
	}
}


// главное что работает. надеюсь работает
var maxWidth = 0;
var startMenu = 0;
var menuLeftpx = 0;
var flagius = 1;
function wisthSelBlock(p){
	if(flagius == 1){
var d = document.getElementsByTagName('div')
var selWidthBlock = document.getElementById('selectWidth')
	selWidthBlock.style.width = p.offsetWidth+'px'
	for(var i=0;i<d.length;i++) {
		if(d[i].className == 'floatMenu'){
			d[i].style.color = '#353535';
			maxWidth += d[i].offsetWidth
			startMenu += 1;
		}
	}
	thisMenu = parseInt(p.id)
	thisMenuId = p.id
	setTimeout(gotoMenu, 0)
	}
}
function gotoMenu(){
flagius = 2;
setConfnumb = 2;
var d = document.getElementsByTagName('div')
var selWidthBlock = document.getElementById('selectWidth')
	for(var i=0;i<d.length;i++) {
		if(d[i].className == 'floatMenu' && setConfnumb <= thisMenu){
			setConfnumb += 1;
			menuLeftpx += d[i].offsetWidth;
			menuLeftpx += 40;
		}
	}
	leftMarg = parseInt(selWidthBlock.style.left)
	if(leftMarg <= menuLeftpx){
	moveBgmenu1();
	}
	if(leftMarg > menuLeftpx){
	moveBgmenu2();
	}
}
var stepBg = 0;
var add = 0;
var int = 1;

function menuresize(){
var d = document.getElementsByTagName('div')
var selWidthBlock = document.getElementById('selectWidth')
	selWidthBlock.style.width = document.getElementById('1m').offsetWidth+'px'
	document.getElementById('1m').style.color = '#fff'
}

function moveBgmenu1(){
	flagius = 2;
var selWidthBlock = document.getElementById('selectWidth')
	leftMarg = parseInt(selWidthBlock.style.left)
	if(leftMarg <= menuLeftpx){
	int += 1;
	add += int;
	selWidthBlock.style.left = add+'px';
	setTimeout(moveBgmenu1, 10)
	}else{
		leftMarg = 0;
		flagius = 1;
		int = 1;
		selWidthBlock.style.left = menuLeftpx+'px'
		menuLeftpx = 0;
		document.getElementById(thisMenuId).style.color = '#fff';
	}
}
function moveBgmenu2(){
	flagius = 2;
var selWidthBlock = document.getElementById('selectWidth')
	leftMarg = parseInt(selWidthBlock.style.left)
	if(leftMarg >= menuLeftpx){
	int += 1;
	add -= int;
	selWidthBlock.style.left = add+'px';
	setTimeout(moveBgmenu2, 10)
	}else{
		leftMarg = 0;
		flagius = 1;
		int = 1;
		selWidthBlock.style.left = menuLeftpx+'px'
		menuLeftpx = 0;
		document.getElementById(thisMenuId).style.color = '#fff';
	}
}


function fillCalendar(elem)
{
    for (var i=1; i<32; i++)
    {
        var el = document.createElement('option');
        el.value = el.innerHTML = i.toString();
        elem.appendChild(el);
    }
}

function checkCalendar()
{
    var s_day = getEl("start_day");
    var s_month = getEl("start_month"); 
    var s_year = getEl("start_year");
    
    var e_day = getEl("end_day");
    var e_month = getEl("end_month");
    var e_year = getEl("end_year");
    
    var date1 = s_month.options[s_month.selectedIndex].value + '/' + s_day.options[s_day.selectedIndex].value + '/' + s_year.options[s_year.selectedIndex].value;
    var date2 = e_month.options[e_month.selectedIndex].value + '/' + e_day.options[e_day.selectedIndex].value + '/' + e_year.options[e_year.selectedIndex].value;
    
    
    if (ValidateForm(date1) && ValidateForm(date2))
        alert('с датами все ок');
    if (Date.parse(date2) < Date.parse(date1))
        alert('дата окончания не может быть раньше даты начала');
}


var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Пожалуйста, введите правильные даты поездки")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Пожалуйста, введите правильные даты поездки")
		return false
	}
return true
}

function ValidateForm(myDate){
	var dt = myDate;
	if (isDate(dt)==false){
		dt.focus()
		return false
	}
    return true
 }
 
 /////////
 ///////
 ///--------------
 
 
function galPhotoover(p){
     imgp = document.getElementById(p).style
     imgp.filter = 'alpha(opacity=50)'
     imgp.opacity = '0.5'
     imgp.MozOpacity = '0.5'
     dispBl = 'imgupp'+idnumbImg
     imgpDisp = document.getElementById(dispBl).style
     imgpDisp.display = 'block'
     dispBc = 'imgupc'+idnumbImg
     imgpDisc = document.getElementById(dispBc).style
     imgpDisc.display = 'block'
}
function galPhotoout(p){
     imgp = document.getElementById(p).style
     imgp.filter='alpha(opacity=100)'
     imgp.opacity = '1'
     imgp.MozOpacity = '1'
     dispBl = 'imgupp'+idnumbImg
     imgpDisp = document.getElementById(dispBl).style
     imgpDisp.display = 'none'     
     dispBc = 'imgupc'+idnumbImg
     imgpDisc = document.getElementById(dispBc).style
     imgpDisc.display = 'none'
}
function resizeTextArea(p){
     textArLenght = p.value.split(/[\r\n]/g).length
     p.style.height = textArLenght*14+'px'
     p.style.height = p.scrollHeight
}

     var arText = new Array();
     arText[0] = markupList['uspeh18'];
     arText[1] = markupList['uspeh17'];
     arText[2] = markupList['uspeh19'];
     arText[3] = markupList['uspeh20'];
     arText[4] = markupList['uspeh21'];
     
function focusArea(a){
     a.style.color = '#000'; 
     if(a.value == arText[0]  || a.value == arText[1]  || a.value == arText[2]  || a.value == arText[3] || a.value == arText[4])
     a.value = ''
}






