var $jq = jQuery.noConflict();

$jq(document).ready(
    function () {                            
        //AddFancyCheckBoxesAndRadioButtons();
        //imageScroller();
        hideFields();
        popup();
    }
);

function AddFancyCheckBoxesAndRadioButtons(){
    $jq('input[type="radio"]').ezMark();
    $jq('input[type="checkbox"]').ezMark();
}

function moveOnMax(field,nextFieldID){
  if(field.value.length >= field.maxLength){
    document.getElementById(nextFieldID).focus();
  }
}

function pasteall(){
    allrows = window.clipboardData.getData('text').split('\n');
    for (var i=0;i<allrows.length;i++){
        textrow='text'+(i+1);
        document.getElementById(textrow).innerText=allrows[i]
    }
}


function hideFields(){
    if ($jq('#kidsBirthday').length != 0) {
	    var kidsBirthday = document.getElementById('kidsBirthday');
	    kidsBirthday.style.display = 'none';
	}
	if ($jq('#expectedBirthday').length != 0) {
        var expectedBirthday = document.getElementById('expectedBirthday');
	    expectedBirthday.style.display = 'none';
	}
	if ($jq('#actionConditions').length != 0) {
        var actionConditions = document.getElementById('actionConditions');
	    actionConditions.style.display = 'none';
	}
	else{
        //do nothing
	}
}



function dateYearBlur(id){
	var optionsDiv2 = document.getElementById('optionsDiv'+id);
    var sarea2 = document.getElementById('sarea' + id);
	optionsDiv2.style.left = findPosX(sarea2) + 'px';
	optionsDiv2.style.top = findPosY(sarea2) + selectAreaHeight - selectAreaOptionsOverlap + 'px';

}

function showKidsBirthDay(){
    var kidsBirthday = document.getElementById('kidsBirthday');
	kidsBirthday.style.display = 'block';
}

function hideKidsBirthDay(){
	var kidsBirthday = document.getElementById('kidsBirthday');
	kidsBirthday.style.display = 'none';
}

function showExpectedBirthDay(){
    var expectedBirthday = document.getElementById('expectedBirthday');
	expectedBirthday.style.display = 'block';
}

function hideExpectedBirthDay(){
	var expectedBirthday = document.getElementById('expectedBirthday');
	expectedBirthday.style.display = 'none';
}

function showActionConditions(){
    var actionConditions = document.getElementById('actionConditions');
	actionConditions.style.display = 'block';
}

function hideActionConditions(){
	var actionConditions = document.getElementById('actionConditions');
	actionConditions.style.display = 'none';
}


//Image rotator

var stor = -1;
var maxstor = 4;
var timeout = 3500;

function imageScroller(){
    if ($jq('#storyContainer').length != 0) {
        showNext();
        //timeout = setTimeout('imageScroller();', timeout);
    } 
    else{
        //do nothing
    }
}

function rotateDiv(stor){
    var divs = document.getElementById("storyContainer").getElementsByTagName("img");
    for (var i=0; i < divs.length; i++ ) {
        var div = divs[i];
        if ( (div.id != "")) {
	        if(i != stor){
        	        div.style.display = "none";
	        }
	        else{
		        div.style.display = "block";
	        }
        }
    }
}

function showNext(){
	var buttonNext = document.getElementById('Next');
    var buttonPrevious = document.getElementById('Previous');
    
	if(stor < maxstor){
		stor++;
		buttonPrevious.style.visibility = "visible";
    }
    if(stor <= 0){
		buttonPrevious.style.visibility = "hidden";
    }
    if(stor == maxstor){
	    buttonNext.style.visibility = "hidden";
	}
	rotateDiv(stor);
}

function showPrev(){
	var buttonNext = document.getElementById('Next');
    var buttonPrevious = document.getElementById('Previous');
	
	if(stor > 0){
		stor--;
		buttonNext.style.visibility = "visible";
	}
	if(stor == 0){
	    buttonPrevious.style.visibility = "hidden";
	}
	rotateDiv(stor);
}

//Text area default text.

$jq(function () {
    $jq('textarea').each(function () {
        $jq.data(this, 'default', this.value);
    }).focus(function() {
        if (!$jq.data(this, 'edited')) {
            this.value = "";
        }
    }).change(function() {
        $jq.data(this, 'edited', this.value != "");
    }).blur(function() {
        if (!$jq.data(this, 'edited')) {
            this.value = $jq.data(this, 'default');
        }
    });
});

//Dates default text

function dateDayFocus(field){
    if (field.value == field.defaultValue){
        field.value ='';
        }
    field.className="tbxDay loginEmail"
}

function dateDayBlur(field){
    if (field.value == ''){
        field.value = field.defaultValue;
        field.className="tbxDay1";
    }
    else{
        field.className="tbxDay";
    }
}

function dateMonthFocus(field){
    if (field.value == field.defaultValue){
        field.value ='';
        }
    field.className="tbxMonth"
}

function dateMonthBlur(field){
    if (field.value == ''){
        field.value = field.defaultValue;
        field.className="tbxMonth1";
    }
    else{
        field.className="tbxMonth";
    }
}

function popup() {
    if ($jq('#popupNewsletter').length != 0) {
        $jq("#popupNewsletter").fancybox({
	        'titlePosition'		: 'inside',
	        'transitionIn'		: 'none',
	        'transitionOut'		: 'none'
        });
	}
	if ($jq('#popupExtraProfidMail').length != 0) {
	    $jq("#popupExtraProfidMail").fancybox({
	        'titlePosition': 'inside',
	        'transitionIn': 'none',
	        'transitionOut': 'none'
	    });
	}
	if ($jq('#popupLoginValidation').length != 0) {
	    $jq("#popupLoginValidation").fancybox({
	        'titlePosition': 'inside',
	        'transitionIn': 'none',
	        'transitionOut': 'none'
	    });
	}
}

