/**
 * @author gdimousis
 */
$(document).ready(function(){

	$("a[href*='/opencms/']").each(function () { 
		//alert($(this).attr("href").replace('/opencms/','/'));
		var newurl=$(this).attr("href").replace('/opencms/','/');
		$(this).attr("href",newurl);
	});
	$("#dsl_availability").hide();
	
	$('.slide').hide();
	$('.slider').toggle(function(){
		$('.slide').hide();
		$(this).next('.slide').show();
	}, function(){
		$(this).next('.slide').hide();
	})
	
	$("#navigation li").hover(function() {
		$(this).children('ul').slideDown(50);
	}, function() {
		$(this).children('ul').slideUp(50);
	})
	
	
	$("#block2").hover(function() {
		$("#dsl_check").hide();
		$("#dsl_availability").show();
	})
	
	$("#footer ul li:first").addClass('first');
	
	$('#quick_nav').click(function(){
		var target = $('.quickLinksList option:selected').val();
		window.location = target;
	})
	
	$("#search_btn").click(function(){$("#search_form").submit()});
	

})


function checkNetAvailability() {

			if (document.getElementById('phoneNumber').value.length!=10  || !isNumeric(document.getElementById('phoneNumber') ) || 
							document.getElementById('phoneNumber').value.search(/^[01]/) != -1  ){
				//alert("<fmt:message key='validation.phone'/>");
				document.getElementById('dialogError').innerHTML="<fmt:message key='validation.phone'/>";
	            		showDialogError('en'); 
				document.getElementById('phoneNumber').value='';
				return;	
			}
			
	        var phone = eval(document.getElementById('phoneNumber').value);    						
	        var area =''; //eval(document.getElementById('AreaCode').value); 
	        var lg = document.getElementById('lg').value;        
	        var url = '/opencms/system/modules/com.on.template/elements/checkNetAvailabilityAjax.jsp?lg='+lg+'&phoneNumber=' + phone +'&AreaCode='+area;
		//var loadstatustext="<img src='/images/loading.gif' /> <p>"+document.getElementById('req').value+"</p>";
	        //document.getElementById("clock").innerHTML=loadstatustext;
	
		var returnedValue = "";
	         var finalTxt="";
		var availTmp="";
		var areaTmp="";
                var coTmp="";				
	        if (phone!='' && phone!= 'undefined') {
	            var oXMLHTTP;
	            if (window.ActiveXObject) { // IE
	                oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	                                
	                if (oXMLHTTP) { 
					
	                    oXMLHTTP.open("POST", url, true);  
	                    oXMLHTTP.onreadystatechange = function(){						
	                        if (oXMLHTTP.readyState == 4 )
	                        {
	                         
	                        returnedValue = oXMLHTTP.responseText;
	
				if ( returnedValue.indexOf("*")!='-1' ) 
				{
					coTmp=returnedValue.split("*")[0];
					areaTmp=returnedValue.split("*")[1];
					availTmp=returnedValue.split("*")[2];
					finalTxt=returnedValue.split("*")[3];
					
					coTmp=trim(coTmp);
					areaTmp=trim(areaTmp);
					availTmp=trim(availTmp);
				}
				else
				{
					finalTxt=returnedValue;
				}
					
	                       document.getElementById("clock").innerHTML=finalTxt;
	                       	$('#phone').val(phone);
				$('#co').val(coTmp);
				$('#area').val(areaTmp);
				$('#availableNum').val(availTmp);

	                        }
	                        };
	
	                    
	                    oXMLHTTP.send();
	                }
	            }
	            else if (window.XMLHttpRequest) { // Non-IE browsers
	                oXMLHTTP = new XMLHttpRequest(); 
	                //oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	                try {
	                    oXMLHTTP.open("POST", url, true);
	                
	                } catch (e) {
	                    alert(e);
	                  }  
	                
	                oXMLHTTP.onreadystatechange = function(){
	                        if (oXMLHTTP.readyState == 4 )
	                        {
	                       
	                       returnedValue = oXMLHTTP.responseText;

				if ( returnedValue.indexOf("*")!='-1' ) 
				{
					coTmp=returnedValue.split("*")[0];
					areaTmp=returnedValue.split("*")[1];
					availTmp=returnedValue.split("*")[2];
					finalTxt=returnedValue.split("*")[3];
					
					
					coTmp=trim(coTmp);
					areaTmp=trim(areaTmp);
					availTmp=trim(availTmp);
				}
				else
				{
					finalTxt=returnedValue;
				}
					
	                       document.getElementById("clock").innerHTML=finalTxt;
	                       
				$('#phone').val(phone);
				$('#co').val(coTmp);
				$('#area').val(areaTmp);
				$('#availableNum').val(availTmp);

	                        }
	                        };  
	                  
	                oXMLHTTP.send(null);
	            } 
	                                        
	         
	        } else {
	
	            //alert('Phone Empty'); 
	            document.getElementById('dialogError').innerHTML='Phone Empty';
	            showDialogError('en');           
	        }  
	             
	        return;     
	
	
	
	              
	} 
	
	
		function handleEnter(event, i_form) {
	 	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			enterWSC();
		}
	}
	
	function handleEnter2(event) {
	
	 var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	 if (keyCode == 13) {
		 checkNetAvailability();
		 return;
	 }
	}
