
function dbRequest(action, file, var1, var2, preURL)
{
    file = preURL+'requests/'+file;
	var req = null; 
		if (window.XMLHttpRequest)
		{
			req = new XMLHttpRequest();
			if (req.overrideMimeType) 
			{
				req.overrideMimeType('text/xml');
			}
		} 
		else if (window.ActiveXObject) 
		{
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e)
			{
				try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	        	}

		req.onreadystatechange = function()
		{ 
			
			if(req.readyState == 4)
			{
				if(req.status == 200)
				{
					switch(action)
					{
					case 'getContinents':      box = document.getElementById('continent_rolldown_'+var1);
					 					       box.style.visibility = 'visible';
										       box.innerHTML = req.responseText;
										       break;
 				    case 'postCountry':        document.getElementById('reloadForm').submit(); break;
 			    	case 'deleteCountry':      document.getElementById('reloadForm').submit(); break;	
 			    	
			     case 'updateAllContactsList': document.getElementById('allContactsBox').innerHTML = req.responseText;
			     							   //initialize();
			     							   if(document.getElementById('allContactsList'))
	Sortable.create("allContactsList",{dropOnEmpty:true,handle:'handle',containment:[""],constraint:false,ghosting:true});	
	if(document.getElementById('countryContactList'))
	Sortable.create('countryContactList',{onUpdate:function(){uploadNewContactsOrder();},dropOnEmpty:true,handle:'handle',containment:["allContactsList","countryContactList"],constraint:false});	    								  						   
											   
 			    	                           break;	
 			    	case 'updateContactOrder': break;
 			case 'getCountryContactsFrontend': document.getElementById('contactsBox').innerHTML = req.responseText;
 											   document.getElementById('world').style.visibility = 'hidden';	
 											   document.getElementById('worldAntiKnipper').style.visibility = 'hidden';	
 			 								   hideBoxes();
 											   
 											   // if CMS logged in
 											   if(var1==1)
 											   { 
 											   document.getElementById('allContactsBox').style.visibility = 'visible';
 											   document.getElementById('right_frame').innerHTML = '';
 											   Sortable.create("countryContactList",{onUpdate:function(){uploadNewContactsOrder();},dropOnEmpty:true,containment:["allContactsList","countryContactList"],constraint:false});	
 											   updateAllContactsList(document.getElementById('countryId').value);
 											   }
 			 								   break;
	               case 'addContactToCountry': getContacts(document.getElementById('countryName').value);
	               							   //alert(document.getElementById('countryName').value);
 			 								   break;
                      case 'insertNewContact': getCountryContacts(document.getElementById('countryName').value);
 			 								   break;
 			  case 'removeContactFromCountry': getContacts(document.getElementById('countryName').value);
 			   								   //alert(document.getElementById('countryName').value);
 			  								   break;
 			  			 case 'deleteContact': 
 			  			 					   updateAllContactsList(0);
 			  			 					   break;
						case 'updateLightbox': document.getElementById('lightbox_new').innerHTML = req.responseText; break;
 			    					   	  

					}
				}		
			} 
		} 
		req.open("GET", file, true); 
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		req.send(null);
}

function getAjaxVideo(name)
{
    document.getElementById('overlay_video').style.visibility = 'visible';
    var holder = document.getElementById('videoholder');
    holder.style.visibility = 'visible';
    holder.innerHTML = "<div style='width: 486px; height: 293px; background: white;'><div id='exitlink' style='margin-top: -8px; margin-left: -210px;'><a href='"+name+"' style='font-size: 11px;'><img src='../../img/link_arrow_back.jpg'> back</a></div><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='480' height='270' style='position: relative; top: 20px;'><param name='movie' value='../../flv/"+name+".swf' /><param name='quality' value='high' /><param name='menu' value='false' /><param name='wmode' value='' /><embed src='../../flv/"+name+".swf' wmode='' quality='high' menu='false' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='480' height='270'></embed></object></div>";
    
}

function addContactToCountry(contactId)
{ 
  if(document.getElementById('countryId')!=0)
  {
    var countryId = document.getElementById('countryId').value;
    file = 'addContactToCountry.php?contactId='+contactId+'&countryId='+countryId;
    dbRequest('addContactToCountry',file,0,0,''); 
  }
}