$(document).ready(function(){
    $("a#single_image").fancybox();
    $("a#inline").fancybox({
        hideOnContentClick: false
    });
    $("a.overlay_group").fancybox({
        overlayOpacity: .5,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300,
        overlayShow: true,
        height:275,
        width:550,
        hideOnContentClick:false
    });
    $("a#interactivemap").fancybox({
        overlayOpacity: .5,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300,
        overlayShow: true,
        height:565,
        width:930,
        hideOnContentClick: false
    });
    $("a#read1").fancybox({
        overlayOpacity: .5,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300,
        overlayShow: true,
        height:530,
        width:730,
        hideOnContentClick: true
    });
    $("a#read2").fancybox({
        overlayOpacity: .5,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300,
        overlayShow: true,
        height:530,
        width:730,
        hideOnContentClick: true
    });
    $("a#read3").fancybox({
        overlayOpacity: .5,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300,
        overlayShow: true,
        height:530,
        width:730,
        hideOnContentClick: true
    });
    $("a#read4").fancybox({
        overlayOpacity: .5,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300,
        overlayShow: true,
        height:530,
        width:730,
        hideOnContentClick: true
    });
    $("a#read5").fancybox({
        overlayOpacity: .5,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300,
        overlayShow: true,
        height:530,
        width:730,
        hideOnContentClick: true
    });
    $("a#read6").fancybox({
        overlayOpacity: .5,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300,
        overlayShow: true,
        height:530,
        width:730,
        hideOnContentClick: true
    });
    $("a#read7").fancybox({
        overlayOpacity: .5,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300,
        overlayShow: true,
        height:530,
        width:730,
        hideOnContentClick: true
    });
    $("a#read8").fancybox({
        overlayOpacity: .5,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300,
        overlayShow: true,
        height:530,
        width:730,
        hideOnContentClick: true
    });	

    //	$("#tab_business").bind("click", function(e){
    //	 	resetMainNavTabs();
    //     	$('#tab_business').attr('class','on');
    //     	$('#business_nav').show("slide", { direction: "down" }, 1000);
    //		//$.post("/actions/ajax_set_tab.php", { type:"business"});
    //    });
    //
    //    $("#tab_personal").bind("click", function(e){
    //	 	resetMainNavTabs();
    //     	$('#tab_personal').attr('class','on');
    //     	$('#personal_nav').show("slide", { direction: "down" }, 1000);
    //		//$.post("/actions/ajax_set_tab.php", { type:"personal"});
    //    });

    $(".print_screen").bind("click", function(e){
        window.print();
    });

    
//    var urlvars = getUrlVars();
//    if(urlvars["navtype"] == 'business') {
//    	setTabBusiness();
//    } else {
//    	setTabPersonal();
//    }
});

function setTabBusiness() {
    $('#tab_business').attr('class','on');
    $('#tab_personal').attr('class','off');
    $('#tab_mycellcom').attr('class','off');
}

function setTabPersonal() {
    $('#tab_personal').attr('class','on');
    $('#tab_business').attr('class','off');
    $('#tab_mycellcom').attr('class','off');
}

function setTabMyCellcom(subNav) {

	if(subNav != "passwordChange")
	{
	    $('#tab_personal').attr('class','off');
	    $('#tab_business').attr('class','off');
	    $('#tab_mycellcom').attr('class','on');
	
	    $('#personal_nav').hide();
	    $('#business_nav').hide();
	    $('#mycellcom_nav').show();
	
	    $('#mycellcom_bill').attr('class','dddefault');
	    $('#mycellcom_minutes').attr('class','dddefault');
	    $('#mycellcom_account').attr('class','dddefault');
	    $('#mycellcom_logoout').attr('class','dddefault');
	
	    $('#mycellcom_' + subNav).attr('class','selected');
	}
}

function resetMainNavTabs() {
    $('#tab_personal').attr('class','off');
    $('#tab_business').attr('class','off');
    $('#tab_mycellcom').attr('class','off');
    $('#personal_nav').hide();
    $('#business_nav').hide();
    $('#mycellcom_nav').hide();
	
}

jQuery.fn.fadeToggle = function(speed, easing, callback) {
    return this.animate({
        opacity: 'toggle'
    }, speed, easing, callback);
}; 


function findLocation() {
	
    $("#locationhover").fadeToggle();
// $('#locationhover').fadeIn('slow');
//		function benmen(eid) {
//			if (t) {
//				clearTimeout(t);
//			}
//			obj = document.getElementById(eid);
//			var curleft = 0;
//			var curtop = 0;
//			if(obj.offsetParent) {
//				do {
//					curleft += obj.offsetLeft;
//					curtop += obj.offsetTop;
//				} while (obj = obj.offsetParent);
//			}
//			if(navigator.userAgent.search("MSIE")!=-1) {
//				document.getElementById(eid + '_menu').style.left = curleft + "px";
//				document.getElementById(eid + '_menu').style.top = (curtop + 28) + "px";
//			} else {
//				document.getElementById(eid +'_menu').style.left = (curleft + 6) + "px";
//				document.getElementById(eid + '_menu').style.top = (curtop + 30) + "px";
//			}
//			Effect.Appear(eid + '_menu', {duration:.1});
//			return false;
//		}
//		function benmen_close() {
//			t=setTimeout('Effect.Fade("benmen_menu", {duration:.1})', 100);
//		}
	
}

var last_used_eid = 0;
var columnizer_options;

toggleBox = function(eid, navid, columnize, options) {
	
    this.t = null;
    this.eid = eid;
    if ($.isArray(navid))
    	this.navid = navid;
    else
    	this.navid = [navid];
    this.columnize = columnize;
    this.options = options ? options : {columns: 2, lastNeverTallest: true, buildOnce: true};
	
    this.hit = function() {
		
        if(last_used_eid != 0 && last_used_eid != this.eid){
            $(last_used_eid).hide();
        }
		
        if (this.t) {
            clearTimeout(this.t);
        }
		
        $.each(this.navid, function(index, value) {
            $(value).addClass("ddhover");
            $(value).removeClass("dddefault");
        });
        
        last_used_eid = this.eid;
        columnizer_options = this.options;
        if (this.columnize){
            $(this.eid).fadeIn("fast", function(){
            	$(last_used_eid + "columnwrapper").columnize(columnizer_options);
            });
            this.columnize = false;
        } else {
        	$(this.eid).fadeIn("fast");
        }
    };
	
    this.moff = function() {

        $.each(this.navid, function(index, value) {
            $(value).addClass("dddefault");
            $(value).removeClass("ddhover");
        });
		
        this.t=setTimeout('$("'+this.eid+'").hide();', 300);
    };
	
};

function findCallingPlans(type) {
    $("#callingplans_" + type).fadeToggle();
// $('#locationhover').fadeIn('slow');
	
}

// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}


function hideLocation() {
    $('#locationhover').fadeOut('slow');
}

function open_chat(pageName) {
    if (!pageName) {
	var title = document.title;
	var titleSeperatorIndex = title.indexOf('::');
	if (titleSeperatorIndex > 0) {
	    pageName = title.substr(titleSeperatorIndex + 2).replace(/^\s+|\s+$/g, '');
	} else {
	    pageName = $('div.roundbody h1').text();
	    if (!pageName) {
		pageName = $('div.roundbody h1 > img').attr('alt');
	    }
	    if (!pageName) {
		pageName = window.location.pathname;
	    }
	}
    }
    
    var chatPath = "/chat/index.html?pg=" + pageName;
    window.open(chatPath,
		"chat",
		"menubar=no, scrollbars=no, status=no, titlebar=no, toolbar=no, width=520, height=450");
    return false;
}

function loadByCat(opt){
    if(opt==0){
        window.location.href = '/admin/index.html';
    }
    if(opt>0){
        window.location.href = '/admin/index.html?cat=' + opt;
    }
	
}

function clearSearch() {
    if($('#search_field').val() == "Enter keywords to search the Cellcom site") {
        $('#search_field').val("");
    }
}

function setSearch() {
    if($('#search_field').val() == "") {
        $('#search_field').val("Enter keywords to search the Cellcom site");
    }
}

function CreateBookmarkLink() {

    title = "Cellcom MP3s";
    url = "http://cellcomdev.cellcom.com/music.html";

    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    } else if( window.external ) { // IE Favorite
        window.external.AddFavorite( url, title);
    }
    else if(window.opera && window.print) { // Opera Hotlist
        return true;
    }
}

	
function echeck(str) {

    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
	
    if (str.indexOf(at)==-1){
        return false;
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        return false;
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        return false;
    }

    if (str.indexOf(at,(lat+1))!=-1){
        return false;
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        return false;
    }

    if (str.indexOf(dot,(lat+2))==-1){
        return false;
    }
	
    if (str.indexOf(" ")!=-1){
        return false;
    }

    return true;
}

function ValidateContactForm()
{
    var emailID=$('#email');
    var emailconf=$('#emailconf');
    var name=$('#name');
    var ssn=$('#ssn');
	
    if ((emailID.val()=="")||echeck(emailID.val())==false){
        alert("Please Enter A Valid Email");
        return false;
    }
	
    if(emailconf.val() != emailID.val()){
        alert("Your email addresses do not match.  Please verify to continue.");
        return false;
    }
	
    if(name.val() == ""){
        alert("Please enter a name to continue.");
        return false;
    }
	
    if(ssn.val().length !=0)
    {
        if(ssn.val().length != 4)
        {
            alert("Please enter the last 4 digits of your SSN (Optional).");
            return false;
        }
    }
	
    return true;
}

function ValidateAgentForm(){
    var emailID=$('#t_email_address');
    var t_contact_person=$('#t_contact_person');
	
    if ((emailID.val()=="")||echeck(emailID.val())==false){
        alert("Please Enter A Valid Email");
        return false;
    }
	
    if(t_contact_person.val() == ""){
        alert("Please enter a contact name to continue.");
        return false;
    }
	
    return true;
}
 
function ValidateEmailSignup(){
    var emailID=$('#email');
    var t_contact_person=$('#fullname');
	
    if ((emailID.val()=="")||echeck(emailID.val())==false){
        alert("Please Enter A Valid Email");
        return false;
    }
	
    if(t_contact_person.val() == ""){
        alert("Please enter a name to continue.");
        return false;
    }
	
    return true;
}
 
function ValidateNewsForm(){
    var emailID=$('#t_email_address');
    var t_contact_person=$('#t_Name');
	
    if ((emailID.val()=="")||echeck(emailID.val())==false){
        alert("Please Enter A Valid Email");
        return false;
    }
	
    if(t_contact_person.val() == ""){
        alert("Please enter a name to continue.");
        return false;
    }
	
    return true;
}

