// JavaScript Document

function toggle_div(obj, togg){
   if(document.getElementById){
	   var el = document.getElementById(obj);   
	   if(togg == 'toggle'){
		  if(el.style.display != "block"){      
			 el.style.display = "block";
		  }else{
			 el.style.display = "none";
		  } 
	   }
	   
	   if(togg == 'hide'){
		  el.style.display = "none";
	   }
	   
	   if(togg == 'show'){
		  el.style.display = "block";      
	   }
   }
   
}

function confirmation_url(Txt, url) {
	var answer = confirm(Txt)
	if (answer){
		goto(url);
	}
}

function confirmation_album(Txt, sid_a, area_b, container_c, get_d) {
	var answer = confirm(Txt)
	if (answer){
		account_checker(sid_a, area_b, container_c, get_d);
		toggle_div(container_c, 'hide');
		//window.location = "http://www.google.com/";
	}
}

function confirmation_pic(Txt, sid_a, area_b, container_c, get_d) {
	var answer = confirm(Txt)
	if (answer){
		account_checker(sid_a, area_b, container_c, get_d);
		toggle_div(container_c, 'hide');
		//window.location = "http://www.google.com/";
	}
}

function confirmation_(Txt, sid_a, area_b, container_c, get_d) {
	var answer = confirm(Txt)
	if (answer){
		account_checker(sid_a, area_b, container_c, get_d);
		toggle_div(container_c, 'hide');
		//window.location = "http://www.google.com/";
	}
}

function goto(url){
	window.location.href = url;
}

function forceField(obj, val){
	document.getElementById(obj).value = val;
}

function donothing(){
	
}

function redirect(url, seconds){
	setTimeout("window.location='"+url+"'",seconds*1000);
}

var divIDString;
var sid_a1;
var get_d1;


function account_checker(sid_a, area_b, container_c, get_d){ 
	divIDString = container_c;
	sid_a1 = sid_a;
	get_d1 = get_d;
	//alert(str_d);
	xmlHttp=GetXmlHttpObject_2();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
 	}
	
	if(divIDString == 'picAreaPresentation')toggle_div('preloader_area3', 'show');
	
	
	var url="output.php";
	var get_da = get_d.replace(/\n/g, '<br>')
	url=url+"?area="+area_b+get_da+"&uSsid="+sid_a;	
	//alert(url);
	url=url+"&sid="+Math.random();	
	xmlHttp.onreadystatechange=stateChangedDiv;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//AJAX Get Start----------------------------------------------------------------
function stateChangedDiv() { 
	if (xmlHttp.readyState==0){
   		alert('The request is not initialized')
    } 
	if (xmlHttp.readyState==1){	
   	//	document.getElementById(divIDString).innerHTML='<div class="preloader_area">The request has been set up</div>';
    } 
	if (xmlHttp.readyState==2){
   	//	document.getElementById(divIDString).innerHTML='<div class="preloader_area">The request has been sent</div>';
    } 
	if (xmlHttp.readyState==3){
   		if(divIDString != 'multistackSec_2' & divIDString != 'picAreaPresentation')document.getElementById(divIDString).innerHTML='<div class="preloader_area"><img src="images/icons/preloader.gif"><br>loading...</div>';
		
    } 
	

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		
		if(divIDString == 'multistackSec_2'){
			toggle_div('multistackSec', 'hide')
			var contentVal = document.getElementById(divIDString);
			contentVal.innerHTML +=xmlHttp.responseText;
			multiadd_process();
		}else{
   			document.getElementById(divIDString).innerHTML=xmlHttp.responseText;
		}
		
		if(divIDString == 'picAreaPresentation')toggle_div('preloader_area3', 'hide');
		
    } 
	
}

function GetXmlHttpObject_2()
{
	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 checkifvalid_basic(){
		
	if (window.document.basic_account.customers_email_address.value==""){
		alert("Error on email address!");
		window.document.basic_account.customers_email_address.focus();
		return false;
	}	
	if (window.document.basic_account.customers_nick.value==""){
		alert("Please enter your Nickname!");
		window.document.basic_account.customers_nick.focus();
		return false;
	}
	if (window.document.basic_account.customers_firstname.value==""){
		alert("Please enter your Firstname!");
		window.document.basic_account.customers_firstname.focus();
		return false;
	}
	if (window.document.basic_account.customers_lastname.value==""){
		alert("Please enter your Lastname!");
		window.document.basic_account.customers_lastname.focus();
		return false;
	}
	
	if (window.document.basic_account.customers_password_check.checked){	
		if (window.document.basic_account.customers_password.value==""){
			alert("Error on password!");
			window.document.basic_account.customers_password.focus();
			return false;
		}
	}	
	
	if (window.document.basic_account.entry_country_id.value==""){
		alert("Please select your country!");
		window.document.basic_account.entry_country_id.focus();
		return false;
	}	
	if (window.document.basic_account.entry_city.value==""){
		alert("Please enter your city!");
		window.document.basic_account.entry_city.focus();
		return false;
	}	
}

function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}






function simpleLB(sid_a, area_b, get_d) {
	document.getElementById('pop_content').style.display = 'block';
	//document.getElementById('pop_content').style.width = popwidth+'px';
	document.getElementById('pop_content_close').style.display = 'block';
	document.getElementById('content_x').style.display = 'block';
	account_checker(sid_a, area_b, 'content_x', get_d);
	
	
	
	
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}

	var DivHeight = document.getElementById('pop_content').offsetHeight;
	//alert(yWithScroll);

	
	document.getElementById('bg_dark').style.height = yWithScroll +'px';
	document.getElementById('bg_dark').style.display = 'block';
}

function simpleLB_close() {	
		document.getElementById('bg_dark').style.display = 'none';
		document.getElementById('pop_content').style.display = 'none';
		document.getElementById('pop_content_close').style.display = 'none';
		document.getElementById('content_x').style.display = 'none';
}

function popupWindowForgot(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=450,height=20,screenX=150,screenY=150,top=150,left=150')
}







function checkIfRemoteFileExists(fileToCheck){
	var tmp=new Image;
	tmp.src=fileToCheck;
	if(tmp.complete){ 
		alert(fileToCheck+" is available"); 
		document.getElementById('display').innerHTML= fileToCheck;
	}else{ // Not got it yet - retry for a few seconds...
		window.setTimeout('checkIfRemoteFileExists(fileToCheck)', 1000);
	}
}




















var divIDString2;


function account_checker_img(sid_a, area_b, container_c, get_d){ 
	divIDString2 = container_c;
	//alert(str_d);
	xmlHttp=GetXmlHttpObject_2();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
 	}
	
	// trigger preloader here
	toggle_div('preloader_area2', 'show');
	
	var url="output.php";
	var get_da = get_d.replace(/\n/g, '<br>')
	url=url+"?area="+area_b+get_da+"&uSsid="+sid_a;	
	//alert(url);
	url=url+"&sid="+Math.random();	
	xmlHttp.onreadystatechange=stateChangedDiv2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}



//AJAX Get Start----------------------------------------------------------------
function stateChangedDiv2() { 
	if (xmlHttp.readyState==0){
   		alert('The request is not initialized')
    }	

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		//check image if exist..
		//var imgchckr = document.getElementById('img_check_ex');
		
		document.getElementById(divIDString2).innerHTML=xmlHttp.responseText;
		
		//alert('input has been loaded "'+ document.getElementById('uSsid').value+'" and '+document.getElementById('img_check_ex').value);
		
		// time to load the image
		setTimeout("remainimageLoading(document.getElementById('uSsid').value, 'ApplyphotoEffect', 'remainimageLoading_cont', '&img='+document.getElementById('img_check_ex').value+'&new='+document.getElementById('new').value+'&new2='+document.getElementById('new2').value+'&old='+document.getElementById('old').value+'&effectID2='+document.getElementById('effectID2').value+'&img_pictures_id='+document.getElementById('img_pictures_id').value+'&act=reloadImg')", 4000);		
		//toggle_div('preloader_area2', 'hide');		
    } 
	
}


function remainimageLoading(usid_a, area_b, container_c, get_d){
	//alert(urlImg + ' not loaded');
	//alert(get_d);
	account_checker(usid_a, area_b, container_c, get_d);
	toggle_div('preloader_area2', 'hide');
}

function d(o){
	return document.getElementById(o);
}

function loadimage(_imagepath){
	image = d("remainimageLoading_val");
	image.style.display = "none";
	imagepath = _imagepath;

	req = getreq();
	req.onreadystatechange = imagexists;
	req.open("get", imagepath, true);
	req.send(null);		
}

function imagexists(){
	if(req.readyState == 4){
		if(req.status == 200){
			image.style.display = "block";
			image.src = imagepath;
		}else{
			image.style.display = "none";
			alert('no src '+imagepath);
		}
	}
}

function getreq(){
	if(window.XMLHttpRequest)
		return new XMLHttpRequest();
	else if(window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
}





var divIDString3;
var sid_a3;


function extract_process(sid_a, area_b, container_c, get_d){ 
	sid_a3 = sid_a;
	divIDString3 = container_c;
	//alert(str_d);
	xmlHttp=GetXmlHttpObject_2();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
 	}
	toggle_div('preloader_area3', 'hide');
	toggle_div('preloader_area2', 'show');
	
	var url="output.php";
	var get_da = get_d.replace(/\n/g, '<br>')
	url=url+"?area="+area_b+get_da+"&uSsid="+sid_a;	
	//alert(url);
	url=url+"&sid="+Math.random();	
	xmlHttp.onreadystatechange=stateChangedDiv3;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//AJAX Get Start----------------------------------------------------------------
function stateChangedDiv3() {  
	if (xmlHttp.readyState==3){
   		document.getElementById(divIDString3).innerHTML='<div class="preloader_area"><img src="images/icons/preloader.gif"><br>loading...</div>';
    } 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
   		document.getElementById(divIDString3).innerHTML=xmlHttp.responseText;
		
		toggle_div('preloader_area3', 'show');
		setTimeout("createThumb_process(sid_a3, 'img_extractor', 'addimg', '')", 2000);	
    } 
	
}

function createThumb(){
	createThumb_process(sid_a3, 'img_extractor', 'addimg', '');
}


function createThumb_process(sid_a, area_b, container_c, get_d){ 
	divIDString4 = container_c;
	sid_a3 = sid_a;
	//alert(str_d);
	xmlHttp=GetXmlHttpObject_2();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
 	}
	var url="output.php";
	var get_da = get_d.replace(/\n/g, '<br>')
	url=url+"?area="+area_b+get_da+"&uSsid="+sid_a;	
	//alert(url);
	url=url+"&sid="+Math.random();	
	xmlHttp.onreadystatechange=stateChangedDiv4;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//AJAX Get Start----------------------------------------------------------------
function stateChangedDiv4() {  
	if (xmlHttp.readyState==3){
   		//document.getElementById(divIDString4).innerHTML='<div class="preloader_area"><img src="images/icons/preloader.gif"><br>loading...</div>';
		
    } 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		var contentVal = document.getElementById(divIDString4);
		contentVal.innerHTML +=xmlHttp.responseText;
		
		
		if(document.getElementById('theresmore').value > parseInt(1)){
			
			contentVal.innerHTML = contentVal.innerHTML.replace(/theresmore/g, '');
			//alert(contentVal.innerHTML);
   			setTimeout("createThumb()", 1000);
		}else{
			toggle_div('extract', 'hide');			
			document.getElementById('preloader_area1').innerHTML = 'All images has been added..<br>You will be redirected in 3 seconds.';
			redirect('myphotos.php?page=stack&action=multistack&uSsid='+sid_a3, 3);
		}
		
		//alert(document.getElementById('theresmore').value);
    } 
	
}

function multiadd_process(){
	if(document.getElementById('theresmore').value > parseInt(1)){
		var contentVal = document.getElementById(divIDString);
		contentVal.innerHTML = contentVal.innerHTML.replace(/theresmore/g, '');
		account_checker(sid_a1, 'multistackSec_add', divIDString, get_d1);
		//setTimeout("account_checker(sid_a1, 'multistackSec_add', divIDString, get_d1)", 1000);
	}else{
		toggle_div('multistackSec_2', 'hide');			
		document.getElementById('preloader_area1').innerHTML = 'All images has been added..<br>You will be redirected in 3 seconds.';
		redirect('myphotos.php?page=stack&img_album_id='+document.getElementById('albumID').value+'&uSsid='+sid_a1, 3);
	}
}