// Get Screen Topmost Position
function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;}

// Sroll Page Up Smoothly
var scrolldelay;
function pageScroll() {
	if (posTop() > 130){
	window.scrollBy(0,-18); 
	scrolldelay = setTimeout('pageScroll()',20); 
	}else{
	clearTimeout(scrolldelay);
	}
}

// Image Streamer
var t;
var current = 0;

function imageFlow(source){

	var imageid = 'pim_'+source;
	var inputid = 'pis_'+source;
	
	var imagestring = document.getElementById(inputid).value;
	var images = imagestring.split('-');
	var limit = images.length - 1;
	
	t = setTimeout('document.getElementById(\'' + imageid + '\').src = \'fileshack/pictures/C' + images[current] + '.jpg\';imageFlow(\'' + source + '\');',1200);
	current ++;
	if(current == limit){
	current = 0;
	}
	
}

function imageFlow_halt(){
	
	current = 0;
	clearTimeout(t);
	
}

function safeLocate(target, message){

	answer = confirm(message)

	if(answer){
	window.location = target;
	}
	else{
	a = 1;
	}

}

function toggleMenu(id){

box = document.getElementById(id);
sts = box.style.display;

	if(!sts || sts == 'none'){
	box.style.display = 'none';
	box.style.display = 'block';
	}else{
	box.style.display = 'none';
	}

}

function swapReport(){
	
	var source = document.getElementById('report_s1512');
	var target = document.getElementById('report_box');
	
	if(source && target){
		var a = source.innerHTML
		if(a != ""){
		message = a.split(",");
		target.innerHTML = message[1];
		target.style.display = "block";
		target.className = "report_" + message[0];
		}else{
		target.innerHTML = "";
		target.style.display = "none";
		}
	}
	
	pageScroll();
	
}

function ajax(){
    var xmlHttp=null;
    try{
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }catch(e){
        // Internet Explorer
        try{
            xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
        }catch(e){
            xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
        }
    }
    return xmlHttp;
}

function generateCityfield(){

	xmlHttp = ajax();
	if (xmlHttp == null){
	alert ('Tarayıcınız Ajax Desteklemiyor!');
	return;
	}
	
	var selector = document.getElementById('ctryfield');
	var value = selector.options[selector.selectedIndex].value;
	if(value == 'Türkiye'){
		var url = 'templates/ajax/s_cities_tr.txt';
		document.getElementById('cityfield_folder').innerHTML='<img src="visual/images/other/spinner.gif" alt="" />';
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState==4){
			document.getElementById('cityfield_folder').innerHTML=xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}else{
	if(document.getElementById('cityfield').type == 'select-one')
	document.getElementById('cityfield_folder').innerHTML='<input class="single_input" name="formInfo_city" id="cityfield" />';
	}

}

function lockCmcfields(){

	document.getElementById('nottcfield').disabled = false;
	
	document.getElementById('tdnumfield').disabled = false;
	document.getElementById('tdnumfield').style.backgroundColor = '#F0F0F0';
	
	document.getElementById('nsnmfield').disabled = false;
	document.getElementById('nsnmfield').style.backgroundColor = '#F0F0F0';
	
	document.getElementById('cnamefield').disabled = 'disabled';
	document.getElementById('cnamefield').style.backgroundColor = 'silver';
	
	document.getElementById('exfndfield').disabled = 'disabled';
	document.getElementById('exfndfield').style.backgroundColor = 'silver';	
	
	document.getElementById('exnumfield').disabled = 'disabled';
	document.getElementById('exnumfield').style.backgroundColor = 'silver';
	
	document.getElementById('type_selector').value = '2';
	
}

function lockIndfields(){

	document.getElementById('cnamefield').disabled = false;
	document.getElementById('cnamefield').style.backgroundColor = '#F0F0F0';
	
	document.getElementById('exfndfield').disabled = false;
	document.getElementById('exfndfield').style.backgroundColor = '#F0F0F0';
	
	document.getElementById('exnumfield').disabled = false;
	document.getElementById('exnumfield').style.backgroundColor = '#F0F0F0';
	
	document.getElementById('tdnumfield').disabled = 'disabled';
	document.getElementById('tdnumfield').style.backgroundColor = 'silver';
	
	document.getElementById('nsnmfield').disabled = 'disabled';
	document.getElementById('nsnmfield').style.backgroundColor = 'silver';
	
	document.getElementById('nottcfield').checked = false;
	document.getElementById('nottcfield').disabled = 'disabled';
	document.getElementById('nottcfield').value = '0';
	
	document.getElementById('type_selector').value = '3';
	
}

function lock_tcnfield(){

	if(document.getElementById('type_selector').value != '3'){

		if(document.getElementById('nottcfield').value == '1'){
		document.getElementById('tdnumfield').disabled = false;
		document.getElementById('nottcfield').value = '0';
		document.getElementById('tdnumfield').style.backgroundColor = '#F0F0F0';
		}else{
		document.getElementById('tdnumfield').disabled = true;
		document.getElementById('nottcfield').value = '1';
		document.getElementById('tdnumfield').style.backgroundColor = 'silver';
		}
	
	}

}

function calculate_rates(sum){
	
	document.getElementById('card_rates').innerHTML = '<div style="text-align:center"><img src="visual/images/other/spinner.gif" alt="" /></div>';
	
	document.getElementById('card_rates_parent').style.display='block';
	
	
	ajax_content('ajax/cardrates.php?s='+sum, 'card_rates');
	
}

// Function for facebook links ...
function fbs_click(){
u=location.href;
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'share','toolbar=0,status=0,width=626,height=436');
return false;
}