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_(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');
	}
}

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);
	}
}

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);
}

function objv(objName){
	return '&'+objName+'='+document.getElementById(objName).value+'';	
}

function del_incomming_loop(){
	clearTimeout(incomming_loop);
}

function loadfrontpage(){
	var sid_a = document.getElementById('addsID').value;
	account_checker(sid_a, 'nav', 'outputs', '');
}

function reloadincoming(){
	var sid_a = document.getElementById('addsID').value;
	account_checker(sid_a, 'chat_incoming', 'outputs', '');
	setTimeout("reloadincoming2()", 3000);
}

function reloadincoming2(){
	var sid_a = document.getElementById('addsID').value;
	account_checker(sid_a, 'chat_incoming', 'outputs', '');
	setTimeout("reloadincoming()", 3000);
}

var divIDString;
var sid_a1;
var get_d1;
var area_b1;
var incomming_loop;
var count_reloadTotal_global;


function account_checker(sid_a, area_b, container_c, get_d){ 
	divIDString = container_c;
	area_b1 = area_b;
	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;
 	}
	
	// create chat waiting area.
	if(area_b1 == 'chat_add'){
		var pastnum = '&pastnum='+document.getElementById('past_total').value;		
	}else{
		var pastnum = '';		
	}
	
	var url="output.php";
	var get_da = get_d.replace(/\n/g, '<br>')
	url=url+"?area="+area_b+get_da+"&addsID="+sid_a+pastnum;	
	//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){
   		//document.getElementById(divIDString).innerHTML='<div class="preloader_area">Loading please wait...</div>';
    } 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
		var responceOUt = document.getElementById(divIDString);
		responceOUt.innerHTML=xmlHttp.responseText;	
		
		// create chat waiting area.
		if(area_b1 == 'chat'){
			var waitingTochat = document.getElementById('waitingTochat');
			if(waitingTochat.value == 2){
				account_checker(sid_a1, 'chat_session', divIDString, '&transaction_code='+document.getElementById('transaction_code').value);
				del_incomming_loop();
				document.getElementById('chat_message').focus();
			}
			
			if(waitingTochat){
				//alert('chat area!');
				// do the waiting loop
				incomming_loop = setTimeout("account_checker(sid_a1, area_b1, divIDString, get_d1)", 3000);
				incomming_loop;
			}
		}
		if(area_b1 == 'chat_add' || area_b1 == 'chat_session'){
			clearTimeout(count_reloadTotal_global);
			clearTimeout(toReload);
			var toReload = setTimeout("count_reloadTotal()", 2000);
			toReload;
		}
		if(area_b1 == 'chat_add_stat'){
			count_reloadTotal_check(responceOUt.innerHTML);
		}
		
    } 
	
}

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 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')
}


// for quote

function website_type(){
	var wtype = document.getElementById('wtype');
	if(wtype.value == 'others'){
		toggle_div('wtype_other', 'show');
	}else{		
		toggle_div('wtype_other', 'hide');
		document.getElementById('wtype_other').value = '';
	}
}



function loadofficerChat(){
	sid_a1 = document.getElementById('addsID').value;
	var chat_stat = document.getElementById('chat_stat').value;
	if(chat_stat == '0'){
		account_checker(sid_a1, 'chat_sessionEnded', 'outputs', '&transaction_code='+document.getElementById('transaction_code').value);	
	}else{
		account_checker(sid_a1, 'chat_session', 'outputs', '&transaction_code='+document.getElementById('transaction_code').value+'&mode=officer');
	}
	del_incomming_loop();
}

var past_total;
var current_total;
function count_chatTotal(transaction_code){
	past_total = document.getElementById('past_total').value;	
	sid_a1 = document.getElementById('addsID').value;
	alert(transaction_code);
	//setTimeout("account_checker(sid_a1, 'chat_add_stat', 'current_total', '&transaction_code='+transaction_code)", 3000);
	setTimeout("count_chatTotal2(transaction_code)", 3000);
}

function count_chatTotal2(transaction_code){
	alert('2');
	past_total = document.getElementById('past_total').value;	
	sid_a1 = document.getElementById('addsID').value;
	setTimeout("account_checker(sid_a1, 'chat_add_stat', 'current_total', '&transaction_code='+transaction_code)", 3000);
	setTimeout("count_chatTotal(transaction_code)", 3000);
}




function count_reloadTotal(){
	//alert('success!');
	count_reloadTotal_global = setTimeout("count_reloadTotal2()", 3000);
	count_reloadTotal_global;
}

function count_reloadTotal2(){
	var sid_a = document.getElementById('addsID2').value;
	// begin the reloop..
	var transaction_code = document.getElementById('transaction_code2').value;
	// to check the current total
	account_checker(sid_a, 'chat_add_stat', 'current_total', '&transaction_code='+transaction_code);
}


function count_reloadTotal_check(num){
	var currentnum = num;
	var pastnum = document.getElementById('past_total').value;
	if(parseInt(currentnum) != parseInt(pastnum)){
		//alert('Needs editing!');
		
		// to display the last message	
		var sid_a = document.getElementById('addsID2').value;
		var transaction_code = document.getElementById('transaction_code2').value;
		account_checker(sid_a, 'chat_load_added_msg', 'chat_session_msg_'+pastnum, '&transaction_code='+transaction_code+'&pastnum='+pastnum);
		forceField('past_total', currentnum);
	}
	count_reloadTotal();
}


function chat_btn(){
	toggle_div('chatSend1', 'hide');
	toggle_div('chatSend2', 'show');
	setTimeout("toggle_div('chatSend1', 'show')", 4000);
	setTimeout("toggle_div('chatSend2', 'hide')", 4000);
}